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
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 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
// VERTEX: uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat3 normal_matrix; // Normalisierte Modelview Matrix // Materialeigenschaften uniform vec4 material_ambient; // Umgebungslicht uniform vec4 material_diffuse; // Beleuchtung uniform vec4 material_specular; // Highlight uniform float material_shininess; struct light{ vec4 position; vec4 ambient; vec4 diffuse; vec4 specular; /*float constant_attenuation; float linear_attenuation; float quadratic_attenuation;*/ }; uniform light light0; // Lichtquelle in vec3 a_Vertex; in vec2 a_TexCoord0; in vec3 a_Normal; out vec2 texCoord0; out vec3 normal; out vec3 halfVector; out vec3 lightDir; out vec4 vertDiffuse; out vec4 vertAmbient; void main(void){ normal = normalize(normal_matrix*a_Normal); vec4 pos = modelview_matrix*vec4(a_Vertex, 1.0); vec3 lightPos = (light0.position).xyz; lightDir = normalize(lightPos); halfVector = normalize(lightPos-(pos.xyz)); vertDiffuse = material_diffuse*light0.diffuse; vertAmbient = material_ambient*light0.ambient; texCoord0 = a_TexCoord0; gl_Position = projection_matrix*pos; } // FRAGMENT: precision highp float; uniform sampler2D texture0; uniform vec4 material_ambient; uniform vec4 material_diffuse; uniform vec4 material_specular; uniform vec4 material_emissive; uniform float material_shininess; struct light{ vec4 position; vec4 ambient; vec4 diffuse; vec4 specular; /*float constant_attenuation; float linear_attenuation; float quadratic_attenuation;*/ }; uniform light light0; in vec2 texCoord0; in vec3 normal; in vec3 halfVector; in vec3 lightDir; in vec4 vertDiffuse; in vec4 vertAmbient; out vec4 outColor; void main(void){ vec3 N = normalize(normal); float NdotL = max(dot(N, normalize(lightDir)), 0.0); vec4 color = vec4(0.0); if(NdotL > 0.0){ color += vertDiffuse*NdotL; vec3 HV = normalize(halfVector); float NdotHV = max(dot(N, HV), 0.0); color += material_specular*light0.specular*pow(NdotHV, material_shininess); } outColor = (color+vertAmbient)*texture(texture0, texCoord0.st); } |
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 24 25 26 27 |
// VERTEX: [...] // halfVector gestrichen, wird hier nicht mehr berechnet out vec3 lightPos; out vec4 pos; [...] pos = modelview_matrix*vec4(a_Vertex, 1.0); lightPos = (light0.position).xyz; [...] // FRAGMENT: [...] in vec3 lightPos; // dementsprechend in vec4 pos; [...] vec3 halfVector = normalize(lightPos-(pos.xyz)); [...] |
Community-Fossil
Community-Fossil
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
void main(void){ normal = normalize(normal_matrix*a_Normal); vec4 pos = modelview_matrix*vec4(a_Vertex, 1.0); vec3 lightPos = light0.position.xyz; lightDir = normalize(pos.xyz-lightPos); dist = length(lightPos); halfVector = normalize((lightPos+pos.xyz)/2); vertDiffuse = material_diffuse*light0.diffuse; vertAmbient = material_ambient*light0.ambient; texCoord0 = a_TexCoord0; gl_Position = projection_matrix*pos; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void main(void){ vec3 N = normalize(normal); float NdotL = max(dot(N, normalize(lightDir)), 0.0); vec4 color = vec4(0.0); if(NdotL > 0.0){ float attenuation = 1.0/(light0.constant_attenuation+ light0.linear_attenuation*dist+ light0.quadratic_attenuation*dist*dist); color += attenuation*(material_diffuse*vertDiffuse*NdotL+vertAmbient); float NdotHV = max(dot(N, halfVector), 0.0); color += material_specular*light0.specular*pow(NdotHV, material_shininess); } outColor = color*texture(texture0, texCoord0.st); } |
Community-Fossil
Werbeanzeige