Rembrandt: Create an effect for the fog stage. Duplicates the C++ code for now.
This commit is contained in:
parent
984bb05046
commit
bdc642f068
3 changed files with 111 additions and 0 deletions
73
Effects/fog.eff
Normal file
73
Effects/fog.eff
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PropertyList>
|
||||
<name>Effects/sunlight</name>
|
||||
<technique n="11">
|
||||
<pass>
|
||||
<lighting>false</lighting>
|
||||
<depth>
|
||||
<enabled>false</enabled>
|
||||
</depth>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<render-bin>
|
||||
<bin-number>10000</bin-number>
|
||||
<bin-name>RenderBin</bin-name>
|
||||
</render-bin>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>depth-buffer</type>
|
||||
</texture-unit>
|
||||
<texture-unit>
|
||||
<unit>1</unit>
|
||||
<type>normal-buffer</type>
|
||||
</texture-unit>
|
||||
<texture-unit>
|
||||
<unit>2</unit>
|
||||
<type>diffuse-buffer</type>
|
||||
</texture-unit>
|
||||
<texture-unit>
|
||||
<unit>3</unit>
|
||||
<type>spec-emis-buffer</type>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/fog.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/fog.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>depth_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>normal_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">1</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>color_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">2</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>spec_emis_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">3</value>
|
||||
</uniform>
|
||||
<!-- The following uniforms are automatically defined and initialized :
|
||||
- fg_SunAmbientColor
|
||||
- fg_SunDiffuseColor
|
||||
- fg_SunSpecularColor
|
||||
- fg_SunDirection
|
||||
- fg_ProjectionMatrixInverse
|
||||
- fg_ViewMatrixInverse
|
||||
- fg_ViewMatrix
|
||||
- fg_Planes
|
||||
- fg_FogColor
|
||||
- fg_FogDensity
|
||||
-->
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
31
Shaders/fog.frag
Normal file
31
Shaders/fog.frag
Normal file
|
@ -0,0 +1,31 @@
|
|||
uniform sampler2D depth_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
uniform sampler2D color_tex;
|
||||
uniform sampler2D spec_emis_tex;
|
||||
uniform vec4 fg_FogColor;
|
||||
uniform float fg_FogDensity;
|
||||
uniform vec3 fg_Planes;
|
||||
varying vec3 ray;
|
||||
void main() {
|
||||
vec2 coords = gl_TexCoord[0].xy;
|
||||
float initialized = texture2D( spec_emis_tex, coords ).a;
|
||||
if ( initialized < 0.1 )
|
||||
discard;
|
||||
vec3 normal;
|
||||
normal.xy = texture2D( normal_tex, coords ).rg * 2.0 - vec2(1.0,1.0);
|
||||
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||
float len = length(normal);
|
||||
normal /= len;
|
||||
vec3 viewDir = normalize(ray);
|
||||
float depth = texture2D( depth_tex, coords ).r;
|
||||
vec3 pos;
|
||||
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||
pos.xy = viewDir.xy / viewDir.z * pos.z;
|
||||
|
||||
float fogFactor = 0.0;
|
||||
const float LOG2 = 1.442695;
|
||||
fogFactor = exp2(-fg_FogDensity * fg_FogDensity * pos.z * pos.z * LOG2);
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
gl_FragColor = vec4(fg_FogColor.rgb, 1.0 - fogFactor);
|
||||
}
|
7
Shaders/fog.vert
Normal file
7
Shaders/fog.vert
Normal file
|
@ -0,0 +1,7 @@
|
|||
uniform mat4 fg_ProjectionMatrixInverse;
|
||||
varying vec3 ray;
|
||||
void main() {
|
||||
gl_Position = gl_Vertex;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
ray = (fg_ProjectionMatrixInverse * gl_Vertex).xyz;
|
||||
}
|
Loading…
Reference in a new issue