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
C-/C++-Quelltext |
|
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
// VERTEX // [...] uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat3 normal_matrix; uniform vec3 camera_position; uniform Material material0; uniform Light light0; in vec3 a_Vertex; in vec2 a_TexCoord; in vec3 a_Normal; out vec2 texCoord; out vec3 N, L, HV; // Normale, Lichtrichtung, halfway vector out vec4 ambient, diffuse; out float attenuationDistance; void main(void){ vec4 pos = modelview_matrix*vec4(a_Vertex, 1.0); N = normalize(normal_matrix*a_Normal); vec3 lightPos = light0.position.xyz; L = normalize(lightPos-pos.xyz); HV = normalize(camera_position-pos.xyz)+L*0.5; attenuationDistance = length(lightPos-pos.xyz); ambient = material0.ambient*light0.ambient; diffuse = material0.diffuse*light0.diffuse; texCoord = a_TexCoord; gl_Position = projection_matrix*pos; } // FRAGMENT // [...] uniform sampler2D texture0; uniform Material material0; uniform light light0; in vec2 texCoord; in vec3 N, L, HV; in vec4 ambient, diffuse; in float attenuationDistance; out vec4 outColor; void main(void){ vec4 color = ambient; vec3 n = normalize(N); float NdotL = max(dot(n, normalize(L)), 0.0); if(NdotL > 0.0){ float NdotHV = max(dot(n, normalize(HV)), 0.0); float attenuation = 1.0/(light0.constant_attenuation+ light0.linear_attenuation*attenuationDistance+ light0.quadratic_attenuation*attenuationDistance*attenuationDistance); color += attenuation*diffuse*NdotL+material0.specular*light0.specular*pow(NdotHV, material0.shininess); } outColor = color*texture(texture0, texCoord.st); } |
Community-Fossil
C-/C++-Quelltext |
|
1 |
shader->sendUniform("light0.position", light.position.x, light.position.y, light.position.z, 1); |
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
void main(void){ vec4 pos = modelview_matrix*vec4(a_Vertex, 1.0); N = normalize(normal_matrix*a_Normal); vec3 lightPos = vec3(modelview_matrix*light0.position); // MAL MODELVIEW GERECHNET L = normalize(lightPos-pos.xyz); HV = normalize((camera_position-pos.xyz+L)*0.5); attenuationDistance = length(light0.position.xyz-pos.xyz); ambient = material0.ambient*light0.ambient; diffuse = material0.diffuse*light0.diffuse; texCoord = a_TexCoord; gl_Position = projection_matrix*pos; } |
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 |
vec4 lightPos = projection_matrix*light0.position; L = normalize(lightPos-pos).xyz; HV = normalize((camera_position-pos.xyz+L)*0.5); attenuationDistance = length(lightPos-pos); |
Ich finde nirgendswo das man die Lichtposition in Eyespace oder Objectspace umrechnen müsste.
Quellcode |
|
1 |
L = normalize(lightPos-pos).xyz; |
Und mit projection sieht das ganze so aus (immer noch falsch)
Community-Fossil
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 |
vec3 lightDir = (light_matrix*light0.position).xyz-pos.xyz; L = normalize(lightDir); attenuationDistance = length(lightDir); HV = normalize((camera_position-pos.xyz+lightDir)/2); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
// in Render Methode: shader->sendUniform4x4("light_matrix", m_lights[m_objectLight[i]]->getModelview(cam_modelview).getArray()); // Methode der Lichtquelle: mat4 bbLight::getModelview(mat4 modelview){ modelview.translate(m_information.position.x, m_information.position.y, m_information.position.z); return modelview; } |
Werbeanzeige