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>
</texture>
<!-- Normal Map -->
<normalmap-enabled type="int"> 0 </normalmap-enabled>
<normalmap-enabled type="int"> 1 </normalmap-enabled>
<normalmap-dds type="int"> 0 </normalmap-dds>
<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 -->
<texture n="3">
<image>Textures/buildings-lightmap.png</image>
@ -39,7 +47,6 @@
<!-- Reflection -->
<reflection-enabled type="int"> 1 </reflection-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-dynamic type="int"> 0 </reflection-dynamic>
<reflection-fresnel type="float"> 0.0 </reflection-fresnel>
@ -362,6 +369,17 @@
<technique n="7">
<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">
<unit>4</unit>
<image>
@ -389,34 +407,19 @@
</pass>
</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">
<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">
<unit>4</unit>
<image>
@ -439,7 +442,7 @@
</internal-format>
</texture-unit>
<program n="0">
<vertex-shader n="1">Shaders/building-ubershader.vert</vertex-shader>
<vertex-shader n="0">Shaders/building-ubershader.vert</vertex-shader>
</program>
</pass>
</technique>
@ -455,7 +458,7 @@
<technique n="11">
<pass>
<program n="0">
<vertex-shader n="1">Shaders/building-default.vert</vertex-shader>
<vertex-shader n="0">Shaders/building-default.vert</vertex-shader>
</program>
</pass>
</technique>
@ -539,15 +542,13 @@
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> -->
<!--fog include-->
<vertex-shader n="1">Shaders/building-default.vert</vertex-shader>
<vertex-shader n="0">Shaders/building-default.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<!--fog include-->
<fragment-shader n="1">Shaders/default.frag</fragment-shader>
</program>
<!-- BEGIN fog include -->
<uniform>
<!--<uniform>
<name>visibility</name>
<type>float</type>
<value>
@ -581,7 +582,7 @@
<value>
<use>terminator</use>
</value>
</uniform>
</uniform>-->
<uniform>
<name>fogType</name>
<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">
<vertex-shader n="0">Shaders/ubershader.vert</vertex-shader>
<fragment-shader>Shaders/ubershader-gbuffer.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
<fragment-shader>Shaders/gbuffer-encode.frag</fragment-shader>
<fragment-shader n="0">Shaders/ubershader-gbuffer.frag</fragment-shader>
<fragment-shader n="1">Shaders/gbuffer-functions.frag</fragment-shader>
<fragment-shader n="2">Shaders/gbuffer-encode.frag</fragment-shader>
</program>
<uniform>
@ -285,18 +285,6 @@ the objects that use it, and replaces it with the default shader.
<value type="int">5</value>
</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>
<name>ReflGradientsTex</name>
<type>sampler-2d</type>
@ -548,31 +536,23 @@ the objects that use it, and replaces it with the default shader.
</uniform>
<uniform>
<name>hdg</name>
<name>lonDeg</name>
<type>float</type>
<value>
<use>model-hdg</use>
<use>pos-lon</use>
</value>
</uniform>
<uniform>
<name>pitch</name>
<name>latDeg</name>
<type>float</type>
<value>
<use>model-pitch</use>
</value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
<use>pos-lat</use>
</value>
</uniform>
<!-- BEGIN fog include -->
<uniform>
<!--<uniform>
<name>visibility</name>
<type>float</type>
<value>
@ -613,7 +593,7 @@ the objects that use it, and replaces it with the default shader.
<value>
<use>fogtype</use>
</value>
</uniform>
</uniform>-->
<!-- END fog include -->
<uniform>
<name>rembrandt_enabled</name>

31
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>
<program>
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<vertex-shader n="0">Shaders/ubershader.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.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>
<uniform>
@ -630,31 +621,23 @@ and fallback to plain transparency when the model shader is disabled.
</uniform>
<uniform>
<name>hdg</name>
<name>lonDeg</name>
<type>float</type>
<value>
<use>model-hdg</use>
<use>pos-lon</use>
</value>
</uniform>
<uniform>
<name>pitch</name>
<name>latDeg</name>
<type>float</type>
<value>
<use>model-pitch</use>
</value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
<use>pos-lat</use>
</value>
</uniform>
<!-- BEGIN fog include -->
<uniform>
<!--<uniform>
<name>visibility</name>
<type>float</type>
<value>
@ -688,7 +671,7 @@ and fallback to plain transparency when the model shader is disabled.
<value>
<use>terminator</use>
</value>
</uniform>
</uniform>-->
<uniform>
<name>fogType</name>
<type>int</type>

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

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

@ -1,50 +1,20 @@
// -*- mode: C; -*-
// RANDOM BUILDINGS for the UBERSHADER vertex shader
// Licence: GPL v2
// © Emilian Huminiuc and Vivian Meazza 2011
#version 120
varying vec3 rawpos;
varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 vertVec;
varying vec3 reflVec;
varying vec3 rawpos;
varying vec3 eyeVec;
varying float alpha;
attribute vec3 tangent;
attribute vec3 binormal;
uniform float pitch;
uniform float roll;
uniform float hdg;
uniform int refl_dynamic;
uniform int nmap_enabled;
uniform int shader_qual;
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)
{
@ -56,75 +26,41 @@ void main(void)
rawpos.xy = vec2(dot(rawpos.xy, vec2(cr, sr)), dot(rawpos.xy, vec2(-sr, cr)));
rawpos = rawpos + gl_Color.xyz;
vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos.x, rawpos.y, rawpos.z, 1.0);
//fog_Func(fogType);
vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos.xyz, 1.0);
eyeVec = ecPosition.xyz;
// Rotate the normal.
vec3 normal = gl_Normal;
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
//normal = gl_NormalMatrix * normal;
VNormal = normalize(gl_NormalMatrix * normal);
vec3 n = normalize(normal);
vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0));
vec3 tempBinormal = cross(n, tempTangent);
vec3 c1 = cross(n, vec3(0.0,0.0,1.0));
vec3 c2 = cross(n, vec3(0.0,1.0,0.0));
if (nmap_enabled > 0){
tempTangent = tangent;
tempBinormal = binormal;
VTangent = c1;
if(length(c2)>length(c1)){
VTangent = c2;
}
VTangent = normalize(gl_NormalMatrix * tempTangent);
VBinormal = normalize(gl_NormalMatrix * tempBinormal);
vec3 t = tempTangent;
vec3 b = tempBinormal;
VBinormal = cross(n, VTangent);
// Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a;
else
alpha = 1.0;
VTangent = normalize(gl_NormalMatrix * -VTangent);
VBinormal = normalize(gl_NormalMatrix * VBinormal);
// 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;
}
// Force no alpha on random buildings
diffuseColor = vec4(gl_FrontMaterial.diffuse.rgb,1.0);
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);
} 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_ClipVertex = ecPosition;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}

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

@ -7,15 +7,13 @@
// by Thorsten Renk, 2013
#version 120
varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 rawpos;
varying vec3 reflVec;
varying vec3 vViewVec;
varying vec3 vertVec;
varying float alpha;
varying vec3 eyeVec;
varying vec3 eyeDir;
uniform sampler2D BaseTex;
uniform sampler2D LightMapTex;
@ -33,6 +31,7 @@ uniform int lightmap_multi;
uniform int nmap_dds;
uniform int nmap_enabled;
uniform int refl_enabled;
uniform int refl_dynamic;
uniform int refl_map;
uniform int grain_texture_enabled;
uniform int rain_enabled;
@ -90,6 +89,47 @@ uniform vec3 dirt_r_color;
uniform vec3 dirt_g_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 shadow_func (in float x, in float y, in float noise, in float dist);
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));
//worldPos3D.a = 0.0;
//vec3 up = (osg_ViewMatrix * worldPos3D).xyz;
float dist = length(vertVec);
float vertex_alt = max(100.0,dot(up, vertVec) + alt);
float dist = length(eyeVec);
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);
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 lightArg = (terminator-yprime_alt)/100000.0;
@ -157,7 +197,7 @@ void main (void)
float mie_angle;
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
{mie_angle = 1.0;}
@ -180,7 +220,7 @@ void main (void)
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 ct = dot(normalize(up), normalize(vertVec));
float ct = dot(normalize(up), normalize(eyeVec));
/// END geometry for light
@ -237,29 +277,65 @@ void main (void)
} else {
N = normalize(VNormal);
}
///END bump
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
vec3 viewVec = normalize(vViewVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color
///END bump ////////////////////////////////////////////////////////////////////
vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25));
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)));
//glare on the backside of tranparent objects
if ((gl_FrontMaterial.diffuse.a < 1.0 || texel.a < 1.0)
&& dot(N, normalize(gl_LightSource[0].position.xyz)) < 0.0) {
nDotVP = max(0.0, dot(-N, normalize(gl_LightSource[0].position.xyz)));
nDotHV = max(0.0, dot(-N, normalize(gl_LightSource[0].halfVector.xyz)));
mat4 reflMatrix = gl_ModelViewMatrixInverse;
vec3 wRefVec = reflect(viewVec,N);
////dynamic reflection /////////////////////////////
if (refl_dynamic > 0){
reflMatrix = osg_ViewMatrixInverse;
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 nDotHV1 = 0.0;
// try specular reflection of sky irradiance
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)
@ -273,7 +349,7 @@ void main (void)
{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)
{
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;
Diffuse.rgb += secondary_light * light_distance_fading(dist);
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.a = texel.a * diffuseColor.a;
////////////////////////////////////////////////////////////////////
//BEGIN reflect
////////////////////////////////////////////////////////////////////
@ -323,20 +399,23 @@ void main (void)
reflFactor = clamp(reflFactor, 0.0, 1.0);
// 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 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
raincolor += Specular;
raincolor *= light_diffuse;
mixedcolor = mix(texel, raincolor, reflFactor).rgb;
vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec3 raincolor = noisecolor.rgb * reflFactor;
raincolor += Specular.rgb;
raincolor *= light_diffuse.rgb;
mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else {
mixedcolor = texel.rgb;
}
/////////////////////////////////////////////////////////////////////
//END reflect
/////////////////////////////////////////////////////////////////////
if (color.a < .999){
color.a += .1 * eDotLV;
}
//////////////////////////////////////////////////////////////////////
//begin DIRT
@ -344,13 +423,19 @@ void main (void)
if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
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));
if (color.a < .999) {
color.a += dirtFactor.r * eDotLV;
}
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_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
if (color.a < 1.0) {
color.a += dirtFactor.g * eDotLV;
color.a += dirtFactor.b * eDotLV;
}
}
}
//////////////////////////////////////////////////////////////////////
@ -373,7 +458,7 @@ void main (void)
}
// 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);
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;
@ -387,11 +472,10 @@ void main (void)
float ambient_offset = clamp(amb_correction, -1.0, 1.0);
//vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient;
vec4 ambient = gl_LightModel.ambient + light_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);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a;

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

@ -1,18 +1,17 @@
// -*- mode: C; -*-
// UBERSHADER - Rembrandt version - fragment shader
// Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011
#version 120
varying vec3 rawpos;
varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying float alpha;
varying vec3 rawpos;
varying vec3 eyeVec;
uniform samplerCube Environment;
uniform sampler2D BaseTex;
@ -22,14 +21,15 @@ uniform sampler2D ReflMapTex;
uniform sampler2D ReflGradientsTex;
uniform sampler3D ReflNoiseTex;
uniform int nmap_enabled;
uniform int nmap_dds;
uniform int refl_enabled;
uniform int refl_map;
uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int dirt_enabled;
uniform int dirt_multi;
uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int nmap_dds;
uniform int nmap_enabled;
uniform int refl_enabled;
uniform int refl_dynamic;
uniform int refl_map;
uniform float lightmap_r_factor;
uniform float lightmap_g_factor;
@ -54,13 +54,47 @@ uniform vec3 dirt_r_color;
uniform vec3 dirt_g_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);
///fog include//////////////////////
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
////////////////////////////////////
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;
}
////////////////////////////////////////////////////////////////////////////////
void main (void)
{
@ -75,7 +109,7 @@ void main (void)
//vec3 ambient = fg_SunAmbientColor.rgb;
vec3 N;
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 ) );
float pf;
@ -88,18 +122,44 @@ void main (void)
} else {
N = normalize(VNormal);
}
///END bump
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
vec3 viewVec = normalize(vViewVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color
///END bump ////////////////////////////////////////////////////////////////////
vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
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 ));
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//BEGIN reflect
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if (refl_enabled > 0){
float reflFactor;
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);
// add fringing fresnel and rainbow effects and modulate by reflection
vec4 reflcolor = mix(reflection, rainbow, refl_rainbow * v);
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
mixedcolor = mix(texel, raincolor, reflFactor).rgb;
vec3 reflcolor = mix(reflection, rainbow.rgb, refl_rainbow * v);
vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec3 raincolor = noisecolor.rgb * reflFactor;
mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else {
mixedcolor = texel.rgb;
}
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//END reflect
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//begin DIRT
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
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));
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_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
}
}
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//END Dirt
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// 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;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction.rgb, color.a);
//vec4 fragColor = vec4(color.rgb * mixedcolor, color.a);
//specifically disallow alpha
color.a = 1.0; //texel.a * alpha;
color.rgb *= mixedcolor.rgb;
color.rgb += ambient_Correction.rgb;
vec4 fragColor = color;
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// BEGIN lightmap
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor;
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),
lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
}
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// END lightmap
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
encode_gbuffer(N, fragColor.rgb, 255, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z);
}

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

@ -1,18 +1,18 @@
// -*- mode: C; -*-
// UBERSHADER - default forward rendering - fragment shader
// Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011
#version 120
varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 rawpos;
varying vec3 reflVec;
varying vec3 vViewVec;
varying float alpha;
varying vec3 eyeVec;
varying vec3 eyeDir;
uniform sampler2D BaseTex;
uniform sampler2D LightMapTex;
@ -29,6 +29,7 @@ uniform int lightmap_multi;
uniform int nmap_dds;
uniform int nmap_enabled;
uniform int refl_enabled;
uniform int refl_dynamic;
uniform int refl_map;
uniform float amb_correction;
@ -54,11 +55,52 @@ uniform vec3 dirt_r_color;
uniform vec3 dirt_g_color;
uniform vec3 dirt_b_color;
///reflection orientation
uniform mat4 osg_ViewMatrixInverse;
uniform float latDeg;
uniform float lonDeg;
///fog include//////////////////////
uniform int fogType;
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)
{
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
@ -71,7 +113,7 @@ void main (void)
vec3 N = vec3(0.0,0.0,1.0);
float pf = 0.0;
///BEGIN bump
///BEGIN bump //////////////////////////////////////////////////////////////////
if (nmap_enabled > 0 ){
N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
@ -80,22 +122,58 @@ void main (void)
} else {
N = normalize(VNormal);
}
///END bump
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
vec3 viewVec = normalize(vViewVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color
///END bump ////////////////////////////////////////////////////////////////////
vec3 viewN = normalize((gl_ModelViewMatrixTranspose * vec4(N,0.0)).xyz);
vec3 viewVec = normalize(eyeVec);
float v = abs(dot(viewVec, viewN));// Map a rainbowish color
vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75));
vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25));
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)));
//glare on the backside of tranparent objects
if ((gl_FrontMaterial.diffuse.a < 1.0 || texel.a < 1.0)
&& dot(N, normalize(gl_LightSource[0].position.xyz)) < 0.0) {
nDotVP = max(0.0, dot(-N, normalize(gl_LightSource[0].position.xyz)));
nDotHV = max(0.0, dot(-N, normalize(gl_LightSource[0].halfVector.xyz)));
mat4 reflMatrix = gl_ModelViewMatrixInverse;
vec3 wRefVec = reflect(viewVec,N);
////dynamic reflection /////////////////////////////
if (refl_dynamic > 0){
reflMatrix = osg_ViewMatrixInverse;
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)
pf = 0.0;
else
@ -104,9 +182,9 @@ void main (void)
vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
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.a = texel.a * diffuseColor.a;
////////////////////////////////////////////////////////////////////
//BEGIN reflect
////////////////////////////////////////////////////////////////////
@ -116,7 +194,6 @@ void main (void)
if(refl_map > 0){
// map the shininess of the object with user input
//float pam = (map.a * -2) + 1; //reverse map
reflFactor = reflmap.a + transparency_offset;
} else if (nmap_enabled > 0) {
// set the reflectivity proportional to shininess with user input
@ -127,13 +204,13 @@ void main (void)
reflFactor = clamp(reflFactor, 0.0, 1.0);
// add fringing fresnel and rainbow effects and modulate by reflection
vec4 reflcolor = mix(reflection, rainbow, refl_rainbow * v);
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
raincolor += Specular;
raincolor *= gl_LightSource[0].diffuse;
mixedcolor = mix(texel, raincolor, reflFactor).rgb;
vec3 reflcolor = mix(reflection, rainbow.rgb, refl_rainbow * v);
vec3 reflfrescolor = mix(reflcolor, fresnel.rgb, refl_fresnel * v);
vec3 noisecolor = mix(reflfrescolor, noisevec.rgb, refl_noise);
vec3 raincolor = noisecolor * reflFactor;
raincolor += Specular.rgb;
raincolor *= gl_LightSource[0].diffuse.rgb;
mixedcolor = mix(texel.rgb, raincolor, reflFactor);
} else {
mixedcolor = texel.rgb;
}
@ -141,21 +218,29 @@ void main (void)
//END reflect
/////////////////////////////////////////////////////////////////////
if (color.a<1.0){
color.a += .1 * eDotLV;
}
//////////////////////////////////////////////////////////////////////
//begin DIRT
//////////////////////////////////////////////////////////////////////
if (dirt_enabled >= 1){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
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));
if (color.a < 1.0) {
color.a += dirtFactor.r * eDotLV;
}
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_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
//////////////////////////////////////////////////////////////////////
@ -164,11 +249,12 @@ void main (void)
// set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(amb_correction, -1.0, 1.0);
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);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a;
@ -189,12 +275,13 @@ void main (void)
} else {
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
/////////////////////////////////////////////////////////////////////
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor;
}

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

@ -1,60 +1,43 @@
// -*- mode: C; -*-
// UBERSHADER - vertex shader
// Licence: GPL v2
// © Emilian Huminiuc and Vivian Meazza 2011
#version 120
varying vec3 rawpos;
varying vec4 diffuseColor;
varying vec3 VBinormal;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying vec3 vertVec;
varying float alpha;
varying vec3 rawpos;
varying vec3 eyeVec;
varying vec3 eyeDir;
attribute vec3 tangent;
attribute vec3 binormal;
uniform float pitch;
uniform float roll;
uniform float hdg;
uniform int refl_dynamic;
uniform int nmap_enabled;
uniform int shader_qual;
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)
{
rawpos = gl_Vertex.xyz;
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);
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);
if (nmap_enabled > 0){
@ -64,48 +47,12 @@ void main(void)
VTangent = normalize(gl_NormalMatrix * tempTangent);
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
// transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = 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;
}
diffuseColor.a = gl_FrontMaterial.diffuse.a;
if(rembrandt_enabled < 1){
gl_FrontColor = gl_FrontMaterial.emission + gl_Color
@ -113,6 +60,8 @@ void main(void)
} else {
gl_FrontColor = gl_Color;
}
gl_Position = ftransform();
gl_ClipVertex = ecPosition;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 KiB