diff --git a/data/shaders/grass.frag b/data/shaders/grass.frag index c0ac2d7f4..cdf9601ac 100644 --- a/data/shaders/grass.frag +++ b/data/shaders/grass.frag @@ -1,8 +1,10 @@ -/*--- GENERIC HEADER -----------------------------------------------------------------------------*/ +#version 130 -varying vec3 nor; uniform float far; uniform float objectid; +uniform sampler2D tex; + +noperspective in vec3 nor; const float near = 1.0; @@ -13,28 +15,16 @@ vec4 encdepth(float v) { return enc; } -/*--- END OF GENERIC HEADER ----------------------------------------------------------------------*/ - - -uniform sampler2D tex; - void main() { vec4 color = texture2D(tex, gl_TexCoord[0].st); - - - -/*--- GENERIC FOOTER -----------------------------------------------------------------------------*/ - float linear_z = (2.0 * near) / (far + near - gl_FragCoord.z * (far - near)); // Tune for better inside range without losing outdoors linear_z *= 2.0; gl_FragData[0] = color; - gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[1] = vec4(0.5 * normalize(nor) + 0.5, linear_z); gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); - -/*--- END OF GENERIC FOOTER ----------------------------------------------------------------------*/ } diff --git a/data/shaders/grass.vert b/data/shaders/grass.vert index a2492d1d0..f47cb38c4 100644 --- a/data/shaders/grass.vert +++ b/data/shaders/grass.vert @@ -1,13 +1,8 @@ -/*--- GENERIC HEADER ---*/ - -varying vec3 nor; -uniform mat4 invtworldm; - - -/*--- END OF GENERIC HEADER --*/ - +#version 130 uniform vec3 windDir; +noperspective out vec3 nor; + void main() { gl_TexCoord[0] = gl_MultiTexCoord0; @@ -15,11 +10,6 @@ void main() vec4 vertexPosition = gl_Vertex; vertexPosition.xyz += windDir * gl_Color.r; - nor = (invtworldm * vec4(gl_Normal, 0.0)).xyz; - nor = normalize(nor); - nor = nor * 0.5 + 0.5; - + nor = gl_NormalMatrix * gl_Normal; gl_Position = gl_ModelViewProjectionMatrix * vertexPosition; - - } diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index 1040e1662..19cd4c080 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -1,36 +1,33 @@ -// Shader based on work by Fabien Sanglard -// Released under the terms of CC-BY 3.0 +#version 130 +uniform sampler2D texture; //The texture +uniform sampler2D normalMap; //The bump-map -uniform sampler2D BumpTex; //The bump-map -uniform sampler2D DecalTex; //The texture -uniform sampler2D LightMapTex; -uniform int HasLightMap; - -// New bumpmapping -varying vec3 lightVec; -varying vec3 halfVec; -varying vec3 eyeVec; +noperspective in vec3 tangent; +noperspective in vec3 bitangent; +noperspective in vec3 normal; +vec4 encdepth(float v) { + vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v; + enc = fract(enc); + enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0); + return enc; +} void main() { - // lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize - vec3 normal = 2.0 * texture2D (BumpTex, gl_TexCoord[0].st).rgb - 1.0; - normal = normalize (normal); + // normal in Tangent Space + vec3 TS_normal = 2.0 * texture2D (normalMap, gl_TexCoord[0].st).rgb - 1.0; + // Because of interpolation, we need to renormalize + vec3 Frag_tangent = normalize(tangent); + vec3 Frag_bitangent = normalize(cross(normal, tangent)); + vec3 Frag_normal = cross(Frag_tangent, Frag_bitangent); - // compute diffuse lighting - float lamberFactor = max (dot (lightVec, normal), 0.0); - vec4 diffuseMaterial; - diffuseMaterial = texture2D (DecalTex, gl_TexCoord[0].st); + vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent + TS_normal.z * Frag_normal; + FragmentNormal = normalize(FragmentNormal); + - if (HasLightMap < 1) - { - // 0.5 is the ambient light - gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5); - } - else - { - gl_FragColor = diffuseMaterial * (0.5 + lamberFactor*0.5) * texture2D(LightMapTex, gl_TexCoord[0].st); - } + gl_FragData[0] = texture2D (texture, gl_TexCoord[0].st); + gl_FragData[1] = vec4(0.5 * FragmentNormal + 0.5, 1.0); + gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, 0.0); } diff --git a/data/shaders/normalmap.vert b/data/shaders/normalmap.vert index 118917190..74764101c 100644 --- a/data/shaders/normalmap.vert +++ b/data/shaders/normalmap.vert @@ -1,54 +1,14 @@ -// Shader based on work by Fabien Sanglard -// Released under the terms of CC-BY 3.0 - -varying vec3 lightVec; -varying vec3 halfVec; -varying vec3 eyeVec; - -uniform vec3 lightdir; +#version 130 +noperspective out vec3 tangent; +noperspective out vec3 bitangent; +noperspective out vec3 normal; void main() { - gl_TexCoord[0] = gl_MultiTexCoord0; - - // Building the matrix Eye Space -> Tangent Space - vec3 n = normalize (gl_NormalMatrix * gl_Normal); - vec3 t = normalize (gl_NormalMatrix * gl_MultiTexCoord1.xyz); // tangent - vec3 b = cross (n, t); - - vec3 vertexPosition = vec3(gl_ModelViewMatrix * gl_Vertex); - - // transform light and half angle vectors by tangent basis - vec3 v; - v.x = dot (lightdir, t); - v.y = dot (lightdir, b); - v.z = dot (lightdir, n); - lightVec = normalize (v); - - - v.x = dot (vertexPosition, t); - v.y = dot (vertexPosition, b); - v.z = dot (vertexPosition, n); - eyeVec = normalize (v); - - - vertexPosition = normalize(vertexPosition); - - // Normalize the halfVector to pass it to the fragment shader - - // No need to divide by two, the result is normalized anyway. - // vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0); - vec3 halfVector = normalize(vertexPosition + lightdir); - v.x = dot (halfVector, t); - v.y = dot (halfVector, b); - v.z = dot (halfVector, n); - - // No need to normalize, t,b,n and halfVector are normal vectors. - //normalize (v); - halfVec = v ; - - + normal = gl_NormalMatrix * gl_Normal; + tangent = gl_NormalMatrix * gl_MultiTexCoord1.xyz; + bitangent = gl_NormalMatrix * gl_MultiTexCoord2.xyz; gl_Position = ftransform(); } \ No newline at end of file diff --git a/data/shaders/objectpass.frag b/data/shaders/objectpass.frag index c557894d2..6c01dff40 100644 --- a/data/shaders/objectpass.frag +++ b/data/shaders/objectpass.frag @@ -1,5 +1,4 @@ -varying vec3 nor; - +#version 130 uniform sampler2D tex; uniform sampler2D lighttex; uniform float far; @@ -7,6 +6,8 @@ uniform int hastex; uniform int haslightmap; uniform float objectid; +noperspective in vec3 nor; + const float near = 1.0; vec4 encdepth(float v) { @@ -34,7 +35,7 @@ void main() { else gl_FragData[0] = gl_Color; - gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[1] = vec4(0.5 * normalize(nor) + 0.5, linear_z); gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); } diff --git a/data/shaders/objectpass.vert b/data/shaders/objectpass.vert index 76e749908..7ddbb49ca 100644 --- a/data/shaders/objectpass.vert +++ b/data/shaders/objectpass.vert @@ -1,12 +1,10 @@ -varying vec3 nor; -uniform mat4 invtworldm; +#version 130 + +noperspective out vec3 nor; void main() { - nor = (invtworldm * vec4(gl_Normal, 0.0)).xyz; - nor = normalize(nor); - nor = nor * 0.5 + 0.5; - + nor = gl_NormalMatrix * gl_Normal; gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; gl_Position = ftransform(); diff --git a/data/shaders/objectpass_ref.frag b/data/shaders/objectpass_ref.frag index 856561b35..1256a6715 100644 --- a/data/shaders/objectpass_ref.frag +++ b/data/shaders/objectpass_ref.frag @@ -1,9 +1,11 @@ -varying vec3 nor; +#version 130 uniform sampler2D tex; uniform float far; uniform int hastex; uniform float objectid; +noperspective in vec3 nor; + const float near = 1.0; vec4 encdepth(float v) { @@ -31,7 +33,7 @@ void main() { // gl_FragData[0] = gl_Color; //} - gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[1] = vec4(0.5 * normalize(nor) + 0.5, linear_z); gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); } diff --git a/data/shaders/objectpass_rimlit.frag b/data/shaders/objectpass_rimlit.frag index 5979f2214..49f7e9699 100644 --- a/data/shaders/objectpass_rimlit.frag +++ b/data/shaders/objectpass_rimlit.frag @@ -1,11 +1,12 @@ -varying vec3 nor; +#version 130 uniform sampler2D tex; uniform float far; uniform int hastex; uniform float objectid; -varying vec3 eyenor; -varying vec3 viewpos; +noperspective in vec3 nor; +noperspective in vec3 eyenor; +noperspective in vec3 viewpos; const float near = 1.0; @@ -39,7 +40,7 @@ void main() { gl_FragData[0] = gl_Color + vec4(vec3(rim), 0.0); } - gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[1] = vec4(0.5 * normalize(nor) + 0.5, linear_z); gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); } diff --git a/data/shaders/objectpass_rimlit.vert b/data/shaders/objectpass_rimlit.vert index b3d98e449..14301c042 100644 --- a/data/shaders/objectpass_rimlit.vert +++ b/data/shaders/objectpass_rimlit.vert @@ -1,15 +1,11 @@ -varying vec3 nor; -uniform mat4 invtworldm; +#version 130 -varying vec3 eyenor; -varying vec3 viewpos; +noperspective out vec3 nor; +noperspective out vec3 eyenor; +noperspective out vec3 viewpos; void main() { - - nor = (invtworldm * vec4(gl_Normal, 0.0)).xyz; - nor = normalize(nor); - nor = nor * 0.5 + 0.5; - + nor = gl_NormalMatrix * gl_Normal; eyenor = gl_NormalMatrix * gl_Normal; viewpos = -normalize((gl_ModelViewMatrix * gl_Vertex).xyz); diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index f8abac686..3a47f7794 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,10 +1,11 @@ -varying vec3 nor; +#version 130 uniform sampler2D tex; uniform float far; uniform float objectid; -varying vec3 eyenor; -varying vec3 viewpos; +noperspective in vec3 eyenor; +noperspective in vec3 viewpos; +noperspective in vec3 nor; const float near = 1.0; diff --git a/data/shaders/pointlight.frag b/data/shaders/pointlight.frag index facc40c0e..4908709d7 100644 --- a/data/shaders/pointlight.frag +++ b/data/shaders/pointlight.frag @@ -3,48 +3,39 @@ uniform sampler2D dtex; uniform vec3 center; uniform vec3 col; -uniform vec3 campos; uniform float r; uniform float spec; uniform vec2 screen; -uniform mat4 invprojview; +uniform mat4 invproj; float decdepth(vec4 rgba) { return dot(rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0)); } void main() { - vec2 texc = gl_FragCoord.xy / screen; float z = decdepth(vec4(texture2D(dtex, texc).xyz, 0.0)); - if (z < 0.03) discard; - - vec3 tmp = vec3(texc, z); - tmp = tmp * 2.0 - 1.0; - - vec4 xpos = vec4(tmp, 1.0); - xpos = invprojview * xpos; - xpos.xyz /= xpos.w; + vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f; + xpos = invproj * xpos; + xpos /= xpos.w; float d = distance(center, xpos.xyz); if (d > r) discard; - float att = 1.0 - smoothstep(0.0, r, d); vec3 norm = texture2D(ntex, texc).xyz; norm = (norm - 0.5) * 2.0; - vec3 camdir = normalize(campos - xpos.xyz); + // Light Direction + vec3 L = normalize(xpos.xyz - center); + vec3 eyedir = normalize(xpos.xyz); + vec3 H = normalize(-L + eyedir); - vec3 L = normalize(center - xpos.xyz); - vec3 H = normalize(L + camdir); - - float NdotL = max(0.0, dot(norm, L)) * att; - if (NdotL < 0.01) discard; + float NdotL = max(0.0, dot(norm, -L)) * att; float NdotH = max(0.0, dot(norm, H)); NdotH = pow(NdotH, spec); NdotH += 0.05; // offset so that the alpha test doesn't kill us - gl_FragColor = NdotL * vec4(col, NdotH); + gl_FragColor = NdotL * vec4(NdotL * col, NdotH); } diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag index ac5e9f7ac..588199f1e 100644 --- a/data/shaders/splatting.frag +++ b/data/shaders/splatting.frag @@ -1,4 +1,4 @@ -varying vec3 nor; +#version 130 uniform float far; uniform float objectid; @@ -9,6 +9,8 @@ uniform sampler2D tex_detail2; uniform sampler2D tex_detail3; //uniform sampler2D tex_detail4; +noperspective in vec3 nor; + const float near = 1.0; vec4 encdepth(float v) { @@ -43,6 +45,6 @@ void main() { gl_FragData[0] = splatted; - gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[1] = vec4(normalize(nor) * 0.5 + 0.5, linear_z); gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); } diff --git a/data/shaders/splatting.vert b/data/shaders/splatting.vert index 4eb1545f8..d1077f703 100644 --- a/data/shaders/splatting.vert +++ b/data/shaders/splatting.vert @@ -15,20 +15,16 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -varying vec3 normal; -varying vec4 vertex_color; -varying vec3 lightdir2; +#version 130 uniform vec3 lightdir; +noperspective out vec3 normal; + void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; gl_Position = ftransform(); - vertex_color = gl_Color; - //normal = normalize(gl_NormalMatrix * gl_Normal); - normal = normalize(gl_Normal); - lightdir2 = normalize(lightdir); + normal = gl_NormalMatrix * gl_Normal; } diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index 7669ce9c1..9edee8d59 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -5,7 +5,7 @@ uniform sampler2D cloudtex; uniform vec3 center; uniform vec3 col; uniform vec2 screen; -uniform mat4 invprojview; +uniform mat4 invproj; uniform int hasclouds; uniform vec2 wind; @@ -42,7 +42,7 @@ void main() { tmp = tmp * 2.0 - 1.0; vec4 xpos = vec4(tmp, 1.0); - xpos = invprojview * xpos; + xpos = invproj * xpos; xpos.xyz /= xpos.w; vec2 cloudcoord = (xpos.xz * 0.00833333) + wind; diff --git a/src/graphics/callbacks.cpp b/src/graphics/callbacks.cpp index 8b5e9cd30..2c9a9079a 100644 --- a/src/graphics/callbacks.cpp +++ b/src/graphics/callbacks.cpp @@ -31,24 +31,15 @@ void NormalMapProvider::OnSetConstants(IMaterialRendererServices *srv, int) { if (!firstdone) { - s32 decaltex = 0; - srv->setPixelShaderConstant("DecalTex", &decaltex, 1); + s32 texture = 0; + srv->setPixelShaderConstant("texture", &texture, 1); - s32 bumptex = 1; - srv->setPixelShaderConstant("BumpTex", &bumptex, 1); - - s32 lightmapTex = (m_with_lightmap ? 2 : 0); - srv->setPixelShaderConstant("LightMapTex", &lightmapTex, 1); - - s32 hasLightMap = (m_with_lightmap ? 1 : 0); - srv->setPixelShaderConstant("HasLightMap", &hasLightMap, 1); + s32 normaltex = 1; + srv->setPixelShaderConstant("normalMap", &normaltex, 1); // We could calculate light direction as coming from the sun (then we'd need to // transform it into camera space). But I find that pretending light // comes from the camera gives good results - const float lightdir[] = {0.1852f, -0.1852f, -0.9259f}; - srv->setVertexShaderConstant("lightdir", lightdir, 3); - firstdone = true; } @@ -122,14 +113,6 @@ void GrassShaderProvider::OnSetConstants(IMaterialRendererServices *srv, int use const float camfar = irr_driver->getSceneManager()->getActiveCamera()->getFarValue(); srv->setVertexShaderConstant("far", &camfar, 1); - // The normal is transformed by the inverse transposed world matrix - // because we want world-space normals - matrix4 invtworldm = irr_driver->getVideoDriver()->getTransform(ETS_WORLD); - invtworldm.makeInverse(); - invtworldm = invtworldm.getTransposed(); - - srv->setVertexShaderConstant("invtworldm", invtworldm.pointer(), 16); - float objectid = 0; const stringc name = mat.TextureLayer[0].Texture->getName().getPath(); objectid = shash8((const u8 *) name.c_str(), name.size()) / 255.0f; @@ -185,14 +168,6 @@ void SplattingProvider::OnSetConstants(IMaterialRendererServices *srv, int) const float camfar = irr_driver->getSceneManager()->getActiveCamera()->getFarValue(); srv->setVertexShaderConstant("far", &camfar, 1); - // The normal is transformed by the inverse transposed world matrix - // because we want world-space normals - matrix4 invtworldm = irr_driver->getVideoDriver()->getTransform(ETS_WORLD); - invtworldm.makeInverse(); - invtworldm = invtworldm.getTransposed(); - - srv->setVertexShaderConstant("invtworldm", invtworldm.pointer(), 16); - float objectid = 0; const stringc name = mat.TextureLayer[0].Texture->getName().getPath(); objectid = shash8((const u8 *) name.c_str(), name.size()) / 255.0f; @@ -352,14 +327,6 @@ void ObjectPassProvider::OnSetConstants(IMaterialRendererServices *srv, int) const float camfar = irr_driver->getSceneManager()->getActiveCamera()->getFarValue(); srv->setVertexShaderConstant("far", &camfar, 1); - // The normal is transformed by the inverse transposed world matrix - // because we want world-space normals - matrix4 invtworldm = irr_driver->getVideoDriver()->getTransform(ETS_WORLD); - invtworldm.makeInverse(); - invtworldm = invtworldm.getTransposed(); - - srv->setVertexShaderConstant("invtworldm", invtworldm.pointer(), 16); - const int hastex = mat.TextureLayer[0].Texture != NULL; srv->setVertexShaderConstant("hastex", &hastex, 1); @@ -405,10 +372,9 @@ void PointLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) srv->setVertexShaderConstant("screen", m_screen, 2); srv->setVertexShaderConstant("spec", &m_specular, 1); srv->setVertexShaderConstant("col", m_color, 3); - srv->setVertexShaderConstant("campos", m_campos, 3); srv->setVertexShaderConstant("center", m_pos, 3); srv->setVertexShaderConstant("r", &m_radius, 1); - srv->setVertexShaderConstant("invprojview", m_invprojview.pointer(), 16); + srv->setVertexShaderConstant("invproj", m_invproj.pointer(), 16); if (!firstdone) { @@ -432,7 +398,7 @@ void SunLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) srv->setVertexShaderConstant("screen", m_screen, 2); srv->setVertexShaderConstant("col", m_color, 3); srv->setVertexShaderConstant("center", m_pos, 3); - srv->setVertexShaderConstant("invprojview", m_invprojview.pointer(), 16); + srv->setVertexShaderConstant("invproj", m_invproj.pointer(), 16); srv->setVertexShaderConstant("hasclouds", &hasclouds, 1); const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; diff --git a/src/graphics/callbacks.hpp b/src/graphics/callbacks.hpp index 341b02e83..5d3cefd1e 100644 --- a/src/graphics/callbacks.hpp +++ b/src/graphics/callbacks.hpp @@ -371,7 +371,6 @@ public: }; // - class PointLightProvider: public CallBase { public: @@ -394,9 +393,20 @@ public: void setPosition(float x, float y, float z) { - m_pos[0] = x; - m_pos[1] = y; - m_pos[2] = z; + const core::vector3df &campos = + irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition(); + const video::IVideoDriver * const drv = irr_driver->getVideoDriver(); + core::vector3df pos(x,y,z); + pos -= campos; + + // get position in eye space coordinates + core::matrix4 m_view = drv->getTransform(video::ETS_VIEW); + float *mat = m_view.pointer(); + + float scale = mat[3] * x + mat[7] * y + mat[11] * z + mat[15]; + m_pos[0] = (mat[0] * x + mat[4] * y + mat[8] * z + mat[12]) / scale; + m_pos[1] = (mat[1] * x + mat[5] * y + mat[9] * z + mat[13]) / scale; + m_pos[2] = (mat[2] * x + mat[6] * y + mat[10] * z + mat[14]) / scale; } void setRadius(float r) @@ -411,24 +421,15 @@ public: void updateIPVMatrix() { - // Update the campos and IPV matrix, only once per frame since it's costly - const core::vector3df &campos = - irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition(); - m_campos[0] = campos.X; - m_campos[1] = campos.Y; - m_campos[2] = campos.Z; - const video::IVideoDriver * const drv = irr_driver->getVideoDriver(); - m_invprojview = drv->getTransform(video::ETS_PROJECTION); - m_invprojview *= drv->getTransform(video::ETS_VIEW); - m_invprojview.makeInverse(); + m_invproj = drv->getTransform(video::ETS_PROJECTION); + m_invproj.makeInverse(); } private: - core::matrix4 m_invprojview; + core::matrix4 m_invproj; - float m_campos[3]; float m_color[3]; float m_pos[3]; float m_screen[2]; @@ -460,9 +461,17 @@ public: void setPosition(float x, float y, float z) { - m_pos[0] = x; - m_pos[1] = y; - m_pos[2] = z; + const video::IVideoDriver * const drv = irr_driver->getVideoDriver(); + // Sun "position" is actually a direction and not a position + core::matrix4 m_view = drv->getTransform(video::ETS_VIEW); + m_view.makeInverse(); + m_view = m_view.getTransposed(); + core::vector3df pos(x, y, z); + m_view.transformVect(pos); + pos.normalize(); + m_pos[0] = pos.X; + m_pos[1] = pos.Y; + m_pos[2] = pos.Z; } void updateIPVMatrix() @@ -470,9 +479,8 @@ public: // Update the IPV matrix, only once per frame since it's costly const video::IVideoDriver * const drv = irr_driver->getVideoDriver(); - m_invprojview = drv->getTransform(video::ETS_PROJECTION); - m_invprojview *= drv->getTransform(video::ETS_VIEW); - m_invprojview.makeInverse(); + m_invproj = drv->getTransform(video::ETS_PROJECTION); + m_invproj.makeInverse(); } void setShadowMatrix(const core::matrix4 &mat) @@ -481,7 +489,7 @@ public: } private: - core::matrix4 m_invprojview, m_shadowmat; + core::matrix4 m_invproj, m_shadowmat; float m_color[3]; float m_pos[3]; float m_screen[2]; diff --git a/src/graphics/sun.cpp b/src/graphics/sun.cpp index 6f1f70acb..514aec28e 100644 --- a/src/graphics/sun.cpp +++ b/src/graphics/sun.cpp @@ -88,7 +88,6 @@ void SunNode::render() cb->setColor(m_color[0], m_color[1], m_color[2]); vector3df pos = getPosition(); - pos.normalize(); cb->setPosition(pos.X, pos.Y, pos.Z); if (!UserConfigParams::m_shadows || !World::getWorld()->getTrack()->hasShadows())