From 1abc5624fbdea50566cce974a0d99699ed98fb45 Mon Sep 17 00:00:00 2001 From: Vivian Meazza Date: Sun, 27 Nov 2011 23:59:33 +0000 Subject: [PATCH] New fog shader Signed-off-by: Vivian Meazza --- Shaders/include_fog.frag | 19 +++++++++++++++++++ Shaders/include_fog.vert | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Shaders/include_fog.frag create mode 100644 Shaders/include_fog.vert diff --git a/Shaders/include_fog.frag b/Shaders/include_fog.frag new file mode 100644 index 000000000..bb8b2bdc7 --- /dev/null +++ b/Shaders/include_fog.frag @@ -0,0 +1,19 @@ +//#define FOG_FUNCTION +//default fog +//varying float fogCoord; +varying vec3 PointPos; +//varying vec4 EyePos; + +vec3 fog_Func(vec3 color, int type) +{ + //if (type == 0){ + const float LOG2 = 1.442695; + //vec3 EyePos = vec3(0.0); + float fogCoord =length(PointPos); + float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); + + if(gl_Fog.density == 1.0) + fogFactor=1.0; + + return mix(gl_Fog.color.rgb, color, fogFactor); +} \ No newline at end of file diff --git a/Shaders/include_fog.vert b/Shaders/include_fog.vert new file mode 100644 index 000000000..2286437ab --- /dev/null +++ b/Shaders/include_fog.vert @@ -0,0 +1,11 @@ +//varying float fogCoord; +varying vec3 PointPos; +//varying vec4 EyePos; + +void fog_func(int type) +{ + PointPos = (gl_ModelViewMatrix * gl_Vertex).xyz; + //PointPos = gl_Vertex; + //EyePos = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); + //fogCoord = abs(ecPosition.z); +}