diff --git a/Effects/building.eff b/Effects/building.eff old mode 100644 new mode 100755 index 504bb23bc..b227bf100 --- a/Effects/building.eff +++ b/Effects/building.eff @@ -12,9 +12,17 @@ normalized - 0 + 1 0 1.0 + + Textures/buildings-normalmap_orig.png + 2d + linear-mipmap-linear + clamp + clamp + normalized + Textures/buildings-lightmap.png @@ -39,7 +47,6 @@ 1 1 - -0.15 0 0.0 @@ -362,6 +369,17 @@ + + true + 1 + 0.6 0.6 0.6 1.0 + 1.0 1.0 1.0 1.0 + 0.0 0.0 0.0 1.0 + 0.02 0.02 0.02 1.0 + 0.1 + ambient-and-diffuse + ambient-and-diffuse + 4 @@ -389,34 +407,19 @@ - - + + true + 1 + 0.6 0.6 0.6 1.0 + 1.0 1.0 1.0 1.0 + 0.0 0.0 0.0 1.0 + 0.02 0.02 0.02 1.0 + 0.1 + ambient-and-diffuse + ambient-and-diffuse + 4 @@ -439,7 +442,7 @@ - Shaders/building-ubershader.vert + Shaders/building-ubershader.vert @@ -455,7 +458,7 @@ - Shaders/building-default.vert + Shaders/building-default.vert @@ -539,15 +542,13 @@ vertex-program-two-side - - - Shaders/building-default.vert + Shaders/building-default.vert Shaders/include_fog.frag Shaders/default.frag - + fogType int diff --git a/Effects/model-combined-deferred.eff b/Effects/model-combined-deferred.eff old mode 100644 new mode 100755 index deeb6b095..f4e0a87ff --- a/Effects/model-combined-deferred.eff +++ b/Effects/model-combined-deferred.eff @@ -244,9 +244,9 @@ the objects that use it, and replaces it with the default shader. Shaders/ubershader.vert - Shaders/ubershader-gbuffer.frag - Shaders/gbuffer-functions.frag - Shaders/gbuffer-encode.frag + Shaders/ubershader-gbuffer.frag + Shaders/gbuffer-functions.frag + Shaders/gbuffer-encode.frag @@ -285,18 +285,6 @@ the objects that use it, and replaces it with the default shader. 5 - - ReflGradientsTex sampler-2d @@ -548,31 +536,23 @@ the objects that use it, and replaces it with the default shader. - hdg + lonDeg float - model-hdg + pos-lon - pitch + latDeg float - model-pitch - - - - - roll - float - - model-roll + pos-lat - + rembrandt_enabled diff --git a/Effects/model-combined-transparent.eff b/Effects/model-combined-transparent.eff old mode 100644 new mode 100755 index 05470e77f..ad8ea1a57 --- a/Effects/model-combined-transparent.eff +++ b/Effects/model-combined-transparent.eff @@ -329,18 +329,9 @@ and fallback to plain transparency when the model shader is disabled. - - Shaders/ubershader.vert + Shaders/ubershader.vert Shaders/include_fog.frag Shaders/ubershader.frag - @@ -628,33 +619,25 @@ and fallback to plain transparency when the model shader is disabled. ambient-correction - + - hdg + lonDeg float - model-hdg + pos-lon - + - pitch + latDeg float - model-pitch - - - - - roll - float - - model-roll + pos-lat - + fogType int diff --git a/Effects/model-combined.eff b/Effects/model-combined.eff old mode 100644 new mode 100755 index 25da2b7cf..ae760c061 --- a/Effects/model-combined.eff +++ b/Effects/model-combined.eff @@ -128,6 +128,12 @@ please see Docs/README.model-combined.eff for documentation orientation/model/roll-deg + + position/longitude-deg + + + position/latitude-deg + /environment/ground-visibility-m /environment/visibility-m @@ -1137,6 +1143,21 @@ please see Docs/README.model-combined.eff for documentation rembrandt + + lonDeg + float + + pos-lon + + + + + latDeg + float + + pos-lat + + @@ -1357,18 +1378,9 @@ please see Docs/README.model-combined.eff for documentation - - Shaders/ubershader.vert + Shaders/ubershader.vert Shaders/include_fog.frag Shaders/ubershader.frag - @@ -1657,32 +1669,25 @@ please see Docs/README.model-combined.eff for documentation + - hdg - float - - model-hdg - + lonDeg + float + + pos-lon + - pitch - float - - model-pitch - - - - - roll - float - - model-roll - + latDeg + float + + pos-lat + - + fogType int diff --git a/Shaders/building-ubershader.vert b/Shaders/building-ubershader.vert old mode 100644 new mode 100755 index 7a6d8a06b..a1c964d7f --- a/Shaders/building-ubershader.vert +++ b/Shaders/building-ubershader.vert @@ -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 vec3 VNormal; -varying vec3 VTangent; -varying vec3 VBinormal; -varying vec3 vViewVec; -varying vec3 vertVec; -varying vec3 reflVec; +varying vec4 diffuseColor; +varying vec3 VBinormal; +varying vec3 VNormal; +varying vec3 VTangent; +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_LightModel.ambient + gl_LightSource[0].ambient); - } else { - gl_FrontColor = vec4(1.0,1.0,1.0,1.0); - } - gl_Position = gl_ModelViewProjectionMatrix * vec4(rawpos,1.0); - gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + if(rembrandt_enabled < 1){ + gl_FrontColor = gl_FrontMaterial.emission + vec4(1.0) + * (gl_LightModel.ambient + gl_LightSource[0].ambient); + } else { + gl_FrontColor = vec4(1.0); + } + gl_Position = gl_ModelViewProjectionMatrix * vec4(rawpos,1.0); + gl_ClipVertex = ecPosition; + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } diff --git a/Shaders/model-ALS-ultra.frag b/Shaders/model-ALS-ultra.frag old mode 100644 new mode 100755 index ed1eb0df1..f013f1561 --- a/Shaders/model-ALS-ultra.frag +++ b/Shaders/model-ALS-ultra.frag @@ -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,21 +277,57 @@ 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 - vec4 fresnel = texture2D(ReflGradientsTex, vec2(v, 0.75)); - vec4 rainbow = texture2D(ReflGradientsTex, vec2(v, 0.25)); +///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; @@ -259,7 +335,7 @@ void main (void) // 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,15 +423,21 @@ 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; + } + } + } ////////////////////////////////////////////////////////////////////// //END Dirt ////////////////////////////////////////////////////////////////////// @@ -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; @@ -402,18 +486,18 @@ void main (void) if ( lightmap_enabled >= 1 ) { vec3 lightmapcolor = vec3(0.0); vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, - lightmap_b_factor, lightmap_a_factor); + lightmap_b_factor, lightmap_a_factor); lightmapFactor = lightmapFactor * lightmapTexel; if (lightmap_multi > 0 ){ lightmapcolor = lightmap_r_color * lightmapFactor.r + - lightmap_g_color * lightmapFactor.g + - lightmap_b_color * lightmapFactor.b + - lightmap_a_color * lightmapFactor.a ; - } else { + lightmap_g_color * lightmapFactor.g + + lightmap_b_color * lightmapFactor.b + + lightmap_a_color * lightmapFactor.a ; + } 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)); - } + } ////////////////////////////////////////////////////////////////////// // END lightmap ///////////////////////////////////////////////////////////////////// @@ -537,10 +621,10 @@ void main (void) ///BEGIN Rayleigh fog /// - // 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 outscatter = 1.0-exp(-dist/rayleigh_length); - fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter); + // 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 outscatter = 1.0-exp(-dist/rayleigh_length); + fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter); 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); @@ -556,6 +640,6 @@ void main (void) 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; - } +} diff --git a/Shaders/ubershader-gbuffer.frag b/Shaders/ubershader-gbuffer.frag old mode 100644 new mode 100755 index 043b1c551..9dde7f670 --- a/Shaders/ubershader-gbuffer.frag +++ b/Shaders/ubershader-gbuffer.frag @@ -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 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,11 +109,11 @@ 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; -///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); @@ -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 -//////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + //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 -////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + // 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 -///////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + // END lightmap + //////////////////////////////////////////////////////////////////////////////// encode_gbuffer(N, fragColor.rgb, 255, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z); } \ No newline at end of file diff --git a/Shaders/ubershader.frag b/Shaders/ubershader.frag old mode 100644 new mode 100755 index d2f5f96d8..14d245b26 --- a/Shaders/ubershader.frag +++ b/Shaders/ubershader.frag @@ -1,64 +1,106 @@ // -*- 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 vec3 eyeVec; +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 sampler2D LightMapTex; -uniform sampler2D NormalTex; -uniform sampler2D ReflGradientsTex; -uniform sampler2D ReflMapTex; -uniform sampler3D ReflNoiseTex; -uniform samplerCube Environment; +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 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_map; +uniform float amb_correction; +uniform float dirt_b_factor; +uniform float dirt_g_factor; +uniform float dirt_r_factor; +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 float amb_correction; -uniform float dirt_b_factor; -uniform float dirt_g_factor; -uniform float dirt_r_factor; -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 lightmap_g_color; +uniform vec3 lightmap_b_color; +uniform vec3 lightmap_a_color; -uniform vec3 lightmap_r_color; -uniform vec3 lightmap_g_color; -uniform vec3 lightmap_b_color; -uniform vec3 lightmap_a_color; +uniform vec3 dirt_r_color; +uniform vec3 dirt_g_color; +uniform vec3 dirt_b_color; -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,19 +182,18 @@ 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 ); - -//////////////////////////////////////////////////////////////////// -//BEGIN reflect -//////////////////////////////////////////////////////////////////// + color.a = texel.a * diffuseColor.a; + //////////////////////////////////////////////////////////////////// + //BEGIN reflect + //////////////////////////////////////////////////////////////////// if (refl_enabled > 0 ){ float reflFactor = 0.0; float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset 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,20 +218,28 @@ 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,18 +249,19 @@ 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; -////////////////////////////////////////////////////////////////////// -// BEGIN lightmap -////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + // BEGIN lightmap + ////////////////////////////////////////////////////////////////////// if ( lightmap_enabled >= 1 ) { vec3 lightmapcolor = vec3(0.0); vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, @@ -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 -///////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + // END lightmap + ///////////////////////////////////////////////////////////////////// fragColor.rgb = fog_Func(fragColor.rgb, fogType); + gl_FragColor = fragColor; } diff --git a/Shaders/ubershader.vert b/Shaders/ubershader.vert old mode 100644 new mode 100755 index 23687cb1b..5379107a0 --- a/Shaders/ubershader.vert +++ b/Shaders/ubershader.vert @@ -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; } diff --git a/Textures/buildings-normalmap_orig.png b/Textures/buildings-normalmap_orig.png new file mode 100755 index 000000000..e28d4c9b5 Binary files /dev/null and b/Textures/buildings-normalmap_orig.png differ