Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Community-Fossil
Community-Fossil
Community-Fossil
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat4 shadow_matrix0; in vec3 a_Vertex; in vec2 a_TexCoord0; out vec2 texCoord0; out vec4 shadowCoord; void main(void){ shadowCoord = shadow_matrix0*vec4(a_Vertex, 1.0); texCoord0 = a_TexCoord0; gl_Position = projection_matrix*(modelview_matrix*vec4(a_Vertex, 1.0)); } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
precision highp float; uniform sampler2D texture0; uniform sampler2D shadowMap0; in vec4 shadowCoord; in vec2 texCoord0; out vec4 outColor; void main(void){ outColor = texture(texture0, texCoord0.xy); vec4 shadowcoord = shadowCoord/shadowCoord.w; shadowcoord.z += 0.0005; float depth = texture(shadowMap0, shadowcoord.st).z; float shadow = 1.0; if(shadowCoord.w > 0.0){ shadow = depth < shadowcoord.z ? 0.5 : 1.0; } outColor *= shadow; if(depth == 1.0){ outColor *= 0.1; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
void setShadowMatrix(){ mat4 modelview, projection; mat4 bias = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0); glGetFloatv(GL_MODELVIEW_MATRIX, modelview.getArray()); glGetFloatv(GL_PROJECTON_MATRIX, projection.getArray()); shadowMatrix = bias; shadowMatrix *= projection; shadowMatrix *= modelview; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »DeKugelschieber« (05.08.2011, 22:37)
Community-Fossil
Dieser Beitrag wurde bereits 9 mal editiert, zuletzt von »dot« (07.08.2011, 00:16)
Community-Fossil
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
uniform sampler2D texture0; uniform sampler2D shadowMap0; in vec4 shadowCoord; in vec2 texCoord0; out vec4 color; void main(void){ color = texture(texture0, texCoord0.st); //vec4 shadowTextureCoord = shadowCoord/shadowCoord.w; vec4 shadowTextureCoord = normalize(shadowCoord); shadowTextureCoord.z += 0.0005; float depth = texture(shadowMap0, shadowTextureCoord.st).z; //if(shadowCoord.w > 0.0){ if(depth < shadowTextureCoord.z){ color *= 0.5; } //} } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »dot« (07.08.2011, 00:52)
Community-Fossil
Also die x und y würde ich bei den Vertices tauschen (habe das glaube ich so gelesen, kann mich aber auch irren).
Und meine Matrix sieht von den Indexen halt so aus (float array [16]):
0 1 2 3
4 5 6 7
8 9 ...
Noch eine Frage: Muss ich bei der Shadowmap alles rendern oder den Boden z.B. nicht?
So hab ichs im Moment, ich render nur die Box. Aber die wirft ja dann auf sich selbst auch Schatten.
Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »dot« (07.08.2011, 11:18)
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
// beim finalen rendern: shader[0]->sendUniform4x4("shadow_matrix0", shadowMatrix.getArray()); // Und die Funktion meiner Shaderklasse: void GLSLProgram::sendUniform4x4(const string &name, const float *matrix, bool transpose){ GLuint location = getUniformLocation(name); glUniformMatrix4fv(location, sizeof(matrix), transpose, matrix); } |
Zitat
Und das willst du nicht oder wie!?
Werbeanzeige