1
0
Fork 0

Rewrite ubershader reflection. Objects using the dynamic option will now display the reflection properly when affected by a spin/rotate animation. Improved appearance of reflection + normalmap. Normalmap support added to random-buildings when ubershader active.

Also fixes some bugs exposed on AMD GPUs
This commit is contained in:
Emilian Huminiuc 2015-03-29 13:47:58 +02:00 committed by Christian Schmitt
parent 59e01f4edc
commit 3dc0e641c1
10 changed files with 555 additions and 471 deletions

71
Effects/building.eff Normal file → Executable file
View file

@ -12,9 +12,17 @@
<internal-format>normalized</internal-format> <internal-format>normalized</internal-format>
</texture> </texture>
<!-- Normal Map --> <!-- Normal Map -->
<normalmap-enabled type="int"> 0 </normalmap-enabled> <normalmap-enabled type="int"> 1 </normalmap-enabled>
<normalmap-dds type="int"> 0 </normalmap-dds> <normalmap-dds type="int"> 0 </normalmap-dds>
<normalmap-tiling type="float"> 1.0 </normalmap-tiling> <normalmap-tiling type="float"> 1.0 </normalmap-tiling>
<texture n="2">
<image>Textures/buildings-normalmap_orig.png</image>
<type>2d</type>
<filter>linear-mipmap-linear</filter>
<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<!-- Light Map --> <!-- Light Map -->
<texture n="3"> <texture n="3">
<image>Textures/buildings-lightmap.png</image> <image>Textures/buildings-lightmap.png</image>
@ -39,7 +47,6 @@
<!-- Reflection --> <!-- Reflection -->
<reflection-enabled type="int"> 1 </reflection-enabled> <reflection-enabled type="int"> 1 </reflection-enabled>
<reflect-map-enabled type="int"> 1 </reflect-map-enabled> <reflect-map-enabled type="int"> 1 </reflect-map-enabled>
<!-- <reflect-map-enabled type="int"> 0 </reflect-map-enabled> -->
<reflection-correction type="float"> -0.15 </reflection-correction> <reflection-correction type="float"> -0.15 </reflection-correction>
<reflection-dynamic type="int"> 0 </reflection-dynamic> <reflection-dynamic type="int"> 0 </reflection-dynamic>
<reflection-fresnel type="float"> 0.0 </reflection-fresnel> <reflection-fresnel type="float"> 0.0 </reflection-fresnel>
@ -362,6 +369,17 @@
<technique n="7"> <technique n="7">
<pass> <pass>
<material>
<active>true</active>
<color-mode-uniform>1</color-mode-uniform>
<ambient type="vec4d">0.6 0.6 0.6 1.0</ambient>
<diffuse type="vec4d">1.0 1.0 1.0 1.0</diffuse>
<specular type="vec4d">0.0 0.0 0.0 1.0</specular>
<emissive type="vec4d">0.02 0.02 0.02 1.0</emissive>
<shininess>0.1</shininess>
<color-mode>ambient-and-diffuse</color-mode>
<color-mode-uniform>ambient-and-diffuse</color-mode-uniform>
</material>
<texture-unit n="4"> <texture-unit n="4">
<unit>4</unit> <unit>4</unit>
<image> <image>
@ -389,34 +407,19 @@
</pass> </pass>
</technique> </technique>
<!-- <technique n="8">
<pass>
<texture-unit n="4">
<unit>4</unit>
<image>
<use>texture[3]/image</use>
</image>
<filter>
<use>texture[3]/filter</use>
</filter>
<wrap-s>
<use>texture[3]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[3]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[3]/internal-format</use>
</internal-format>
</texture-unit>
<program n="0">
<vertex-shader n="1">Shaders/building-ubershader.vert</vertex-shader>
</program>
</pass>
</technique>-->
<technique n="9"> <technique n="9">
<pass> <pass>
<material>
<active>true</active>
<color-mode-uniform>1</color-mode-uniform>
<ambient type="vec4d">0.6 0.6 0.6 1.0</ambient>
<diffuse type="vec4d">1.0 1.0 1.0 1.0</diffuse>
<specular type="vec4d">0.0 0.0 0.0 1.0</specular>
<emissive type="vec4d">0.02 0.02 0.02 1.0</emissive>
<shininess>0.1</shininess>
<color-mode>ambient-and-diffuse</color-mode>
<color-mode-uniform>ambient-and-diffuse</color-mode-uniform>
</material>
<texture-unit n="4"> <texture-unit n="4">
<unit>4</unit> <unit>4</unit>
<image> <image>
@ -439,7 +442,7 @@
</internal-format> </internal-format>
</texture-unit> </texture-unit>
<program n="0"> <program n="0">
<vertex-shader n="1">Shaders/building-ubershader.vert</vertex-shader> <vertex-shader n="0">Shaders/building-ubershader.vert</vertex-shader>
</program> </program>
</pass> </pass>
</technique> </technique>
@ -455,7 +458,7 @@
<technique n="11"> <technique n="11">
<pass> <pass>
<program n="0"> <program n="0">
<vertex-shader n="1">Shaders/building-default.vert</vertex-shader> <vertex-shader n="0">Shaders/building-default.vert</vertex-shader>
</program> </program>
</pass> </pass>
</technique> </technique>
@ -539,15 +542,13 @@
<use>vertex-program-two-side</use> <use>vertex-program-two-side</use>
</vertex-program-two-side> </vertex-program-two-side>
<program> <program>
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> --> <vertex-shader n="0">Shaders/building-default.vert</vertex-shader>
<!--fog include-->
<vertex-shader n="1">Shaders/building-default.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader> <fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<!--fog include--> <!--fog include-->
<fragment-shader n="1">Shaders/default.frag</fragment-shader> <fragment-shader n="1">Shaders/default.frag</fragment-shader>
</program> </program>
<!-- BEGIN fog include --> <!-- BEGIN fog include -->
<uniform> <!--<uniform>
<name>visibility</name> <name>visibility</name>
<type>float</type> <type>float</type>
<value> <value>
@ -581,7 +582,7 @@
<value> <value>
<use>terminator</use> <use>terminator</use>
</value> </value>
</uniform> </uniform>-->
<uniform> <uniform>
<name>fogType</name> <name>fogType</name>
<type>int</type> <type>int</type>

38
Effects/model-combined-deferred.eff Normal file → Executable file
View file

@ -244,9 +244,9 @@ the objects that use it, and replaces it with the default shader.
<program n="0"> <program n="0">
<vertex-shader n="0">Shaders/ubershader.vert</vertex-shader> <vertex-shader n="0">Shaders/ubershader.vert</vertex-shader>
<fragment-shader>Shaders/ubershader-gbuffer.frag</fragment-shader> <fragment-shader n="0">Shaders/ubershader-gbuffer.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader> <fragment-shader n="1">Shaders/gbuffer-functions.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-encode.frag</fragment-shader> <fragment-shader n="2">Shaders/gbuffer-encode.frag</fragment-shader>
</program> </program>
<uniform> <uniform>
@ -285,18 +285,6 @@ the objects that use it, and replaces it with the default shader.
<value type="int">5</value> <value type="int">5</value>
</uniform> </uniform>
<!-- <uniform>
<name>ReflFresnelTex</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>ReflRainbowTex</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>-->
<uniform> <uniform>
<name>ReflGradientsTex</name> <name>ReflGradientsTex</name>
<type>sampler-2d</type> <type>sampler-2d</type>
@ -548,31 +536,23 @@ the objects that use it, and replaces it with the default shader.
</uniform> </uniform>
<uniform> <uniform>
<name>hdg</name> <name>lonDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-hdg</use> <use>pos-lon</use>
</value> </value>
</uniform> </uniform>
<uniform> <uniform>
<name>pitch</name> <name>latDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-pitch</use> <use>pos-lat</use>
</value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
</value> </value>
</uniform> </uniform>
<!-- BEGIN fog include --> <!-- BEGIN fog include -->
<uniform> <!--<uniform>
<name>visibility</name> <name>visibility</name>
<type>float</type> <type>float</type>
<value> <value>
@ -613,7 +593,7 @@ the objects that use it, and replaces it with the default shader.
<value> <value>
<use>fogtype</use> <use>fogtype</use>
</value> </value>
</uniform> </uniform>-->
<!-- END fog include --> <!-- END fog include -->
<uniform> <uniform>
<name>rembrandt_enabled</name> <name>rembrandt_enabled</name>

35
Effects/model-combined-transparent.eff Normal file → Executable file
View file

@ -329,18 +329,9 @@ and fallback to plain transparency when the model shader is disabled.
</vertex-program-two-side> </vertex-program-two-side>
<program> <program>
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> --> <vertex-shader n="0">Shaders/ubershader.vert</vertex-shader>
<vertex-shader n="1">Shaders/ubershader.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/ubershader.frag</fragment-shader> <fragment-shader n="1">Shaders/ubershader.frag</fragment-shader>
<!--<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>-->
</program> </program>
<uniform> <uniform>
@ -628,33 +619,25 @@ and fallback to plain transparency when the model shader is disabled.
<use>ambient-correction</use> <use>ambient-correction</use>
</value> </value>
</uniform> </uniform>
<uniform> <uniform>
<name>hdg</name> <name>lonDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-hdg</use> <use>pos-lon</use>
</value> </value>
</uniform> </uniform>
<uniform> <uniform>
<name>pitch</name> <name>latDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-pitch</use> <use>pos-lat</use>
</value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
</value> </value>
</uniform> </uniform>
<!-- BEGIN fog include --> <!-- BEGIN fog include -->
<uniform> <!--<uniform>
<name>visibility</name> <name>visibility</name>
<type>float</type> <type>float</type>
<value> <value>
@ -688,7 +671,7 @@ and fallback to plain transparency when the model shader is disabled.
<value> <value>
<use>terminator</use> <use>terminator</use>
</value> </value>
</uniform> </uniform>-->
<uniform> <uniform>
<name>fogType</name> <name>fogType</name>
<type>int</type> <type>int</type>

65
Effects/model-combined.eff Normal file → Executable file
View file

@ -128,6 +128,12 @@ please see Docs/README.model-combined.eff for documentation
<model-roll> <model-roll>
<use>orientation/model/roll-deg</use> <use>orientation/model/roll-deg</use>
</model-roll> </model-roll>
<pos-lon>
<use>position/longitude-deg</use>
</pos-lon>
<pos-lat>
<use>position/latitude-deg</use>
</pos-lat>
<!-- fog include --> <!-- fog include -->
<visibility><use>/environment/ground-visibility-m</use></visibility> <visibility><use>/environment/ground-visibility-m</use></visibility>
<avisibility><use>/environment/visibility-m</use></avisibility> <avisibility><use>/environment/visibility-m</use></avisibility>
@ -1137,6 +1143,21 @@ please see Docs/README.model-combined.eff for documentation
<use>rembrandt</use> <use>rembrandt</use>
</value> </value>
</uniform> </uniform>
<uniform>
<name>lonDeg</name>
<type>float</type>
<value>
<use>pos-lon</use>
</value>
</uniform>
<uniform>
<name>latDeg</name>
<type>float</type>
<value>
<use>pos-lat</use>
</value>
</uniform>
</pass> </pass>
</technique> </technique>
@ -1357,18 +1378,9 @@ please see Docs/README.model-combined.eff for documentation
</vertex-program-two-side> </vertex-program-two-side>
<program n="0"> <program n="0">
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> --> <vertex-shader n="0">Shaders/ubershader.vert</vertex-shader>
<vertex-shader n="1">Shaders/ubershader.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/ubershader.frag</fragment-shader> <fragment-shader n="1">Shaders/ubershader.frag</fragment-shader>
<!--<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>-->
</program> </program>
<uniform> <uniform>
@ -1657,32 +1669,25 @@ please see Docs/README.model-combined.eff for documentation
</value> </value>
</uniform> </uniform>
<uniform> <uniform>
<name>hdg</name> <name>lonDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-hdg</use> <use>pos-lon</use>
</value> </value>
</uniform> </uniform>
<uniform> <uniform>
<name>pitch</name> <name>latDeg</name>
<type>float</type> <type>float</type>
<value> <value>
<use>model-pitch</use> <use>pos-lat</use>
</value> </value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
</value>
</uniform> </uniform>
<!-- BEGIN fog include --> <!-- BEGIN fog include -->
<uniform> <!--<uniform>
<name>visibility</name> <name>visibility</name>
<type>float</type> <type>float</type>
<value> <value>
@ -1716,7 +1721,7 @@ please see Docs/README.model-combined.eff for documentation
<value> <value>
<use>terminator</use> <use>terminator</use>
</value> </value>
</uniform> </uniform>-->
<uniform> <uniform>
<name>fogType</name> <name>fogType</name>
<type>int</type> <type>int</type>

124
Shaders/building-ubershader.vert Normal file → Executable file
View file

@ -1,50 +1,20 @@
// -*- mode: C; -*- // -*- mode: C; -*-
// RANDOM BUILDINGS for the UBERSHADER vertex shader
// Licence: GPL v2 // Licence: GPL v2
// © Emilian Huminiuc and Vivian Meazza 2011 // © Emilian Huminiuc and Vivian Meazza 2011
#version 120 #version 120
varying vec3 rawpos; varying vec4 diffuseColor;
varying vec3 VNormal; varying vec3 VBinormal;
varying vec3 VTangent; varying vec3 VNormal;
varying vec3 VBinormal; varying vec3 VTangent;
varying vec3 vViewVec; varying vec3 rawpos;
varying vec3 vertVec; varying vec3 eyeVec;
varying vec3 reflVec;
varying float alpha;
attribute vec3 tangent;
attribute vec3 binormal;
uniform float pitch;
uniform float roll;
uniform float hdg;
uniform int refl_dynamic; uniform int refl_dynamic;
uniform int nmap_enabled; uniform int nmap_enabled;
uniform int shader_qual; uniform int shader_qual;
uniform int rembrandt_enabled; uniform int rembrandt_enabled;
uniform int color_is_position;
//////Fog Include///////////
// uniform int fogType;
// void fog_Func(int type);
////////////////////////////
void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat)
{
rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0,
0.0 , cosRx , -sinRx * cosRx, 0.0,
-sinRy, sinRx * cosRy, cosRx * cosRy , 0.0,
0.0 , 0.0 , 0.0 , 1.0 );
}
void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
{
rotmat = mat4( cosRz, -sinRz, 0.0, 0.0,
sinRz, cosRz, 0.0, 0.0,
0.0 , 0.0 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 );
}
void main(void) void main(void)
{ {
@ -56,75 +26,41 @@ void main(void)
rawpos.xy = vec2(dot(rawpos.xy, vec2(cr, sr)), dot(rawpos.xy, vec2(-sr, cr))); rawpos.xy = vec2(dot(rawpos.xy, vec2(cr, sr)), dot(rawpos.xy, vec2(-sr, cr)));
rawpos = rawpos + gl_Color.xyz; rawpos = rawpos + gl_Color.xyz;
vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos.x, rawpos.y, rawpos.z, 1.0); vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos.xyz, 1.0);
//fog_Func(fogType);
eyeVec = ecPosition.xyz;
// Rotate the normal. // Rotate the normal.
vec3 normal = gl_Normal; vec3 normal = gl_Normal;
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr))); normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
//normal = gl_NormalMatrix * normal;
VNormal = normalize(gl_NormalMatrix * normal); VNormal = normalize(gl_NormalMatrix * normal);
vec3 n = normalize(normal); vec3 n = normalize(normal);
vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0)); vec3 c1 = cross(n, vec3(0.0,0.0,1.0));
vec3 tempBinormal = cross(n, tempTangent); vec3 c2 = cross(n, vec3(0.0,1.0,0.0));
if (nmap_enabled > 0){ VTangent = c1;
tempTangent = tangent; if(length(c2)>length(c1)){
tempBinormal = binormal; VTangent = c2;
} }
VTangent = normalize(gl_NormalMatrix * tempTangent); VBinormal = cross(n, VTangent);
VBinormal = normalize(gl_NormalMatrix * tempBinormal);
vec3 t = tempTangent;
vec3 b = tempBinormal;
// Super hack: if diffuse material alpha is less than 1, assume a VTangent = normalize(gl_NormalMatrix * -VTangent);
// transparency animation is at work VBinormal = normalize(gl_NormalMatrix * VBinormal);
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a;
else
alpha = 1.0;
// Vertex in eye coordinates
vertVec = ecPosition.xyz;
vViewVec.x = dot(t, vertVec);
vViewVec.y = dot(b, vertVec);
vViewVec.z = dot(n, vertVec);
// calculate the reflection vector
vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0);
vec3 reflVec_stat = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz;
if (refl_dynamic > 0){
//prepare rotation matrix
mat4 RotMatPR;
mat4 RotMatH;
float _roll = roll;
if (_roll>90.0 || _roll < -90.0)
{
_roll = -_roll;
}
float cosRx = cos(radians(_roll));
float sinRx = sin(radians(_roll));
float cosRy = cos(radians(-pitch));
float sinRy = sin(radians(-pitch));
float cosRz = cos(radians(hdg));
float sinRz = sin(radians(hdg));
rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR);
rotationMatrixH(sinRz, cosRz, RotMatH);
vec3 reflVec_dyn = (RotMatH * (RotMatPR * normalize(gl_ModelViewMatrixInverse * reflect_eye))).xyz;
reflVec = reflVec_dyn; // Force no alpha on random buildings
} else { diffuseColor = vec4(gl_FrontMaterial.diffuse.rgb,1.0);
reflVec = reflVec_stat;
}
if(rembrandt_enabled < 1){ if(rembrandt_enabled < 1){
gl_FrontColor = gl_FrontMaterial.emission + vec4(1.0,1.0,1.0,1.0) gl_FrontColor = gl_FrontMaterial.emission + vec4(1.0)
* (gl_LightModel.ambient + gl_LightSource[0].ambient); * (gl_LightModel.ambient + gl_LightSource[0].ambient);
} else { } else {
gl_FrontColor = vec4(1.0,1.0,1.0,1.0); gl_FrontColor = vec4(1.0);
} }
gl_Position = gl_ModelViewProjectionMatrix * vec4(rawpos,1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(rawpos,1.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_ClipVertex = ecPosition;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
} }

196
Shaders/model-ALS-ultra.frag Normal file → Executable file
View file

@ -7,15 +7,13 @@
// by Thorsten Renk, 2013 // by Thorsten Renk, 2013
#version 120 #version 120
varying vec4 diffuseColor;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 rawpos; varying vec3 rawpos;
varying vec3 reflVec; varying vec3 eyeVec;
varying vec3 vViewVec; varying vec3 eyeDir;
varying vec3 vertVec;
varying float alpha;
uniform sampler2D BaseTex; uniform sampler2D BaseTex;
uniform sampler2D LightMapTex; uniform sampler2D LightMapTex;
@ -33,6 +31,7 @@ uniform int lightmap_multi;
uniform int nmap_dds; uniform int nmap_dds;
uniform int nmap_enabled; uniform int nmap_enabled;
uniform int refl_enabled; uniform int refl_enabled;
uniform int refl_dynamic;
uniform int refl_map; uniform int refl_map;
uniform int grain_texture_enabled; uniform int grain_texture_enabled;
uniform int rain_enabled; uniform int rain_enabled;
@ -90,6 +89,47 @@ uniform vec3 dirt_r_color;
uniform vec3 dirt_g_color; uniform vec3 dirt_g_color;
uniform vec3 dirt_b_color; uniform vec3 dirt_b_color;
///reflection orientation
uniform mat4 osg_ViewMatrixInverse;
uniform float latDeg;
uniform float lonDeg;
//////rotation matrices/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
mat3 rotX(in float angle)
{
mat3 rotmat = mat3(
1.0, 0.0, 0.0,
0.0, cos(angle), -sin(angle),
0.0, sin(angle), cos(angle)
);
return rotmat;
}
mat3 rotY(in float angle)
{
mat3 rotmat = mat3(
cos(angle), 0.0, sin(angle),
0.0, 1.0, 0.0,
-sin(angle), 0.0, cos(angle)
);
return rotmat;
}
mat3 rotZ(in float angle)
{
mat3 rotmat = mat3(
cos(angle), -sin(angle), 0.0,
sin(angle), cos(angle), 0.0,
0.0, 0.0, 1.0
);
return rotmat;
}
////////////////////////////////////////////////////////////////////////////////
float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize, in float dot_density); float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize, in float dot_density);
float shadow_func (in float x, in float y, in float noise, in float dist); float shadow_func (in float x, in float y, in float noise, in float dist);
float fog_func (in float targ, in float altitude); float fog_func (in float targ, in float altitude);
@ -143,13 +183,13 @@ void main (void)
//vec4 worldPos3D = (osg_ViewMatrixInverse * vec4 (0.0,0.0,0.0, 1.0)); //vec4 worldPos3D = (osg_ViewMatrixInverse * vec4 (0.0,0.0,0.0, 1.0));
//worldPos3D.a = 0.0; //worldPos3D.a = 0.0;
//vec3 up = (osg_ViewMatrix * worldPos3D).xyz; //vec3 up = (osg_ViewMatrix * worldPos3D).xyz;
float dist = length(vertVec); float dist = length(eyeVec);
float vertex_alt = max(100.0,dot(up, vertVec) + alt); float vertex_alt = max(100.0,dot(up, eyeVec) + alt);
float vertex_scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); float vertex_scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
vec3 lightHorizon = gl_LightSource[0].position.xyz - up * dot(up,gl_LightSource[0].position.xyz); vec3 lightHorizon = gl_LightSource[0].position.xyz - up * dot(up,gl_LightSource[0].position.xyz);
float yprime = -dot(vertVec, lightHorizon); float yprime = -dot(eyeVec, lightHorizon);
float yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt); float yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
float lightArg = (terminator-yprime_alt)/100000.0; float lightArg = (terminator-yprime_alt)/100000.0;
@ -157,7 +197,7 @@ void main (void)
float mie_angle; float mie_angle;
if (lightArg < 10.0) if (lightArg < 10.0)
{mie_angle = (0.5 * dot(normalize(vertVec), normalize(gl_LightSource[0].position.xyz)) ) + 0.5;} {mie_angle = (0.5 * dot(normalize(eyeVec), normalize(gl_LightSource[0].position.xyz)) ) + 0.5;}
else else
{mie_angle = 1.0;} {mie_angle = 1.0;}
@ -180,7 +220,7 @@ void main (void)
float fog_lightArg = (terminator-fog_yprime_alt)/100000.0; float fog_lightArg = (terminator-fog_yprime_alt)/100000.0;
float fog_earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, fog_yprime_alt) + 0.1; float fog_earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, fog_yprime_alt) + 0.1;
float ct = dot(normalize(up), normalize(vertVec)); float ct = dot(normalize(up), normalize(eyeVec));
/// END geometry for light /// END geometry for light
@ -237,21 +277,57 @@ void main (void)
} else { } else {
N = normalize(VNormal); N = normalize(VNormal);
} }
///END bump ///END bump ////////////////////////////////////////////////////////////////////
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal)); vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75)); vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25)); vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25));
float nDotVP = max(0.0, dot(N, normalize(gl_LightSource[0].position.xyz))); mat4 reflMatrix = gl_ModelViewMatrixInverse;
float nDotHV = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz))); vec3 wRefVec = reflect(viewVec,N);
//glare on the backside of tranparent objects
if ((gl_FrontMaterial.diffuse.a < 1.0 || texel.a < 1.0) ////dynamic reflection /////////////////////////////
&& dot(N, normalize(gl_LightSource[0].position.xyz)) < 0.0) { if (refl_dynamic > 0){
nDotVP = max(0.0, dot(-N, normalize(gl_LightSource[0].position.xyz))); reflMatrix = osg_ViewMatrixInverse;
nDotHV = max(0.0, dot(-N, normalize(gl_LightSource[0].halfVector.xyz)));
} vec3 wVertVec = normalize(reflMatrix * vec4(viewVec,0.0)).xyz;
vec3 wNormal = normalize(reflMatrix * vec4(N,0.0)).xyz;
float latRad = radians(90. - latDeg);
float lonRad = radians(lonDeg);
mat3 rotCorrX = rotX(-lonRad);
mat3 rotCorrY = rotY(latRad);
mat3 reflCorr = rotCorrX * rotCorrY;
wRefVec = reflect(wVertVec,wNormal);
wRefVec = normalize(reflCorr * wRefVec);
} else { ///static reflection
wRefVec = normalize(reflMatrix * vec4(wRefVec,0.0)).xyz;
}
vec3 reflection = textureCube(Environment, wRefVec).xyz;
vec3 E = eyeDir;
E = normalize(E);
vec3 L = normalize((gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz);
vec3 HV = normalize(L + E);
N = viewN;
float nDotVP = dot(N,L);
float nDotHV = dot(N,HV);
float eDotLV = max(0.0, dot(-E,L));
//glare on the backside of tranparent objects
if ((gl_Color.a < .999 || texel.a < .999) && nDotVP < 0.0) {
nDotVP = dot(-N, L);
nDotHV = dot(-N, HV);
}
nDotVP = max(0.0, nDotVP);
nDotHV = max(0.0, nDotHV);
float nDotVP1 = 0.0; float nDotVP1 = 0.0;
float nDotHV1 = 0.0; float nDotHV1 = 0.0;
@ -259,7 +335,7 @@ void main (void)
// try specular reflection of sky irradiance // try specular reflection of sky irradiance
nDotVP1 = max(0.0, dot(N, up)); nDotVP1 = max(0.0, dot(N, up));
nDotHV1 = max(0.0, dot(N, normalize(normalize(up) + normalize(-vertVec)))); nDotHV1 = max(0.0, dot(N, normalize(normalize(up) + normalize(-eyeVec))));
if (nDotVP == 0.0) if (nDotVP == 0.0)
@ -273,7 +349,7 @@ void main (void)
{pf1 = pow(nDotHV1, 0.5*gl_FrontMaterial.shininess);} {pf1 = pow(nDotHV1, 0.5*gl_FrontMaterial.shininess);}
vec3 relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz; vec3 relPos = (gl_ModelViewMatrixInverse * vec4 (eyeVec,0.0)).xyz;
if (cloud_shadow_flag == 1) if (cloud_shadow_flag == 1)
{ {
light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist); light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist);
@ -298,11 +374,11 @@ void main (void)
vec4 Diffuse = light_diffuse * nDotVP; vec4 Diffuse = light_diffuse * nDotVP;
Diffuse.rgb += secondary_light * light_distance_fading(dist); Diffuse.rgb += secondary_light * light_distance_fading(dist);
vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf + gl_FrontMaterial.specular * light_ambient * pf1; vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf + gl_FrontMaterial.specular * light_ambient * pf1;
Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(vertVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0); Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(eyeVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0);
vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse; vec4 color = gl_Color + Diffuse * diffuseColor;
color = clamp( color, 0.0, 1.0 ); color = clamp( color, 0.0, 1.0 );
color.a = texel.a * diffuseColor.a;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
//BEGIN reflect //BEGIN reflect
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -323,20 +399,23 @@ void main (void)
reflFactor = clamp(reflFactor, 0.0, 1.0); reflFactor = clamp(reflFactor, 0.0, 1.0);
// 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, refl_rainbow * v); vec3 reflcolor = mix(reflection, rainbow.rgb, refl_rainbow * v);
//vec4 reflcolor = reflection; //vec4 reflcolor = reflection;
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v); vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise); vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0); vec3 raincolor = noisecolor.rgb * reflFactor;
raincolor += Specular; raincolor += Specular.rgb;
raincolor *= light_diffuse; raincolor *= light_diffuse.rgb;
mixedcolor = mix(texel, raincolor, reflFactor).rgb; mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else { } else {
mixedcolor = texel.rgb; mixedcolor = texel.rgb;
} }
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
//END reflect //END reflect
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
if (color.a < .999){
color.a += .1 * eDotLV;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//begin DIRT //begin DIRT
@ -344,15 +423,21 @@ void main (void)
if (dirt_enabled >= 1){ if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor); vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb; vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb;
//dirtFactor.r = smoothstep(0.0, 1.0, dirtFactor.r);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r));
if (color.a < .999) {
color.a += dirtFactor.r * eDotLV;
}
if (dirt_multi > 0) { if (dirt_multi > 0) {
//dirtFactor.g = smoothstep(0.0, 1.0, dirtFactor.g); //dirtFactor.g = smoothstep(0.0, 1.0, dirtFactor.g);
//dirtFactor.b = smoothstep(0.0, 1.0, dirtFactor.b); //dirtFactor.b = smoothstep(0.0, 1.0, dirtFactor.b);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g));
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
} if (color.a < 1.0) {
} color.a += dirtFactor.g * eDotLV;
color.a += dirtFactor.b * eDotLV;
}
}
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//END Dirt //END Dirt
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -373,7 +458,7 @@ void main (void)
} }
// secondary reflection of sky irradiance in water film // secondary reflection of sky irradiance in water film
float fresnelW = ((0.8 * wetness) ) * (1.0-smoothstep(0.0,0.4, dot(N,-normalize(vertVec)) * 1.0 - 0.2 * rain_factor * wetness)); float fresnelW = ((0.8 * wetness) ) * (1.0-smoothstep(0.0,0.4, dot(N,-normalize(eyeVec)) * 1.0 - 0.2 * rain_factor * wetness));
float sky_factor = (1.0-ct*ct); float sky_factor = (1.0-ct*ct);
vec3 sky_light = vec3 (1.0,1.0,1.0) * length(light_diffuse.rgb) * (1.0-effective_scattering); vec3 sky_light = vec3 (1.0,1.0,1.0) * length(light_diffuse.rgb) * (1.0-effective_scattering);
Specular.rgb += sky_factor * fresnelW * sky_light; Specular.rgb += sky_factor * fresnelW * sky_light;
@ -387,11 +472,10 @@ void main (void)
float ambient_offset = clamp(amb_correction, -1.0, 1.0); float ambient_offset = clamp(amb_correction, -1.0, 1.0);
//vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient; //vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient;
vec4 ambient = gl_LightModel.ambient + light_ambient; vec4 ambient = gl_LightModel.ambient + light_ambient;
vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0) vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6);
* ambient_offset ; ambient_Correction *= ambient_offset ;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a); vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a; fragColor += Specular * nmap.a;
@ -402,18 +486,18 @@ void main (void)
if ( lightmap_enabled >= 1 ) { if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor = vec3(0.0); vec3 lightmapcolor = vec3(0.0);
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor,
lightmap_b_factor, lightmap_a_factor); lightmap_b_factor, lightmap_a_factor);
lightmapFactor = lightmapFactor * lightmapTexel; lightmapFactor = lightmapFactor * lightmapTexel;
if (lightmap_multi > 0 ){ if (lightmap_multi > 0 ){
lightmapcolor = lightmap_r_color * lightmapFactor.r + lightmapcolor = lightmap_r_color * lightmapFactor.r +
lightmap_g_color * lightmapFactor.g + lightmap_g_color * lightmapFactor.g +
lightmap_b_color * lightmapFactor.b + lightmap_b_color * lightmapFactor.b +
lightmap_a_color * lightmapFactor.a ; lightmap_a_color * lightmapFactor.a ;
} else { } else {
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r; lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
} }
fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * smoothstep(0.0, 1.0, mixedcolor*.5 + lightmapcolor*.5)); fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * smoothstep(0.0, 1.0, mixedcolor*.5 + lightmapcolor*.5));
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// END lightmap // END lightmap
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
@ -537,10 +621,10 @@ void main (void)
///BEGIN Rayleigh fog /// ///BEGIN Rayleigh fog ///
// Rayleigh color shift due to out-scattering // Rayleigh color shift due to out-scattering
float rayleigh_length = 0.5 * avisibility * (2.5 - 1.9 * air_pollution)/alt_factor(eye_alt, eye_alt+relPos.z); float rayleigh_length = 0.5 * avisibility * (2.5 - 1.9 * air_pollution)/alt_factor(eye_alt, eye_alt+relPos.z);
float outscatter = 1.0-exp(-dist/rayleigh_length); float outscatter = 1.0-exp(-dist/rayleigh_length);
fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter); fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter);
vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity; vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z); float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z);
@ -556,6 +640,6 @@ void main (void)
hazeColor.rgb = max(hazeColor.rgb, minLight.rgb); hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(mvisibility), fragColor.rgb,transmission); fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(mvisibility), fragColor.rgb,transmission);
gl_FragColor = fragColor; gl_FragColor = fragColor;
} }

163
Shaders/ubershader-gbuffer.frag Normal file → Executable file
View file

@ -1,18 +1,17 @@
// -*- mode: C; -*- // -*- mode: C; -*-
// UBERSHADER - Rembrandt version - fragment shader
// Licence: GPL v2 // Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy // Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by // with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011 // Emilian Huminiuc and Vivian Meazza 2011
#version 120 #version 120
varying vec3 rawpos; varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 rawpos;
varying vec3 vViewVec; varying vec3 eyeVec;
varying vec3 reflVec;
varying float alpha;
uniform samplerCube Environment; uniform samplerCube Environment;
uniform sampler2D BaseTex; uniform sampler2D BaseTex;
@ -22,14 +21,15 @@ uniform sampler2D ReflMapTex;
uniform sampler2D ReflGradientsTex; uniform sampler2D ReflGradientsTex;
uniform sampler3D ReflNoiseTex; uniform sampler3D ReflNoiseTex;
uniform int nmap_enabled; uniform int dirt_enabled;
uniform int nmap_dds; uniform int dirt_multi;
uniform int refl_enabled; uniform int lightmap_enabled;
uniform int refl_map; uniform int lightmap_multi;
uniform int lightmap_enabled; uniform int nmap_dds;
uniform int lightmap_multi; uniform int nmap_enabled;
uniform int dirt_enabled; uniform int refl_enabled;
uniform int dirt_multi; uniform int refl_dynamic;
uniform int refl_map;
uniform float lightmap_r_factor; uniform float lightmap_r_factor;
uniform float lightmap_g_factor; uniform float lightmap_g_factor;
@ -54,13 +54,47 @@ uniform vec3 dirt_r_color;
uniform vec3 dirt_g_color; uniform vec3 dirt_g_color;
uniform vec3 dirt_b_color; uniform vec3 dirt_b_color;
//uniform vec4 fg_SunAmbientColor;
void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth); void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
///fog include////////////////////// uniform mat4 osg_ViewMatrixInverse;
uniform int fogType; uniform float latDeg;
vec3 fog_Func(vec3 color, int type); uniform float lonDeg;
////////////////////////////////////
//////rotation matrices/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
mat3 rotX(in float angle)
{
mat3 rotmat = mat3(
1.0, 0.0, 0.0,
0.0, cos(angle), -sin(angle),
0.0, sin(angle), cos(angle)
);
return rotmat;
}
mat3 rotY(in float angle)
{
mat3 rotmat = mat3(
cos(angle), 0.0, sin(angle),
0.0, 1.0, 0.0,
-sin(angle), 0.0, cos(angle)
);
return rotmat;
}
mat3 rotZ(in float angle)
{
mat3 rotmat = mat3(
cos(angle), -sin(angle), 0.0,
sin(angle), cos(angle), 0.0,
0.0, 0.0, 1.0
);
return rotmat;
}
////////////////////////////////////////////////////////////////////////////////
void main (void) void main (void)
{ {
@ -75,11 +109,11 @@ void main (void)
//vec3 ambient = fg_SunAmbientColor.rgb; //vec3 ambient = fg_SunAmbientColor.rgb;
vec3 N; vec3 N;
vec3 dotN; vec3 dotN;
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb, float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb,
vec3( 0.3, 0.59, 0.11 ) ); vec3( 0.3, 0.59, 0.11 ) );
float pf; float pf;
///BEGIN bump ///BEGIN bump
if (nmap_enabled > 0){ if (nmap_enabled > 0){
N = nmap.rgb * 2.0 - 1.0; N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal); N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
@ -88,18 +122,44 @@ void main (void)
} else { } else {
N = normalize(VNormal); N = normalize(VNormal);
} }
///END bump ///END bump ////////////////////////////////////////////////////////////////////
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal)); vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75)); vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25)); vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25));
vec4 color = gl_Color;// * gl_FrontMaterial.diffuse;
mat4 reflMatrix = gl_ModelViewMatrixInverse;
vec3 wRefVec = reflect(viewVec,N);
////dynamic reflection /////////////////////////////
if (refl_dynamic > 0 && refl_enabled > 0){
reflMatrix = osg_ViewMatrixInverse;
vec3 wVertVec = (reflMatrix * vec4(eyeVec,0.0)).xyz;
vec3 wNormal = (reflMatrix * vec4(N,0.0)).xyz;
float latRad = radians(90. - latDeg);
float lonRad = radians(lonDeg);
mat3 rotCorrX = rotX(-lonRad);
mat3 rotCorrY = rotY(latRad);
mat3 reflCorr = rotCorrX * rotCorrY;
wRefVec = reflect(wVertVec,wNormal);
wRefVec = normalize(reflCorr * wRefVec);
} else if (refl_enabled > 0) { ///static reflection
wRefVec = normalize(reflMatrix * vec4(wRefVec,0.0)).xyz;
}
vec3 reflection = textureCube(Environment, wRefVec).xyz;
vec4 color = gl_Color + gl_FrontLightModelProduct.sceneColor;
float specular = dot((gl_FrontMaterial.specular * nmap.a).rgb, vec3( 0.3, 0.59, 0.11 )); float specular = dot((gl_FrontMaterial.specular * nmap.a).rgb, vec3( 0.3, 0.59, 0.11 ));
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//BEGIN reflect //BEGIN reflect
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
if (refl_enabled > 0){ if (refl_enabled > 0){
float reflFactor; float reflFactor;
float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset
@ -115,36 +175,33 @@ void main (void)
reflFactor = clamp(reflFactor, 0.0, 1.0); reflFactor = clamp(reflFactor, 0.0, 1.0);
// 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, refl_rainbow * v); vec3 reflcolor = mix(reflection, rainbow.rgb, refl_rainbow * v);
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v); vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise); vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0); vec3 raincolor = noisecolor.rgb * reflFactor;
mixedcolor = mix(texel, raincolor, reflFactor).rgb; mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else { } else {
mixedcolor = texel.rgb; mixedcolor = texel.rgb;
} }
///////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//END reflect //END reflect
///////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//begin DIRT //begin DIRT
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
if (dirt_enabled >= 1){ if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor); vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb; vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb;
//dirtFactor.r = smoothstep(0.0, 1.0, dirtFactor.r);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r));
if (dirt_multi > 0) { if (dirt_multi > 0) {
//dirtFactor.g = smoothstep(0.0, 1.0, dirtFactor.g);
//dirtFactor.b = smoothstep(0.0, 1.0, dirtFactor.b);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g));
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
} }
} }
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//END Dirt //END Dirt
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// set ambient adjustment to remove bluiness with user input // set ambient adjustment to remove bluiness with user input
@ -152,13 +209,15 @@ void main (void)
vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6) * ambient_offset; vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6) * ambient_offset;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
color.a = texel.a * alpha; //specifically disallow alpha
vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction.rgb, color.a); color.a = 1.0; //texel.a * alpha;
//vec4 fragColor = vec4(color.rgb * mixedcolor, color.a); color.rgb *= mixedcolor.rgb;
color.rgb += ambient_Correction.rgb;
vec4 fragColor = color;
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BEGIN lightmap // BEGIN lightmap
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
if ( lightmap_enabled >= 1 ) { if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor; vec3 lightmapcolor;
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, lightmap_b_factor, lightmap_a_factor); vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, lightmap_b_factor, lightmap_a_factor);
@ -179,9 +238,9 @@ void main (void)
fragColor.rgb = max(fragColor.rgb * (1.0 - emission), fragColor.rgb = max(fragColor.rgb * (1.0 - emission),
lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor); lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
} }
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// END lightmap // END lightmap
///////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
encode_gbuffer(N, fragColor.rgb, 255, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z); encode_gbuffer(N, fragColor.rgb, 255, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z);
} }

239
Shaders/ubershader.frag Normal file → Executable file
View file

@ -1,64 +1,106 @@
// -*- mode: C; -*- // -*- mode: C; -*-
// UBERSHADER - default forward rendering - fragment shader
// Licence: GPL v2 // Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy // Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by // with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011 // Emilian Huminiuc and Vivian Meazza 2011
#version 120 #version 120
varying vec4 diffuseColor;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 rawpos; varying vec3 rawpos;
varying vec3 reflVec; varying vec3 eyeVec;
varying vec3 vViewVec; varying vec3 eyeDir;
varying float alpha; uniform sampler2D BaseTex;
uniform sampler2D LightMapTex;
uniform sampler2D NormalTex;
uniform sampler2D ReflGradientsTex;
uniform sampler2D ReflMapTex;
uniform sampler3D ReflNoiseTex;
uniform samplerCube Environment;
uniform sampler2D BaseTex; uniform int dirt_enabled;
uniform sampler2D LightMapTex; uniform int dirt_multi;
uniform sampler2D NormalTex; uniform int lightmap_enabled;
uniform sampler2D ReflGradientsTex; uniform int lightmap_multi;
uniform sampler2D ReflMapTex; uniform int nmap_dds;
uniform sampler3D ReflNoiseTex; uniform int nmap_enabled;
uniform samplerCube Environment; uniform int refl_enabled;
uniform int refl_dynamic;
uniform int refl_map;
uniform int dirt_enabled; uniform float amb_correction;
uniform int dirt_multi; uniform float dirt_b_factor;
uniform int lightmap_enabled; uniform float dirt_g_factor;
uniform int lightmap_multi; uniform float dirt_r_factor;
uniform int nmap_dds; uniform float lightmap_a_factor;
uniform int nmap_enabled; uniform float lightmap_b_factor;
uniform int refl_enabled; uniform float lightmap_g_factor;
uniform int refl_map; uniform float lightmap_r_factor;
uniform float nmap_tile;
uniform float refl_correction;
uniform float refl_fresnel;
uniform float refl_noise;
uniform float refl_rainbow;
uniform float amb_correction; uniform vec3 lightmap_r_color;
uniform float dirt_b_factor; uniform vec3 lightmap_g_color;
uniform float dirt_g_factor; uniform vec3 lightmap_b_color;
uniform float dirt_r_factor; uniform vec3 lightmap_a_color;
uniform float lightmap_a_factor;
uniform float lightmap_b_factor;
uniform float lightmap_g_factor;
uniform float lightmap_r_factor;
uniform float nmap_tile;
uniform float refl_correction;
uniform float refl_fresnel;
uniform float refl_noise;
uniform float refl_rainbow;
uniform vec3 lightmap_r_color; uniform vec3 dirt_r_color;
uniform vec3 lightmap_g_color; uniform vec3 dirt_g_color;
uniform vec3 lightmap_b_color; uniform vec3 dirt_b_color;
uniform vec3 lightmap_a_color;
uniform vec3 dirt_r_color; ///reflection orientation
uniform vec3 dirt_g_color; uniform mat4 osg_ViewMatrixInverse;
uniform vec3 dirt_b_color; uniform float latDeg;
uniform float lonDeg;
///fog include////////////////////// ///fog include//////////////////////
uniform int fogType; uniform int fogType;
vec3 fog_Func(vec3 color, int type); vec3 fog_Func(vec3 color, int type);
//////////////////////////////////// ////////////////////////////////////
//////rotation matrices/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
mat3 rotX(in float angle)
{
mat3 rotmat = mat3(
1.0, 0.0, 0.0,
0.0, cos(angle), -sin(angle),
0.0, sin(angle), cos(angle)
);
return rotmat;
}
mat3 rotY(in float angle)
{
mat3 rotmat = mat3(
cos(angle), 0.0, sin(angle),
0.0, 1.0, 0.0,
-sin(angle), 0.0, cos(angle)
);
return rotmat;
}
mat3 rotZ(in float angle)
{
mat3 rotmat = mat3(
cos(angle), -sin(angle), 0.0,
sin(angle), cos(angle), 0.0,
0.0, 0.0, 1.0
);
return rotmat;
}
////////////////////////////////////////////////////////////////////////////////
void main (void) void main (void)
{ {
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st); vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
@ -71,7 +113,7 @@ void main (void)
vec3 N = vec3(0.0,0.0,1.0); vec3 N = vec3(0.0,0.0,1.0);
float pf = 0.0; float pf = 0.0;
///BEGIN bump ///BEGIN bump //////////////////////////////////////////////////////////////////
if (nmap_enabled > 0 ){ if (nmap_enabled > 0 ){
N = nmap.rgb * 2.0 - 1.0; N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal); N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
@ -80,22 +122,58 @@ void main (void)
} else { } else {
N = normalize(VNormal); N = normalize(VNormal);
} }
///END bump ///END bump ////////////////////////////////////////////////////////////////////
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal)); vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75)); vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25)); vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25));
float nDotVP = max(0.0, dot(N, normalize(gl_LightSource[0].position.xyz))); mat4 reflMatrix = gl_ModelViewMatrixInverse;
float nDotHV = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz))); vec3 wRefVec = reflect(viewVec,N);
//glare on the backside of tranparent objects
if ((gl_FrontMaterial.diffuse.a < 1.0 || texel.a < 1.0) ////dynamic reflection /////////////////////////////
&& dot(N, normalize(gl_LightSource[0].position.xyz)) < 0.0) { if (refl_dynamic > 0){
nDotVP = max(0.0, dot(-N, normalize(gl_LightSource[0].position.xyz))); reflMatrix = osg_ViewMatrixInverse;
nDotHV = max(0.0, dot(-N, normalize(gl_LightSource[0].halfVector.xyz)));
vec3 wVertVec = normalize(reflMatrix * vec4(viewVec,0.0)).xyz;
vec3 wNormal = normalize(reflMatrix * vec4(N,0.0)).xyz;
float latRad = radians(90. - latDeg);
float lonRad = radians(lonDeg);
mat3 rotCorrX = rotX(-lonRad);
mat3 rotCorrY = rotY(latRad);
mat3 reflCorr = rotCorrX * rotCorrY;
wRefVec = reflect(wVertVec,wNormal);
wRefVec = normalize(reflCorr * wRefVec);
} else { ///static reflection
wRefVec = normalize(reflMatrix * vec4(wRefVec,0.0)).xyz;
} }
vec3 reflection = textureCube(Environment, wRefVec).xyz;
vec3 E = eyeDir;
E = normalize(E);
vec3 L = normalize((gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz);
vec3 H = normalize(L + E);
N = viewN;
float nDotVP = dot(N,L);
float nDotHV = dot(N,H);
float eDotLV = max(0.0, dot(-E,L));
//glare on the backside of tranparent objects
if ((gl_Color.a < .999 || texel.a < 1.0) && nDotVP < 0.0) {
nDotVP = dot(-N, L);
nDotHV = dot(-N, H);
}
nDotVP = max(0.0, nDotVP);
nDotHV = max(0.0, nDotHV);
if (nDotVP == 0.0) if (nDotVP == 0.0)
pf = 0.0; pf = 0.0;
else else
@ -104,19 +182,18 @@ void main (void)
vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
vec4 Specular = gl_FrontMaterial.specular * gl_LightSource[0].diffuse * pf; vec4 Specular = gl_FrontMaterial.specular * gl_LightSource[0].diffuse * pf;
vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse; vec4 color = gl_Color + Diffuse*diffuseColor;
color = clamp( color, 0.0, 1.0 ); color = clamp( color, 0.0, 1.0 );
color.a = texel.a * diffuseColor.a;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
//BEGIN reflect //BEGIN reflect
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
if (refl_enabled > 0 ){ if (refl_enabled > 0 ){
float reflFactor = 0.0; float reflFactor = 0.0;
float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset
if(refl_map > 0){ if(refl_map > 0){
// map the shininess of the object with user input // map the shininess of the object with user input
//float pam = (map.a * -2) + 1; //reverse map
reflFactor = reflmap.a + transparency_offset; reflFactor = reflmap.a + transparency_offset;
} else if (nmap_enabled > 0) { } else if (nmap_enabled > 0) {
// set the reflectivity proportional to shininess with user input // set the reflectivity proportional to shininess with user input
@ -127,13 +204,13 @@ void main (void)
reflFactor = clamp(reflFactor, 0.0, 1.0); reflFactor = clamp(reflFactor, 0.0, 1.0);
// 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, refl_rainbow * v); vec3 reflcolor = mix(reflection, rainbow.rgb, refl_rainbow * v);
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v); vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise); vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0); vec3 raincolor = noisecolor * reflFactor;
raincolor += Specular; raincolor += Specular.rgb;
raincolor *= gl_LightSource[0].diffuse; raincolor *= gl_LightSource[0].diffuse.rgb;
mixedcolor = mix(texel, raincolor, reflFactor).rgb; mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else { } else {
mixedcolor = texel.rgb; mixedcolor = texel.rgb;
} }
@ -141,20 +218,28 @@ void main (void)
//END reflect //END reflect
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
if (color.a<1.0){
color.a += .1 * eDotLV;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//begin DIRT //begin DIRT
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
if (dirt_enabled >= 1){ if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor); vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb; vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb;
//dirtFactor.r = smoothstep(0.0, 1.0, dirtFactor.r);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r));
if (color.a < 1.0) {
color.a += dirtFactor.r * eDotLV;
}
if (dirt_multi > 0) { if (dirt_multi > 0) {
//dirtFactor.g = smoothstep(0.0, 1.0, dirtFactor.g);
//dirtFactor.b = smoothstep(0.0, 1.0, dirtFactor.b);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g));
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b)); mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
if (color.a < 1.0) {
color.a += dirtFactor.g * eDotLV;
color.a += dirtFactor.b * eDotLV;
}
} }
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
//END Dirt //END Dirt
@ -164,18 +249,19 @@ void main (void)
// set ambient adjustment to remove bluiness with user input // set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(amb_correction, -1.0, 1.0); float ambient_offset = clamp(amb_correction, -1.0, 1.0);
vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient; vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient;
vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0)
* ambient_offset ; vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6);
ambient_Correction *= ambient_offset;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0); ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a); vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a; fragColor += Specular * nmap.a;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// BEGIN lightmap // BEGIN lightmap
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
if ( lightmap_enabled >= 1 ) { if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor = vec3(0.0); vec3 lightmapcolor = vec3(0.0);
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor,
@ -189,12 +275,13 @@ void main (void)
} else { } else {
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r; lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
} }
fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * smoothstep(0.0, 1.0, mixedcolor*.5 + lightmapcolor*.5)); fragColor.rgb = max(fragColor.rgb, lightmapcolor * smoothstep(0.0, 1.0, mixedcolor*.5 + lightmapcolor*.5));
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// END lightmap // END lightmap
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
fragColor.rgb = fog_Func(fragColor.rgb, fogType); fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor; gl_FragColor = fragColor;
} }

95
Shaders/ubershader.vert Normal file → Executable file
View file

@ -1,60 +1,43 @@
// -*- mode: C; -*- // -*- mode: C; -*-
// UBERSHADER - vertex shader
// Licence: GPL v2 // Licence: GPL v2
// © Emilian Huminiuc and Vivian Meazza 2011 // © Emilian Huminiuc and Vivian Meazza 2011
#version 120 #version 120
varying vec3 rawpos; varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 rawpos;
varying vec3 vViewVec; varying vec3 eyeVec;
varying vec3 reflVec; varying vec3 eyeDir;
varying vec3 vertVec;
varying float alpha;
attribute vec3 tangent; attribute vec3 tangent;
attribute vec3 binormal; attribute vec3 binormal;
uniform float pitch;
uniform float roll;
uniform float hdg;
uniform int refl_dynamic;
uniform int nmap_enabled; uniform int nmap_enabled;
uniform int shader_qual;
uniform int rembrandt_enabled; uniform int rembrandt_enabled;
//////Fog Include///////////
// uniform int fogType;
// void fog_Func(int type);
////////////////////////////
void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat)
{
rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0,
0.0 , cosRx , -sinRx * cosRx, 0.0,
-sinRy, sinRx * cosRy, cosRx * cosRy , 0.0,
0.0 , 0.0 , 0.0 , 1.0 );
}
void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
{
rotmat = mat4( cosRz, -sinRz, 0.0, 0.0,
sinRz, cosRz, 0.0, 0.0,
0.0 , 0.0 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 );
}
void main(void) void main(void)
{ {
rawpos = gl_Vertex.xyz; rawpos = gl_Vertex.xyz;
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
//fog_Func(fogType); eyeVec = ecPosition.xyz;
eyeDir = gl_ModelViewMatrixInverse[3].xyz - gl_Vertex.xyz;
VNormal = normalize(gl_NormalMatrix * gl_Normal); VNormal = normalize(gl_NormalMatrix * gl_Normal);
vec3 n = normalize(gl_Normal); vec3 n = normalize(gl_Normal);
vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0));
// generate "fake" binormals/tangents
vec3 c1 = cross(n, vec3(0.0,0.0,1.0));
vec3 c2 = cross(n, vec3(0.0,1.0,0.0));
vec3 tempTangent = c1;
if(length(c2)>length(c1)){
tempTangent = c2;
}
vec3 tempBinormal = cross(n, tempTangent); vec3 tempBinormal = cross(n, tempTangent);
if (nmap_enabled > 0){ if (nmap_enabled > 0){
@ -64,48 +47,12 @@ void main(void)
VTangent = normalize(gl_NormalMatrix * tempTangent); VTangent = normalize(gl_NormalMatrix * tempTangent);
VBinormal = normalize(gl_NormalMatrix * tempBinormal); VBinormal = normalize(gl_NormalMatrix * tempBinormal);
vec3 t = tempTangent;
vec3 b = tempBinormal;
diffuseColor = gl_Color;
// Super hack: if diffuse material alpha is less than 1, assume a // Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work // transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0) if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a; diffuseColor.a = gl_FrontMaterial.diffuse.a;
else
alpha = gl_Color.a;
// Vertex in eye coordinates
vertVec = ecPosition.xyz;
vViewVec.x = dot(t, vertVec);
vViewVec.y = dot(b, vertVec);
vViewVec.z = dot(n, vertVec);
// calculate the reflection vector
vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0);
vec3 reflVec_stat = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz;
if (refl_dynamic > 0){
//prepare rotation matrix
mat4 RotMatPR;
mat4 RotMatH;
float _roll = roll;
if (_roll>90.0 || _roll < -90.0)
{
_roll = -_roll;
}
float cosRx = cos(radians(_roll));
float sinRx = sin(radians(_roll));
float cosRy = cos(radians(-pitch));
float sinRy = sin(radians(-pitch));
float cosRz = cos(radians(hdg));
float sinRz = sin(radians(hdg));
rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR);
rotationMatrixH(sinRz, cosRz, RotMatH);
vec3 reflVec_dyn = (RotMatH * (RotMatPR * normalize(gl_ModelViewMatrixInverse * reflect_eye))).xyz;
reflVec = reflVec_dyn;
} else {
reflVec = reflVec_stat;
}
if(rembrandt_enabled < 1){ if(rembrandt_enabled < 1){
gl_FrontColor = gl_FrontMaterial.emission + gl_Color gl_FrontColor = gl_FrontMaterial.emission + gl_Color
@ -113,6 +60,8 @@ void main(void)
} else { } else {
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
} }
gl_Position = ftransform(); gl_Position = ftransform();
gl_ClipVertex = ecPosition;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 KiB