PK ®ýJ×éYf±± diff.patchdiff -ur --binary model3emu/Src/Graphics/New3D/R3DShader.cpp model3emu-patch/Src/Graphics/New3D/R3DShader.cpp --- model3emu/Src/Graphics/New3D/R3DShader.cpp 2017-07-29 21:45:07.000000000 +0200 +++ model3emu-patch/Src/Graphics/New3D/R3DShader.cpp 2017-07-29 21:22:10.000000000 +0200 @@ -11,16 +11,42 @@ uniform float fogStart; uniform float modelScale; -//outputs to fragment shader +// outputs to fragment shader varying float fsFogFactor; varying vec3 fsViewVertex; varying vec3 fsViewNormal; // per vertex normal vector varying vec4 fsColor; +// helper functions +vec3 getScale(in mat3 matrix) +{ + vec3 scale; + + scale.x = length(matrix[0]); + scale.y = length(matrix[1]); + scale.z = length(matrix[2]); + + return scale; +} + void main(void) { + mat3 normalMatrix = mat3(gl_ModelViewMatrix); + vec3 normalVector = gl_Normal; + vec3 scaleFactor = getScale(normalMatrix); + + float nLength = length(normalVector); + if (nLength > 0.0) + normalVector /= vec3(nLength); + + if (modelScale != 1.0) + normalVector /= modelScale; + else + normalVector /= scaleFactor; + fsViewVertex = vec3(gl_ModelViewMatrix * gl_Vertex); - fsViewNormal = (mat3(gl_ModelViewMatrix) * gl_Normal) / modelScale; + fsViewNormal = (normalMatrix * normalVector); + float z = length(fsViewVertex); fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0); @@ -137,7 +163,7 @@ // Total light intensity: sum of all components lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y); // diffuse + ambient - lightIntensity = clamp(lightIntensity,0.0,1.0); + //lightIntensity = clamp(lightIntensity,0.0,1.0); // Compute spotlight and apply lighting float enable, range, d; PK ®ýJ×éYf±± $ diff.patch Á^–£ÓÁ^–£Ó磤¢ÓPK\Ù