Skip to content

Commit 56a0e53

Browse files
committed
Richtige Indizierung beim Hinzufügen der neuen Indizes zum Buffer,
Schatten sehen richtig aus, aber Cormacks Reverse gilt immer noch nicht. D.h. wenn man sich in die Schatten hineinbegibt, springt plötzlich die Anzeige von Schatten auf Nicht-Schatten
1 parent d99251d commit 56a0e53

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

10/code/shader/material_and_light.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ uniform int drawShadows;
2929
void main() {
3030
// TODO: add an option to switch between normal lighting and shadow color (black) rendering //
3131
if(drawShadows == 1) {
32-
color = vec4(1,0,0,0.3);
32+
color = vec4(0,0,0,0.5);
3333
return;
3434
}
3535

10/code/src/Ex10.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void renderShadow() {
486486
}
487487

488488
//Done TODO: disable drawing to screen (we just want to change the stencil buffer) //
489-
/*glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
489+
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
490490
glDepthMask(GL_FALSE);
491491
//Done TODO: enable stencil test and face culling //
492492
// - we need face culling to separately render front facing and back facing triangles //
@@ -501,20 +501,12 @@ void renderShadow() {
501501
glm_ModelViewMatrix.top() *= glm::scale(glm::vec3(10));
502502
glUniformMatrix4fv(uniformLocations["modelview"], 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));
503503
glUniform1i(uniformLocations["drawShadows"], 1);
504-
505-
// setup light and material in shader //
506-
setupLightAndMaterial();*/
504+
507505

508506
MeshObj *mesh = objLoader.getMeshObj("sceneObject");
509-
glDisable(GL_CULL_FACE);
510-
glUniform1i(uniformLocations["drawShadows"], 1);
511-
glEnable( GL_BLEND );
512-
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
513507
mesh->renderShadowVolume();
514-
glDisable(GL_BLEND);
515-
glEnable(GL_CULL_FACE);
516508

517-
/*glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
509+
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
518510
glCullFace(GL_FRONT);
519511

520512
mesh->renderShadowVolume();
@@ -532,10 +524,8 @@ void renderShadow() {
532524
glEnable( GL_BLEND );
533525
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
534526

535-
536-
537527
renderScreenFillingQuad();
538-
glDisable( GL_BLEND );*/
528+
glDisable( GL_BLEND );
539529

540530

541531
//Done TODO: disable stencil testing for further rendering and restore original rendering state //

10/code/src/MeshObj.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,10 @@ void MeshObj::initShadowVolume(glm::vec3 lightPos) {
178178
// TODO: for every vertex: //
179179
// - project vertex from lightsource to *infinity* //
180180
// - append vertex to local vertex data storage //
181-
GLfloat farFarAway = 1000.0f;
181+
GLfloat farFarAway = 100.0f;
182182

183183
unsigned int numVerts = shadows.vertex_position.size();
184-
185-
for (int i=0 ; i < numVerts; i = i+3){
184+
for (unsigned int i=0 ; i < numVerts; i = i+3){
186185
glm::vec3 vpos(shadows.vertex_position[i],shadows.vertex_position[i+1],shadows.vertex_position[i+2]);
187186

188187
glm::vec3 lDir = vpos - lightPos;
@@ -201,7 +200,8 @@ void MeshObj::initShadowVolume(glm::vec3 lightPos) {
201200
// - the second set contains the projected vertex data *in the same order* //
202201
// -> you might want to store the size of such a set to easily access //
203202
// corresponding vertices later on //
204-
GLuint sizeOfSet = shadows.vertex_position.size()/2;
203+
GLuint sizeOfSet = shadows.vertex_position.size()/(2*3); //because in vertex_position each position vector has 3 elements
204+
205205
// TODO: project 8 (6 sides + 2 caps) shadow triangles for each mesh triangle //
206206
// - process every geometry face and create 6 (or 8) new faces from it //
207207
// - be sure to check the face orientation and flip back facing triangles //
@@ -255,8 +255,8 @@ void MeshObj::initShadowVolume(glm::vec3 lightPos) {
255255
shadows.indices.push_back(ia1);
256256

257257
shadows.indices.push_back(ib1);
258-
shadows.indices.push_back(ic1);
259258
shadows.indices.push_back(ia1);
259+
shadows.indices.push_back(ic1);
260260

261261
}
262262
// TODO: save the index count of your shadow volume object in 'mIndexCount_shadow' //

0 commit comments

Comments
 (0)