From f50063402dea5ab8a2e1badd2e7566d1ca100cbf Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 21 Sep 2017 00:25:48 +0100 Subject: [PATCH] Adjust shaders to support shadows --- CI/before_script.msvc.sh | 2 +- files/shaders/lighting.glsl | 28 +++++++++++++++++++++------- files/shaders/objects_fragment.glsl | 13 ++++++++++--- files/shaders/objects_vertex.glsl | 6 ++++++ files/shaders/terrain_fragment.glsl | 13 ++++++++++--- files/shaders/terrain_vertex.glsl | 6 ++++++ 6 files changed, 54 insertions(+), 14 deletions(-) diff --git a/CI/before_script.msvc.sh b/CI/before_script.msvc.sh index 14998a3c6..11317a33f 100644 --- a/CI/before_script.msvc.sh +++ b/CI/before_script.msvc.sh @@ -761,7 +761,7 @@ if [ -z $CI ]; then echo " settings-default.cfg" cp settings-default.cfg $BUILD_CONFIG/settings-default.cfg echo " resources/" - cp -r resources $BUILD_CONFIG/resources + cp -r resources $BUILD_CONFIG echo fi diff --git a/files/shaders/lighting.glsl b/files/shaders/lighting.glsl index 7b8486fbe..892ae485a 100644 --- a/files/shaders/lighting.glsl +++ b/files/shaders/lighting.glsl @@ -1,10 +1,23 @@ #define MAX_LIGHTS 8 -vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor) +vec3 perLight(int lightIndex, vec3 viewPos, vec3 viewNormal, vec4 diffuse, vec3 ambient) { vec3 lightDir; float d; + lightDir = gl_LightSource[lightIndex].position.xyz - (viewPos.xyz * gl_LightSource[lightIndex].position.w); + d = length(lightDir); + lightDir = normalize(lightDir); + + return (ambient * gl_LightSource[lightIndex].ambient.xyz + diffuse.xyz * gl_LightSource[lightIndex].diffuse.xyz * max(dot(viewNormal.xyz, lightDir), 0.0)) * clamp(1.0 / (gl_LightSource[lightIndex].constantAttenuation + gl_LightSource[lightIndex].linearAttenuation * d + gl_LightSource[lightIndex].quadraticAttenuation * d * d), 0.0, 1.0); +} + +#ifdef FRAGMENT +vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, float shadowing) +#else +vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor) +#endif +{ #if @colorMode == 3 vec4 diffuse = gl_FrontMaterial.diffuse; vec3 ambient = vertexColor.xyz; @@ -17,13 +30,14 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor) #endif vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a); - for (int i=0; i