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
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Materialeigenschaften m_shaderProgram->sendUniform("material_ambient", 0, 0, 0, 0); m_shaderProgram->sendUniform("material_diffuse", 0.5, 0.5, 0.5, 0); m_shaderProgram->sendUniform("material_specular", 1, 1, 1, 0); m_shaderProgram->sendUniform("material_shininess", 100); // Lichtquelle m_shaderProgram->sendUniform("light0.ambient", 1, 1, 1, 0); m_shaderProgram->sendUniform("light0.diffuse", 1, 1, 1, 0); m_shaderProgram->sendUniform("light0.specular", 1, 1, 1, 0); m_shaderProgram->sendUniform("light0.constant_attenuation", 0.3f); m_shaderProgram->sendUniform("light0.linear_attenuation", 0.1f); m_shaderProgram->sendUniform("light0.quadratic_attenuation", 0.01f); m_shaderProgram->sendUniform("light0.position", 0, 0, -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 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 |
#version 130 precision highp float; 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 vec4 a_Vertex; in vec2 a_TexCoord0; in vec3 a_Normal; out vec2 texCoord0; out vec3 normal; out vec3 lightDir; out vec3 halfVector; out vec4 vertDiffuse; out vec4 vertAmbient; out float dist; void main(void){ normal = normalize(normal_matrix*a_Normal); vec3 lightPos = normalize(light0.position).xyz; vec4 pos = modelview_matrix*a_Vertex; lightDir = lightPos-pos.xyz; vec3 E = -(pos.xyz); dist = length(lightDir); lightDir = normalize(lightDir); halfVector = normalize(lightPos+E); vertDiffuse = material_diffuse*light0.diffuse; vertAmbient = material_ambient*light0.ambient; texCoord0 = a_TexCoord0; gl_Position = projection_matrix*pos; } |
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 |
#version 130 precision highp float; uniform sampler2D texture0; // Textur // 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; in vec2 texCoord0; in vec3 normal; in vec3 lightDir; in vec3 halfVector; in vec4 vertDiffuse; in vec4 vertAmbient; in float dist; out vec4 outColor; void main(void){ vec3 N = normalize(normal); float NdotL = max(dot(N, normalize(lightDir)), 0.0); vec4 color = vec4(0.0, 0.0, 0.0, 0.0); // Hinten anfangen if(NdotL > 0.0){ color += vertDiffuse*NdotL; vec3 HV = normalize(halfVector); float NdotHV = max(dot(N, HV), 0.0); color += material_specular*light0.specular*NdotHV; } float attenuation = 1.0/(light0.constant_attenuation+light0.linear_attenuation*dist+light0.quadratic_attenuation*dist*dist); outColor = ((color*attenuation)+vertAmbient)*texture(texture0, texCoord0.st); } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »dot« (30.03.2011, 15:07)
Community-Fossil
Community-Fossil
Zitat
Und das mit der "Normalisierten Modelview Matrix" wär auch noch interessant wie du die genau berechnest, bzw. was du da genau drunter verstehst...
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void main(void){ normal = normalize(normal_matrix*a_Normal); vec4 pos = modelview_matrix*vec4(a_Vertex, 1.0); vec3 lightPos = light0.position.xyz; lightDir = lightPos-pos.xyz; dist = length(lightDir); lightDir = normalize(lightDir); vec3 E = -(pos.xyz); halfVector = normalize(lightPos+E); vertDiffuse = material_diffuse*light0.diffuse; vertAmbient = material_ambient*light0.ambient; texCoord0 = a_TexCoord0; gl_Position = projection_matrix*pos; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void main(void){ vec3 N = normalize(normal); float NdotL = max(dot(N, normalize(lightDir)), 0.0); vec4 color = vec4(0.0); // Hinten anfangen 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); } float attenuation = 1.0/(light0.constant_attenuation+light0.linear_attenuation*dist+light0.quadratic_attenuation*dist*dist); outColor = ((color*attenuation)+vertAmbient)*texture(texture0, texCoord0.st); } |
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 |
static vector<float> normalizeMatrix(const float *matrix){ vector<float> M(9); M[0] = matrix[0]; M[1] = matrix[1]; M[2] = matrix[2]; M[3] = matrix[4]; M[4] = matrix[5]; M[5] = matrix[6]; M[6] = matrix[8]; M[7] = matrix[9]; M[8] = matrix[10]; float determinate = M[0]*M[4]*M[8]+M[1]*M[5]*M[6]+M[2]*M[3]*M[7]; determinate -= M[2]*M[4]*M[6]+M[0]*M[5]*M[7]+M[1]*M[3]*M[8]; float oneOverDet = 1/determinate; vector<float> N(9); N[0] = (M[4]*M[8]-M[5]*M[7])*oneOverDet; N[3] = (M[2]*M[7]-M[1]*M[8])*oneOverDet; N[6] = (M[1]*M[5]-M[2]*M[4])*oneOverDet; N[1] = (M[5]*M[6]-M[3]*M[8])*oneOverDet; N[4] = (M[0]*M[8]-M[2]*M[6])*oneOverDet; N[7] = (M[2]*M[3]-M[0]*M[5])*oneOverDet; N[2] = (M[3]*M[7]-M[4]*M[6])*oneOverDet; N[5] = (M[1]*M[6]-M[8]*M[7])*oneOverDet; N[8] = (M[0]*M[4]-M[1]*M[3])*oneOverDet; return N; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »dot« (30.03.2011, 17:58)
Werbeanzeige