1
0
Fork 0

Simple conversion of ubershader for Rembrandt, as ubersahader-gbuffer.frag

Make model-combined-gbuffer use it
Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
Emilian Huminiuc 2012-03-31 22:18:43 +03:00
parent b2b391b2ef
commit a3f004f4ec
2 changed files with 187 additions and 2 deletions

View file

@ -49,9 +49,12 @@ the objects that use it, and replaces it with the default shader.
</shininess> </shininess>
<color-mode>ambient-and-diffuse</color-mode> <color-mode>ambient-and-diffuse</color-mode>
</material> </material>
<cull-face>back</cull-face>
<program> <program>
<vertex-shader n="1">Shaders/deferred-gbuffer.vert</vertex-shader> <vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/deferred-gbuffer.frag</fragment-shader> <fragment-shader n="1">Shaders/ubershader-gbuffer.frag</fragment-shader>
<!-- <vertex-shader n="1">Shaders/deferred-gbuffer.vert</vertex-shader>
<fragment-shader n="1">Shaders/deferred-gbuffer.frag</fragment-shader>-->
</program> </program>
</pass> </pass>
</technique> </technique>

View file

@ -0,0 +1,182 @@
// -*- mode: C; -*-
// Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011
varying vec3 rawpos;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying float alpha;
uniform samplerCube Environment;
uniform sampler2D BaseTex;
uniform sampler2D NormalTex;
uniform sampler2D LightMapTex;
uniform sampler2D ReflMapTex;
uniform sampler2D ReflFresnelTex;
uniform sampler2D ReflRainbowTex;
uniform sampler3D ReflNoiseTex;
uniform int nmap_enabled;
uniform int nmap_dds;
uniform int nmap_tile;
uniform int refl_enabled;
uniform int refl_map;
uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int shader_qual;
uniform int dirt_enabled;
uniform int dirt_multi;
uniform float lightmap_r_factor;
uniform float lightmap_g_factor;
uniform float lightmap_b_factor;
uniform float lightmap_a_factor;
uniform float refl_correction;
uniform float refl_fresnel;
uniform float refl_rainbow;
uniform float refl_noise;
uniform float amb_correction;
uniform float dirt_r_factor;
uniform float dirt_g_factor;
uniform float dirt_b_factor;
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 vec4 fg_SunAmbientColor;
///fog include//////////////////////
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
////////////////////////////////////
void main (void)
{
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * nmap_tile);
vec4 reflmap = texture2D(ReflMapTex, gl_TexCoord[0].st);
vec4 noisevec = texture3D(ReflNoiseTex, rawpos.xyz);
vec4 lightmapTexel = texture2D(LightMapTex, gl_TexCoord[0].st);
vec3 mixedcolor;
vec3 ambient = vec3(0.85,0.85,0.9);//placeholder for sun ambient
//vec3 ambient = fg_SunAmbientColor.rgb;
vec3 N;
vec3 dotN;
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb, vec3( 0.3, 0.59, 0.11 ) );
float pf;
///BEGIN bump
if (nmap_enabled > 0 && shader_qual > 2){
N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (nmap_dds > 0)
N = -N;
} else {
N = normalize(VNormal);
}
vec2 eyeN = (N.xy + vec2(1.0,1.0))*0.5;
///END bump
vec4 reflection = textureCube(Environment, reflVec * N);
vec3 viewVec = normalize(vViewVec);
float v = dot(viewVec, normalize(VNormal));// Map a rainbowish color
vec4 fresnel = texture2D(ReflFresnelTex, vec2(v, 0.0));
vec4 rainbow = texture2D(ReflRainbowTex, vec2(v, 0.0));
vec4 color = gl_Color + gl_FrontMaterial.diffuse;
float specular = dot((gl_FrontMaterial.specular * nmap.a).rgb, vec3( 0.3, 0.59, 0.11 ));
////////////////////////////////////////////////////////////////////
//BEGIN reflect
////////////////////////////////////////////////////////////////////
if (refl_enabled > 0 && shader_qual > 1){
float reflFactor;
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
reflFactor = reflmap.a + transparency_offset;
} else if (nmap_enabled > 0) {
// set the reflectivity proportional to shininess with user input
reflFactor = (gl_FrontMaterial.shininess / 128.0) * nmap.a + transparency_offset;
} else {
reflFactor = gl_FrontMaterial.shininess/128.0 + transparency_offset;
}
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;
} else {
mixedcolor = texel.rgb;
}
/////////////////////////////////////////////////////////////////////
//END reflect
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//begin DIRT
//////////////////////////////////////////////////////////////////////
if (dirt_enabled > 0.0){
float dirtFactorR = reflmap.r * dirt_r_factor;
dirtFactorR = smoothstep(0.0, 1.0, dirtFactorR);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, dirtFactorR);
if (dirt_multi > 0) {
float dirtFactorG = reflmap.g * dirt_g_factor;
float dirtFactorB = reflmap.b * dirt_b_factor;
dirtFactorG = smoothstep(0.0, 1.0, dirtFactorG);
dirtFactorB = smoothstep(0.0, 1.0, dirtFactorB);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, dirtFactorG);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, dirtFactorB);
}
}
//////////////////////////////////////////////////////////////////////
//END Dirt
//////////////////////////////////////////////////////////////////////
// set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(amb_correction, -1.0, 1.0);
vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6) * ambient_offset;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
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);
//////////////////////////////////////////////////////////////////////
// BEGIN lightmap
//////////////////////////////////////////////////////////////////////
if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor;
if (lightmap_multi >0 ){
lightmapcolor = lightmap_r_color * lightmap_r_factor * lightmapTexel.r +
lightmap_g_color * lightmap_g_factor * lightmapTexel.g +
lightmap_b_color * lightmap_b_factor * lightmapTexel.b +
lightmap_a_color * lightmap_a_factor * lightmapTexel.a ;
} else {
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmap_r_factor;
}
fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
}
//////////////////////////////////////////////////////////////////////
// END lightmap
/////////////////////////////////////////////////////////////////////
gl_FragData[0]=vec4(eyeN, 0.0, 1.0);
gl_FragData[1]=vec4(fragColor.rgb,1.0/255.0);
gl_FragData[2]=vec4(specular, gl_FrontMaterial.shininess/255.0, emission, 1.0);
}