1
0
Fork 0

Make runway shader work with Rembrandt

Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
Emilian Huminiuc 2012-06-23 23:09:54 +03:00
parent 4bf1738cd7
commit 333d70aeca
3 changed files with 463 additions and 39 deletions

View file

@ -85,6 +85,332 @@
<tangent type="int">6</tangent> <tangent type="int">6</tangent>
<binormal type="int">7</binormal> <binormal type="int">7</binormal>
</generate> </generate>
<technique n="8">
<predicate>
<and>
<property>/sim/rendering/shaders/generic</property>
<property>/sim/rendering/rembrandt/enabled</property>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
<extension-supported>GL_EXT_gpu_shader4</extension-supported>
</and>
</predicate>
<pass>
<texture-unit>
<unit>0</unit>
<image>
<use>texture[0]/image</use>
</image>
<filter>
<use>texture[0]/filter</use>
</filter>
<wrap-s>
<use>texture[0]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[0]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[1]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image>
<use>texture[8]/image</use>
</image>
<filter>
<use>texture[8]/filter</use>
</filter>
<wrap-s>
<use>texture[8]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[8]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<type>noise</type>
</texture-unit>
<texture-unit>
<unit>4</unit>
<image>
<use>texture[4]/image</use>
</image>
<filter>
<use>texture[4]/filter</use>
</filter>
<wrap-s>
<use>texture[4]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[4]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[4]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>5</unit>
<type>
<use>texture[5]/type</use>
</type>
<!-- use this form for a cube cross -->
<!--<image>
<use>texture[5]/image</use>
</image>-->
<!-- use this form for a 6 image cube map -->
<images>
<use>texture[5]/images</use>
</images>
</texture-unit>
<texture-unit>
<unit>6</unit>
<type>
<use>texture[6]/type</use>
</type>
<image>
<use>texture[6]/image</use>
</image>
<filter>
<use>texture[6]/filter</use>
</filter>
<wrap-s>
<use>texture[6]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[6]/wrap-t</use>
</wrap-t>
</texture-unit>
<texture-unit>
<unit>7</unit>
<type>
<use>texture[7]/type</use>
</type>
<image>
<use>texture[7]/image</use>
</image>
<filter>
<use>texture[7]/filter</use>
</filter>
<wrap-s>
<use>texture[7]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[7]/wrap-t</use>
</wrap-t>
</texture-unit>
<vertex-program-two-side>
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<lighting>false</lighting>
<material>
<ambient>
<use>material/ambient</use>
</ambient>
<diffuse>
<use>material/diffuse</use>
</diffuse>
<specular>
<use>material/specular</use>
</specular>
<emissive>
<use>material/emissive</use>
</emissive>
<shininess>
<use>material/shininess</use>
</shininess>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/reflect-bump-spec.vert</vertex-shader>
<fragment-shader>Shaders/runway-gbuffer.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-encode.frag</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>Map</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>Noise</name>
<type>sampler-3d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>Environment</name>
<type>sampler-cube</type>
<value type="int">5</value>
</uniform>
<uniform>
<name>Rainbow</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>Fresnel</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<!-- set the amount of fringing colour 0.0 - 1.0 -->
<uniform>
<name>rainbowiness</name>
<type>float</type>
<value>
<use>rainbowiness</use>
</value>
</uniform>
<!-- set the amount of fresnel effect colour 0.0 - 1.0 -->
<uniform>
<name>fresneliness</name>
<type>float</type>
<value>
<use>fresneliness</use>
</value>
</uniform>
<!-- set the amount of noisiness 0.0 - 1.0 -->
<uniform>
<name>noisiness</name>
<type>float</type>
<value>
<use>noisiness</use>
</value>
</uniform>
<!-- The reflection is set proportional to the shininess of the material.
The amount of reflection may be adjusted by the use of this correction
-1.0 (fully transparent)- 1.0 (fully opaque) -->
<uniform>
<name>spec_adjust</name>
<type>float</type>
<value>
<use>wetness</use>
</value>
</uniform>
<!-- set the amount of ambient light correction 0.0 - 1.0 -->
<uniform>
<name>ambient_correction</name>
<type>float</type>
<value>
<use>ambient_correction</use>
</value>
</uniform>
<!-- use a reflection map-->
<uniform>
<name>reflect_map</name>
<type>float</type>
<value>
<use>reflect_map</use>
</value>
</uniform>
<!-- normalmap is .dds-->
<uniform>
<name>normalmap_dds</name>
<type>float</type>
<value>
<use>normalmap_dds</use>
</value>
</uniform>
<uniform>
<name>visibility</name>
<type>float</type>
<value>
<use>visibility</use>
</value>
</uniform>
<uniform>
<name>avisibility</name>
<type>float</type>
<value>
<use>avisibility</use>
</value>
</uniform>
<uniform>
<name>hazeLayerAltitude</name>
<type>float</type>
<value>
<use>lthickness</use>
</value>
</uniform>
<uniform>
<name>scattering</name>
<type>float</type>
<value>
<use>scattering</use>
</value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value>
<use>terminator</use>
</value>
</uniform>
<uniform>
<name>fogType</name>
<type>int</type>
<value>
<use>fogtype</use>
</value>
</uniform>
</pass>
</technique>
<technique n="9"> <technique n="9">
<predicate> <predicate>
<and> <and>
@ -232,7 +558,7 @@
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> --> <!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader n="1">Shaders/reflect-bump-spec.vert</vertex-shader> <vertex-shader n="1">Shaders/reflect-bump-spec.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader> <fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/runway-reflect-bump-spec.frag</fragment-shader> <fragment-shader n="1">Shaders/runway.frag</fragment-shader>
<attribute> <attribute>
<name>tangent</name> <name>tangent</name>
<index>6</index> <index>6</index>

107
Shaders/runway-gbuffer.frag Normal file
View file

@ -0,0 +1,107 @@
// -*- mode: C; -*-
// Licence: GPL v2
// © Emilian Huminiuc and Vivian Meazza 2011
#version 120
varying vec3 rawpos;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying vec4 Diffuse;
varying float alpha;
//varying float fogCoord;
uniform samplerCube Environment;
uniform sampler2D Rainbow;
uniform sampler2D BaseTex;
uniform sampler2D Fresnel;
uniform sampler2D Map;
uniform sampler2D NormalTex;
uniform sampler3D Noise;
uniform float spec_adjust;
uniform float rainbowiness;
uniform float fresneliness;
uniform float noisiness;
uniform float ambient_correction;
uniform float normalmap_dds;
void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
void main (void)
{
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * 8.0);
vec4 map = texture2D(Map, gl_TexCoord[0].st * 8.0);
vec4 specNoise = texture3D(Noise, rawpos.xyz * 0.0045);
vec4 noisevec = texture3D(Noise, rawpos.xyz);
vec3 ambient = vec3(0.85,0.85,0.9);//placeholder for sun ambient
vec3 N;
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
vec3( 0.3, 0.59, 0.11 ) );
N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (normalmap_dds > 0)
N = -N;
// calculate the specular light
float refl_correction = spec_adjust * 1.9 - 1.0;
float shininess = max (0.35, refl_correction) * nmap.a;
float specular = dot(vec3(0.5*shininess), vec3( 0.3, 0.59, 0.11 ));
vec4 color = vec4(1.0);
color.a = texel.a * alpha;
color = clamp(color, 0.0, 1.0);
vec3 viewVec = normalize(vViewVec);
// Map a rainbowish color
float v = dot(viewVec, normalize(VNormal));
vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0));
// Map a fresnel effect
vec4 fresnel = texture2D(Fresnel, vec2(v, 0.0));
// map the refection of the environment
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
// set the user shininess offset
float transparency_offset = clamp(refl_correction, -1.0, 1.0);
float reflFactor = 0.0;
float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0;
MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor);
reflFactor = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * (1.0- N.z) + transparency_offset ;
reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor);
// set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(ambient_correction, -1.0, 1.0);
vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6) * ambient_offset;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
// add fringing fresnel and rainbow effects and modulate by reflection
vec4 reflcolor = mix(reflection, rainbow, rainbowiness * v);
vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
vec4 mixedcolor = mix(texel, raincolor, reflFactor);
// the final reflection
vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction, color.a);
encode_gbuffer(N, fragColor.rgb, 1, specular, shininess, emission, gl_FragCoord.z);
}

View file

@ -45,53 +45,46 @@ void main (void)
//vec3 halfV; //vec3 halfV;
//float NdotL, NdotHV; //float NdotL, NdotHV;
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * 8.0); vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * 8.0);
vec4 map = texture2D(Map, gl_TexCoord[0].st * 8.0); vec4 map = texture2D(Map, gl_TexCoord[0].st * 8.0);
vec4 specNoise = texture3D(Noise, rawpos.xyz * 0.0045); vec4 specNoise = texture3D(Noise, rawpos.xyz * 0.0045);
vec4 noisevec = texture3D(Noise, rawpos.xyz); vec4 noisevec = texture3D(Noise, rawpos.xyz);
vec3 lightDir = gl_LightSource[0].position.xyz; vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz; vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec3 N; vec3 N;
float pf; float pf;
// vec4 color = gl_Color; N = nmap.rgb * 2.0 - 1.0;
//vec4 specular = vec4(0.0); N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (normalmap_dds > 0)
N = nmap.rgb * 2.0 - 1.0; N = -N;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (normalmap_dds > 0)
N = -N;
// calculate the specular light // calculate the specular light
float refl_correction = spec_adjust * 1.9 - 1.0; float refl_correction = spec_adjust * 1.9 - 1.0;
float shininess = max (0.35, refl_correction); float shininess = max (0.35, refl_correction);
float nDotVP = max(0.0, dot(N, normalize(gl_LightSource[0].position.xyz))); float nDotVP = max(0.0, dot(N, normalize(gl_LightSource[0].position.xyz)));
float nDotHV = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz))); float nDotHV = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz)));
if (nDotVP == 0.0) if (nDotVP == 0.0)
pf = 0.0; pf = 0.0;
else else
pf = pow(nDotHV, /*gl_FrontMaterial.*/shininess); pf = pow(nDotHV, /*gl_FrontMaterial.*/shininess);
vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
vec4 Specular = /*gl_FrontMaterial.specular*/ vec4(vec3(0.5*shininess), 1.0)* gl_LightSource[0].specular * pf; vec4 Specular = vec4(vec3(0.5*shininess), 1.0)* gl_LightSource[0].specular * pf;
vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse; vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse;
color += Specular * /*gl_FrontMaterial.specular*/ vec4(vec3(0.5*shininess), 1.0) * nmap.a; color += Specular * vec4(vec3(0.5*shininess), 1.0) * nmap.a;
//color.a = alpha;
//vec4 texelcolor = color * texel + specular;
color.a = texel.a * alpha; color.a = texel.a * alpha;
color = clamp(color, 0.0, 1.0); color = clamp(color, 0.0, 1.0);
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(vViewVec);
// Map a rainbowish color // Map a rainbowish color
float v = dot(viewVec, normalize(VNormal)); float v = dot(viewVec, normalize(VNormal));
vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0)); vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0));
// Map a fresnel effect // Map a fresnel effect
@ -105,14 +98,12 @@ void main (void)
float transparency_offset = clamp(refl_correction, -1.0, 1.0); float transparency_offset = clamp(refl_correction, -1.0, 1.0);
float reflFactor = 0.0; float reflFactor = 0.0;
//vec4 specNoise1 = texture3D(Noise, rawpos.xyz*0.001); float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0;
float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0; MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor);
//MixFactor *= specNoise1.r;
MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor);
reflFactor = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * (1.0- N.z) + transparency_offset ; reflFactor = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * (1.0- N.z) + transparency_offset ;
//reflFactor = clamp(reflFactor, 0.0, 0.75);
reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor); reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor);
// set ambient adjustment to remove bluiness with user input // set ambient adjustment to remove bluiness with user input
@ -122,17 +113,17 @@ void main (void)
// add fringing fresnel and rainbow effects and modulate by reflection // add fringing fresnel and rainbow effects and modulate by reflection
vec4 reflcolor = mix(reflection, rainbow, rainbowiness * v); vec4 reflcolor = mix(reflection, rainbow, rainbowiness * v);
reflcolor += Specular * nmap.a; reflcolor += Specular * nmap.a;
vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v); vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness); vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0); vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
raincolor += Specular * nmap.a; raincolor += Specular * nmap.a;
vec4 mixedcolor = mix(texel, raincolor, reflFactor); vec4 mixedcolor = mix(texel, raincolor, reflFactor);
// the final reflection // the final reflection
vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction.rgb, color.a); vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a; fragColor += Specular * nmap.a;
fragColor.rgb = fog_Func(fragColor.rgb, fogType); fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor; gl_FragColor = fragColor;