From 1223bca3d4405ef2a1e2e5512322c11ceb680a46 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 17 Feb 2016 23:29:26 +0100 Subject: [PATCH] Move doLighting to separate file --- files/shaders/CMakeLists.txt | 1 + files/shaders/lighting.glsl | 37 +++++++++++++++++++++++++++++ files/shaders/objects_vertex.glsl | 39 +------------------------------ 3 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 files/shaders/lighting.glsl diff --git a/files/shaders/CMakeLists.txt b/files/shaders/CMakeLists.txt index edb5b51f2..a7b631139 100644 --- a/files/shaders/CMakeLists.txt +++ b/files/shaders/CMakeLists.txt @@ -8,6 +8,7 @@ set(SHADER_FILES water_nm.png objects_vertex.glsl objects_fragment.glsl + lighting.glsl ) copy_all_files(${CMAKE_CURRENT_SOURCE_DIR} ${DDIR} "${SHADER_FILES}") diff --git a/files/shaders/lighting.glsl b/files/shaders/lighting.glsl new file mode 100644 index 000000000..98490b8b8 --- /dev/null +++ b/files/shaders/lighting.glsl @@ -0,0 +1,37 @@ +#define MAX_LIGHTS 8 + +vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor) +{ + vec3 lightDir; + float d; + +#if @colorMode == 2 + vec4 diffuse = vertexColor; + vec3 ambient = vertexColor.xyz; +#else + vec4 diffuse = gl_FrontMaterial.diffuse; + vec3 ambient = gl_FrontMaterial.ambient.xyz; +#endif + vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a); + + for (int i=0; i