├── LICENSE ├── README.md ├── screenshots ├── screenshot1.png ├── screenshot2.png └── screenshot3.png └── shaders ├── default_shader ├── opengl_fragment.glsl └── opengl_vertex.glsl ├── minimap_shader ├── opengl_fragment.glsl └── opengl_vertex.glsl ├── nodes_shader ├── opengl_fragment.glsl └── opengl_vertex.glsl ├── selection_shader ├── opengl_fragment.glsl └── opengl_vertex.glsl └── wielded_shader ├── opengl_fragment.glsl └── opengl_vertex.glsl /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Presence 2 | Colour-enhancing shaders for Minetest 3 | 4 | This is my attempt at subtly improving Minetest graphics without modifying core engine code. If you have any suggestions for future improvement, feel free to contact me, as I know little about the Minetest graphics code. 5 | 6 | ![screenshot](https://raw.githubusercontent.com/random-geek/Presence/master/screenshots/screenshot1.png "Underground room") 7 | 8 | ![screenshot](https://raw.githubusercontent.com/random-geek/Presence/master/screenshots/screenshot2.png "Cave") 9 | 10 | ![screenshot](https://raw.githubusercontent.com/random-geek/Presence/master/screenshots/screenshot3.png "Snowy area at dawn") 11 | 12 | ## Installation 13 | Rename the `/client/shaders` directory to something else (or delete it entirely). Then copy the `shaders` folder to the `client` folder. The shaders will take effect after leaving and rejoining the game. 14 | 15 | ## Credits 16 | All shaders are identical to or are derivative works of the original shaders for Minetest, found [here](https://github.com/minetest/minetest/tree/master/client/shaders). All due credit goes to the original author(s) of this code. 17 | -------------------------------------------------------------------------------- /screenshots/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-geek/Presence/26c8e404181936ce2eb269761ae3ba72f8ea5029/screenshots/screenshot1.png -------------------------------------------------------------------------------- /screenshots/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-geek/Presence/26c8e404181936ce2eb269761ae3ba72f8ea5029/screenshots/screenshot2.png -------------------------------------------------------------------------------- /screenshots/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-geek/Presence/26c8e404181936ce2eb269761ae3ba72f8ea5029/screenshots/screenshot3.png -------------------------------------------------------------------------------- /shaders/default_shader/opengl_fragment.glsl: -------------------------------------------------------------------------------- 1 | void main(void) 2 | { 3 | gl_FragColor = gl_Color; 4 | } 5 | -------------------------------------------------------------------------------- /shaders/default_shader/opengl_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 mWorldViewProj; 2 | 3 | void main(void) 4 | { 5 | gl_TexCoord[0] = gl_MultiTexCoord0; 6 | gl_Position = mWorldViewProj * gl_Vertex; 7 | 8 | gl_FrontColor = gl_BackColor = gl_Color; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/minimap_shader/opengl_fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D baseTexture; 2 | uniform sampler2D normalTexture; 3 | uniform vec3 yawVec; 4 | 5 | void main (void) 6 | { 7 | vec2 uv = gl_TexCoord[0].st; 8 | 9 | //texture sampling rate 10 | const float step = 1.0 / 256.0; 11 | float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r; 12 | float t = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r; 13 | float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r; 14 | float r = texture2D(normalTexture, vec2(uv.x + step, uv.y)).r; 15 | float br = texture2D(normalTexture, vec2(uv.x + step, uv.y - step)).r; 16 | float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r; 17 | float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r; 18 | float l = texture2D(normalTexture, vec2(uv.x - step, uv.y)).r; 19 | float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl); 20 | float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr); 21 | vec4 bump = vec4 (normalize(vec3 (dX, dY, 0.1)),1.0); 22 | float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0; 23 | vec4 base = texture2D(baseTexture, uv).rgba; 24 | vec3 L = normalize(vec3(0.0, 0.75, 1.0)); 25 | float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0); 26 | float diffuse = dot(yawVec, bump.xyz); 27 | 28 | vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular) * base.rgb; 29 | vec4 col = vec4(color.rgb, base.a); 30 | col *= gl_Color; 31 | gl_FragColor = vec4(col.rgb, base.a); 32 | } 33 | -------------------------------------------------------------------------------- /shaders/minimap_shader/opengl_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 mWorldViewProj; 2 | uniform mat4 mWorld; 3 | 4 | void main(void) 5 | { 6 | gl_TexCoord[0] = gl_MultiTexCoord0; 7 | gl_Position = mWorldViewProj * gl_Vertex; 8 | gl_FrontColor = gl_BackColor = gl_Color; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/nodes_shader/opengl_fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D baseTexture; 2 | uniform sampler2D normalTexture; 3 | uniform sampler2D textureFlags; 4 | 5 | uniform vec4 skyBgColor; 6 | uniform float fogDistance; 7 | uniform vec3 eyePosition; 8 | 9 | varying vec3 vPosition; 10 | varying vec3 worldPosition; 11 | varying float area_enable_parallax; 12 | 13 | varying vec3 eyeVec; 14 | varying vec3 tsEyeVec; 15 | varying vec3 lightVec; 16 | varying vec3 tsLightVec; 17 | 18 | bool normalTexturePresent = false; 19 | 20 | const float e = 2.718281828459; 21 | const float BS = 10.0; 22 | const float fogStart = FOG_START; 23 | const float fogShadingParameter = 1 / ( 1 - fogStart); 24 | 25 | #ifdef ENABLE_TONE_MAPPING 26 | 27 | /* Hable's UC2 Tone mapping parameters 28 | A = 0.22; 29 | B = 0.30; 30 | C = 0.10; 31 | D = 0.20; 32 | E = 0.01; 33 | F = 0.30; 34 | W = 11.2; 35 | equation used: ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F 36 | */ 37 | 38 | vec3 uncharted2Tonemap(vec3 x) 39 | { 40 | return ((x * (0.22 * x + 0.03) + 0.002) / (x * (0.22 * x + 0.3) + 0.06)) - 0.03333; 41 | } 42 | 43 | vec4 applyToneMapping(vec4 color) 44 | { 45 | color = vec4(pow(color.rgb, vec3(2.2)), color.a); 46 | const float gamma = 1.6; 47 | const float exposureBias = 5.5; 48 | color.rgb = uncharted2Tonemap(exposureBias * color.rgb); 49 | // Precalculated white_scale from 50 | //vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W)); 51 | vec3 whiteScale = vec3(1.036015346); 52 | color.rgb *= whiteScale; 53 | return vec4(pow(color.rgb, vec3(1.0 / gamma)), color.a); 54 | } 55 | 56 | #endif 57 | 58 | void get_texture_flags() 59 | { 60 | vec4 flags = texture2D(textureFlags, vec2(0.0, 0.0)); 61 | if (flags.r > 0.5) { 62 | normalTexturePresent = true; 63 | } 64 | } 65 | 66 | float intensity(vec3 color) 67 | { 68 | return (color.r + color.g + color.b) / 3.0; 69 | } 70 | 71 | float get_rgb_height(vec2 uv) 72 | { 73 | return intensity(texture2D(baseTexture, uv).rgb); 74 | } 75 | 76 | vec4 get_normal_map(vec2 uv) 77 | { 78 | vec4 bump = texture2D(normalTexture, uv).rgba; 79 | bump.xyz = normalize(bump.xyz * 2.0 - 1.0); 80 | return bump; 81 | } 82 | 83 | float find_intersection(vec2 dp, vec2 ds) 84 | { 85 | float depth = 1.0; 86 | float best_depth = 0.0; 87 | float size = 0.0625; 88 | for (int i = 0; i < 15; i++) { 89 | depth -= size; 90 | float h = texture2D(normalTexture, dp + ds * depth).a; 91 | if (depth <= h) { 92 | best_depth = depth; 93 | break; 94 | } 95 | } 96 | depth = best_depth; 97 | for (int i = 0; i < 4; i++) { 98 | size *= 0.5; 99 | float h = texture2D(normalTexture,dp + ds * depth).a; 100 | if (depth <= h) { 101 | best_depth = depth; 102 | depth += size; 103 | } else { 104 | depth -= size; 105 | } 106 | } 107 | return best_depth; 108 | } 109 | 110 | float find_intersectionRGB(vec2 dp, vec2 ds) 111 | { 112 | const float depth_step = 1.0 / 24.0; 113 | float depth = 1.0; 114 | for (int i = 0 ; i < 24 ; i++) { 115 | float h = get_rgb_height(dp + ds * depth); 116 | if (h >= depth) 117 | break; 118 | depth -= depth_step; 119 | } 120 | return depth; 121 | } 122 | 123 | void main(void) 124 | { 125 | vec3 color; 126 | vec4 bump; 127 | vec2 uv = gl_TexCoord[0].st; 128 | bool use_normalmap = false; 129 | get_texture_flags(); 130 | 131 | #ifdef ENABLE_PARALLAX_OCCLUSION 132 | vec2 eyeRay = vec2 (tsEyeVec.x, -tsEyeVec.y); 133 | const float scale = PARALLAX_OCCLUSION_SCALE / PARALLAX_OCCLUSION_ITERATIONS; 134 | const float bias = PARALLAX_OCCLUSION_BIAS / PARALLAX_OCCLUSION_ITERATIONS; 135 | 136 | #if PARALLAX_OCCLUSION_MODE == 0 137 | // Parallax occlusion with slope information 138 | if (normalTexturePresent && area_enable_parallax > 0.0) { 139 | for (int i = 0; i < PARALLAX_OCCLUSION_ITERATIONS; i++) { 140 | vec4 normal = texture2D(normalTexture, uv.xy); 141 | float h = normal.a * scale - bias; 142 | uv += h * normal.z * eyeRay; 143 | } 144 | #endif 145 | 146 | #if PARALLAX_OCCLUSION_MODE == 1 147 | // Relief mapping 148 | if (normalTexturePresent && area_enable_parallax > 0.0) { 149 | vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE; 150 | float dist = find_intersection(uv, ds); 151 | uv += dist * ds; 152 | #endif 153 | } else if (GENERATE_NORMALMAPS == 1 && area_enable_parallax > 0.0) { 154 | vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE; 155 | float dist = find_intersectionRGB(uv, ds); 156 | uv += dist * ds; 157 | } 158 | #endif 159 | 160 | #if USE_NORMALMAPS == 1 161 | if (normalTexturePresent) { 162 | bump = get_normal_map(uv); 163 | use_normalmap = true; 164 | } 165 | #endif 166 | 167 | #if GENERATE_NORMALMAPS == 1 168 | if (normalTexturePresent == false) { 169 | float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP)); 170 | float t = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y - SAMPLE_STEP)); 171 | float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP)); 172 | float r = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y)); 173 | float br = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y - SAMPLE_STEP)); 174 | float b = get_rgb_height(vec2(uv.x, uv.y - SAMPLE_STEP)); 175 | float bl = get_rgb_height(vec2(uv.x -SAMPLE_STEP, uv.y - SAMPLE_STEP)); 176 | float l = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y)); 177 | float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl); 178 | float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr); 179 | bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0); 180 | use_normalmap = true; 181 | } 182 | #endif 183 | vec4 base = texture2D(baseTexture, uv).rgba; 184 | 185 | #ifdef ENABLE_BUMPMAPPING 186 | if (use_normalmap) { 187 | vec3 L = normalize(lightVec); 188 | vec3 E = normalize(eyeVec); 189 | float specular = pow(clamp(dot(reflect(L, bump.xyz), E), 0.0, 1.0), 1.0); 190 | float diffuse = dot(-E,bump.xyz); 191 | color = (diffuse + 0.1 * specular) * base.rgb; 192 | } else { 193 | color = base.rgb; 194 | } 195 | #else 196 | color = base.rgb; 197 | #endif 198 | 199 | vec4 col = vec4(color.rgb * gl_Color.rgb, 1.0); 200 | 201 | #ifdef ENABLE_TONE_MAPPING 202 | col = applyToneMapping(col); 203 | #endif 204 | 205 | // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?), 206 | // the fog will only be rendered correctly if the last operation before the 207 | // clamp() is an addition. Else, the clamp() seems to be ignored. 208 | // E.g. the following won't work: 209 | // float clarity = clamp(fogShadingParameter 210 | // * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0); 211 | // As additions usually come for free following a multiplication, the new formula 212 | // should be more efficient as well. 213 | // Note: clarity = (1 - fogginess) 214 | float clarity = clamp(fogShadingParameter 215 | - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0); 216 | col = mix(skyBgColor, col, clarity); 217 | col = vec4(col.rgb, base.a); 218 | 219 | gl_FragColor = col; 220 | } 221 | -------------------------------------------------------------------------------- /shaders/nodes_shader/opengl_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 mWorldViewProj; 2 | uniform mat4 mWorld; 3 | 4 | // Color of the light emitted by the sun. 5 | uniform vec3 dayLight; 6 | uniform vec3 eyePosition; 7 | uniform float animationTimer; 8 | 9 | varying vec3 vPosition; 10 | varying vec3 worldPosition; 11 | 12 | varying vec3 eyeVec; 13 | varying vec3 lightVec; 14 | varying vec3 tsEyeVec; 15 | varying vec3 tsLightVec; 16 | varying float area_enable_parallax; 17 | 18 | // Color of the light emitted by the light sources. 19 | const vec3 artificialLight = vec3(1.04, 1.04, 1.04); 20 | 21 | // random-geek's colour definitions, for use with colour tinting. 22 | const vec3 sunEffect = vec3(1.0, 0.8, 0.4); 23 | const vec3 orange = vec3(1.0, 0.89, 0.75); 24 | const vec3 cyan = vec3(0.75, 0.89, 1.0); 25 | 26 | const float e = 2.718281828459; 27 | const float BS = 10.0; 28 | 29 | // random-geek's custom daylight. Colour temperature is based on amount of light, with intermediate values (dusk and dawn) being the most orange. 30 | vec3 globalSun = dayLight.rgb * mix(vec3(1.0), sunEffect, -2.25 * abs(dayLight.r - 0.5) + 1); 31 | 32 | float smoothCurve(float x) 33 | { 34 | return x * x * (3.0 - 2.0 * x); 35 | } 36 | 37 | 38 | float triangleWave(float x) 39 | { 40 | return abs(fract(x + 0.5) * 2.0 - 1.0); 41 | } 42 | 43 | 44 | float smoothTriangleWave(float x) 45 | { 46 | return smoothCurve(triangleWave(x)) * 2.0 - 1.0; 47 | } 48 | 49 | 50 | void main(void) 51 | { 52 | gl_TexCoord[0] = gl_MultiTexCoord0; 53 | //TODO: make offset depending on view angle and parallax uv displacement 54 | //thats for textures that doesnt align vertically, like dirt with grass 55 | //gl_TexCoord[0].y += 0.008; 56 | 57 | //Allow parallax/relief mapping only for certain kind of nodes 58 | //Variable is also used to control area of the effect 59 | #if (DRAW_TYPE == NDT_NORMAL || DRAW_TYPE == NDT_LIQUID || DRAW_TYPE == NDT_FLOWINGLIQUID) 60 | area_enable_parallax = 1.0; 61 | #else 62 | area_enable_parallax = 0.0; 63 | #endif 64 | 65 | 66 | float disp_x; 67 | float disp_z; 68 | #if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES) || (MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS) 69 | vec4 pos2 = mWorld * gl_Vertex; 70 | float tOffset = (pos2.x + pos2.y) * 0.001 + pos2.z * 0.002; 71 | disp_x = (smoothTriangleWave(animationTimer * 23.0 + tOffset) + 72 | smoothTriangleWave(animationTimer * 11.0 + tOffset)) * 0.4; 73 | disp_z = (smoothTriangleWave(animationTimer * 31.0 + tOffset) + 74 | smoothTriangleWave(animationTimer * 29.0 + tOffset) + 75 | smoothTriangleWave(animationTimer * 13.0 + tOffset)) * 0.5; 76 | #endif 77 | 78 | 79 | #if (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER 80 | vec4 pos = gl_Vertex; 81 | pos.y -= 2.0; 82 | float posYbuf = (pos.z / WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH); 83 | pos.y -= sin(posYbuf) * WATER_WAVE_HEIGHT + sin(posYbuf / 7.0) * WATER_WAVE_HEIGHT; 84 | gl_Position = mWorldViewProj * pos; 85 | #elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES 86 | vec4 pos = gl_Vertex; 87 | pos.x += disp_x; 88 | pos.y += disp_z * 0.1; 89 | pos.z += disp_z; 90 | gl_Position = mWorldViewProj * pos; 91 | #elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS 92 | vec4 pos = gl_Vertex; 93 | if (gl_TexCoord[0].y < 0.05) { 94 | pos.x += disp_x; 95 | pos.z += disp_z; 96 | } 97 | gl_Position = mWorldViewProj * pos; 98 | #else 99 | gl_Position = mWorldViewProj * gl_Vertex; 100 | #endif 101 | 102 | 103 | vPosition = gl_Position.xyz; 104 | worldPosition = (mWorld * gl_Vertex).xyz; 105 | 106 | // Don't generate heightmaps when too far from the eye 107 | float dist = distance (vec3(0.0, 0.0, 0.0), vPosition); 108 | if (dist > 150.0) { 109 | area_enable_parallax = 0.0; 110 | } 111 | 112 | vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0); 113 | 114 | vec3 normal, tangent, binormal; 115 | normal = normalize(gl_NormalMatrix * gl_Normal); 116 | tangent = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz); 117 | binormal = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz); 118 | 119 | vec3 v; 120 | 121 | lightVec = sunPosition - worldPosition; 122 | v.x = dot(lightVec, tangent); 123 | v.y = dot(lightVec, binormal); 124 | v.z = dot(lightVec, normal); 125 | tsLightVec = normalize (v); 126 | 127 | eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; 128 | v.x = dot(eyeVec, tangent); 129 | v.y = dot(eyeVec, binormal); 130 | v.z = dot(eyeVec, normal); 131 | tsEyeVec = normalize (v); 132 | // Calculate color. 133 | // Red, green and blue components are pre-multiplied with 134 | // the brightness, so now we have to multiply these 135 | // colors with the color of the incoming light. 136 | // The pre-baked colors are halved to prevent overflow. 137 | vec4 color; 138 | // The alpha gives the ratio of sunlight in the incoming light. 139 | float nightRatio = 1 - gl_Color.a; 140 | 141 | vec3 localSun = globalSun * mix(cyan, orange, pow(gl_Color.a * globalSun.r, 3)); 142 | 143 | color.rgb = gl_Color.rgb * (gl_Color.a * globalSun + 144 | nightRatio * artificialLight.rgb) * 2; 145 | 146 | // random-geek's contrast; makes lights lighter and darks darker for better clarity. 147 | float light = max(color.r, max(color.g, color.b)); 148 | float lightNew = 0.75*(light-0.5)/(abs(light-0.5) + 0.25) + 0.5; 149 | color.rgb *= lightNew/light; 150 | 151 | // random-geek's colour grading; adds blue to darker areas and orange to lighter areas. 152 | color.rgb *= mix(cyan, orange, pow(lightNew, 2)); 153 | 154 | color.a = 1; 155 | 156 | gl_FrontColor = gl_BackColor = clamp(color, 0.0, 1.0); 157 | } -------------------------------------------------------------------------------- /shaders/selection_shader/opengl_fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D baseTexture; 2 | 3 | void main(void) 4 | { 5 | vec2 uv = gl_TexCoord[0].st; 6 | vec4 color = texture2D(baseTexture, uv); 7 | color.rgb *= gl_Color.rgb; 8 | gl_FragColor = color; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/selection_shader/opengl_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 mWorldViewProj; 2 | 3 | void main(void) 4 | { 5 | gl_TexCoord[0] = gl_MultiTexCoord0; 6 | gl_Position = mWorldViewProj * gl_Vertex; 7 | 8 | gl_FrontColor = gl_BackColor = gl_Color; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/wielded_shader/opengl_fragment.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D baseTexture; 2 | uniform sampler2D normalTexture; 3 | uniform sampler2D textureFlags; 4 | 5 | uniform vec4 skyBgColor; 6 | uniform float fogDistance; 7 | uniform vec3 eyePosition; 8 | 9 | varying vec3 vPosition; 10 | varying vec3 worldPosition; 11 | 12 | varying vec3 eyeVec; 13 | varying vec3 lightVec; 14 | 15 | bool normalTexturePresent = false; 16 | bool texTileableHorizontal = false; 17 | bool texTileableVertical = false; 18 | bool texSeamless = false; 19 | 20 | const float e = 2.718281828459; 21 | const float BS = 10.0; 22 | const float fogStart = FOG_START; 23 | const float fogShadingParameter = 1 / ( 1 - fogStart); 24 | 25 | void get_texture_flags() 26 | { 27 | vec4 flags = texture2D(textureFlags, vec2(0.0, 0.0)); 28 | if (flags.r > 0.5) { 29 | normalTexturePresent = true; 30 | } 31 | if (flags.g > 0.5) { 32 | texTileableHorizontal = true; 33 | } 34 | if (flags.b > 0.5) { 35 | texTileableVertical = true; 36 | } 37 | if (texTileableHorizontal && texTileableVertical) { 38 | texSeamless = true; 39 | } 40 | } 41 | 42 | float intensity(vec3 color) 43 | { 44 | return (color.r + color.g + color.b) / 3.0; 45 | } 46 | 47 | float get_rgb_height(vec2 uv) 48 | { 49 | if (texSeamless) { 50 | return intensity(texture2D(baseTexture, uv).rgb); 51 | } else { 52 | return intensity(texture2D(baseTexture, clamp(uv, 0.0, 0.999)).rgb); 53 | } 54 | } 55 | 56 | vec4 get_normal_map(vec2 uv) 57 | { 58 | vec4 bump = texture2D(normalTexture, uv).rgba; 59 | bump.xyz = normalize(bump.xyz * 2.0 - 1.0); 60 | return bump; 61 | } 62 | 63 | void main(void) 64 | { 65 | vec3 color; 66 | vec4 bump; 67 | vec2 uv = gl_TexCoord[0].st; 68 | bool use_normalmap = false; 69 | get_texture_flags(); 70 | 71 | #if USE_NORMALMAPS == 1 72 | if (normalTexturePresent) { 73 | bump = get_normal_map(uv); 74 | use_normalmap = true; 75 | } 76 | #endif 77 | 78 | #if GENERATE_NORMALMAPS == 1 79 | if (normalTexturePresent == false) { 80 | float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP)); 81 | float t = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y - SAMPLE_STEP)); 82 | float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP)); 83 | float r = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y)); 84 | float br = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y - SAMPLE_STEP)); 85 | float b = get_rgb_height(vec2(uv.x, uv.y - SAMPLE_STEP)); 86 | float bl = get_rgb_height(vec2(uv.x -SAMPLE_STEP, uv.y - SAMPLE_STEP)); 87 | float l = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y)); 88 | float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl); 89 | float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr); 90 | bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0); 91 | use_normalmap = true; 92 | } 93 | #endif 94 | 95 | vec4 base = texture2D(baseTexture, uv).rgba; 96 | 97 | #ifdef ENABLE_BUMPMAPPING 98 | if (use_normalmap) { 99 | vec3 L = normalize(lightVec); 100 | vec3 E = normalize(eyeVec); 101 | float specular = pow(clamp(dot(reflect(L, bump.xyz), E), 0.0, 1.0), 1.0); 102 | float diffuse = dot(-E,bump.xyz); 103 | color = (diffuse + 0.1 * specular) * base.rgb; 104 | } else { 105 | color = base.rgb; 106 | } 107 | #else 108 | color = base.rgb; 109 | #endif 110 | 111 | vec4 col = vec4(color.rgb, base.a); 112 | col *= gl_Color; 113 | // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?), 114 | // the fog will only be rendered correctly if the last operation before the 115 | // clamp() is an addition. Else, the clamp() seems to be ignored. 116 | // E.g. the following won't work: 117 | // float clarity = clamp(fogShadingParameter 118 | // * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0); 119 | // As additions usually come for free following a multiplication, the new formula 120 | // should be more efficient as well. 121 | // Note: clarity = (1 - fogginess) 122 | float clarity = clamp(fogShadingParameter 123 | - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0); 124 | col = mix(skyBgColor, col, clarity); 125 | 126 | gl_FragColor = vec4(col.rgb, base.a); 127 | } 128 | -------------------------------------------------------------------------------- /shaders/wielded_shader/opengl_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 mWorldViewProj; 2 | uniform mat4 mWorld; 3 | 4 | uniform vec3 eyePosition; 5 | uniform float animationTimer; 6 | 7 | varying vec3 vPosition; 8 | varying vec3 worldPosition; 9 | 10 | varying vec3 eyeVec; 11 | varying vec3 lightVec; 12 | varying vec3 tsEyeVec; 13 | varying vec3 tsLightVec; 14 | 15 | const float e = 2.718281828459; 16 | const float BS = 10.0; 17 | 18 | void main(void) 19 | { 20 | gl_TexCoord[0] = gl_MultiTexCoord0; 21 | gl_Position = mWorldViewProj * gl_Vertex; 22 | 23 | vPosition = gl_Position.xyz; 24 | worldPosition = (mWorld * gl_Vertex).xyz; 25 | 26 | vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0); 27 | 28 | lightVec = sunPosition - worldPosition; 29 | eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; 30 | 31 | gl_FrontColor = gl_BackColor = gl_Color; 32 | } 33 | --------------------------------------------------------------------------------