Ubershader: some spring cleaning, readability
Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
parent
337aeb7fe4
commit
5fbc5bddf6
3 changed files with 54 additions and 45 deletions
|
@ -76,7 +76,8 @@ void main (void)
|
|||
//vec3 ambient = fg_SunAmbientColor.rgb;
|
||||
vec3 N;
|
||||
vec3 dotN;
|
||||
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission , vec3( 0.3, 0.59, 0.11 ) );
|
||||
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission,
|
||||
vec3( 0.3, 0.59, 0.11 ) );
|
||||
float pf;
|
||||
|
||||
///BEGIN bump
|
||||
|
@ -108,9 +109,9 @@ void main (void)
|
|||
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;
|
||||
reflFactor = gl_FrontMaterial.shininess * 0.0078125 * nmap.a + transparency_offset;
|
||||
} else {
|
||||
reflFactor = gl_FrontMaterial.shininess/128.0 + transparency_offset;
|
||||
reflFactor = gl_FrontMaterial.shininess * 0.0078125 + transparency_offset;
|
||||
}
|
||||
reflFactor = clamp(reflFactor, 0.0, 1.0);
|
||||
|
||||
|
@ -131,16 +132,15 @@ void main (void)
|
|||
//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);
|
||||
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
|
||||
vec3 dirtFactor.rgb = 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) {
|
||||
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);
|
||||
//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));
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -162,19 +162,23 @@ void main (void)
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
if ( lightmap_enabled >= 1 ) {
|
||||
vec3 lightmapcolor;
|
||||
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, lightmap_b_factor, lightmap_a_factor);
|
||||
lightmapFactor = lightmapFactor * lightmapTexel;
|
||||
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 ;
|
||||
emission = max(max(lightmap_r_factor * lightmapTexel.r, lightmap_g_factor * lightmapTexel.g),max( lightmap_b_factor * lightmapTexel.b, lightmap_a_factor * lightmapTexel.a));
|
||||
lightmapcolor = lightmap_r_color * lightmapFactor.r +
|
||||
lightmap_g_color * lightmapFactor.g +
|
||||
lightmap_b_color * lightmapFactor.b +
|
||||
lightmap_a_color * lightmapFactor.a ;
|
||||
emission = max(max(lightmapFactor.r * lightmapTexel.r, lightmapFactor.g * lightmapTexel.g),
|
||||
max( lightmapFactor.b * lightmapTexel.b, lightmapFactor.a * lightmapTexel.a));
|
||||
} else {
|
||||
lightmapcolor = lightmapTexel.r * lightmap_r_color * lightmap_r_factor;
|
||||
emission = lightmapTexel.r * lightmap_r_factor;
|
||||
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
|
||||
emission = lightmapTexel.r * lightmapFactor.r;
|
||||
}
|
||||
//fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
|
||||
emission = length(lightmapcolor);
|
||||
fragColor.rgb = max(fragColor.rgb * (1.0 - emission), lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
|
||||
fragColor.rgb = max(fragColor.rgb * (1.0 - emission),
|
||||
lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// END lightmap
|
||||
|
|
|
@ -92,7 +92,8 @@ void main (void)
|
|||
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) {
|
||||
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)));
|
||||
}
|
||||
|
@ -122,9 +123,9 @@ void main (void)
|
|||
reflFactor = reflmap.a + transparency_offset;
|
||||
} else if (nmap_enabled > 0 && shader_qual > 2) {
|
||||
// set the reflectivity proportional to shininess with user input
|
||||
reflFactor = (gl_FrontMaterial.shininess / 128.0) * nmap.a + transparency_offset;
|
||||
reflFactor = gl_FrontMaterial.shininess * 0.0078125 * nmap.a + transparency_offset;
|
||||
} else {
|
||||
reflFactor = gl_FrontMaterial.shininess/128.0 + transparency_offset;
|
||||
reflFactor = gl_FrontMaterial.shininess* 0.0078125 + transparency_offset;
|
||||
}
|
||||
reflFactor = clamp(reflFactor, 0.0, 1.0);
|
||||
|
||||
|
@ -148,16 +149,15 @@ void main (void)
|
|||
//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);
|
||||
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) {
|
||||
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);
|
||||
//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));
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -167,7 +167,8 @@ void main (void)
|
|||
|
||||
// set ambient adjustment to remove bluiness with user input
|
||||
float ambient_offset = clamp(amb_correction, -1.0, 1.0);
|
||||
vec4 ambient_Correction = vec4(gl_LightSource[0].ambient.rg, gl_LightSource[0].ambient.b * 0.6, 0.5) * ambient_offset ;
|
||||
vec4 ambient_Correction = vec4(gl_LightSource[0].ambient.rg, gl_LightSource[0].ambient.b * 0.6, 0.5)
|
||||
* ambient_offset ;
|
||||
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
|
||||
|
||||
color.a = texel.a * alpha;
|
||||
|
@ -182,13 +183,16 @@ void main (void)
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
if ( lightmap_enabled >= 1 ) {
|
||||
vec3 lightmapcolor;
|
||||
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor,
|
||||
lightmap_b_factor, lightmap_a_factor);
|
||||
lightmapFactor = lightmapFactor * lightmapTexel;
|
||||
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 ;
|
||||
lightmapcolor = lightmap_r_color * lightmapFactor.r +
|
||||
lightmap_g_color * lightmapFactor.g +
|
||||
lightmap_b_color * lightmapFactor.b +
|
||||
lightmap_a_color * lightmapFactor.a ;
|
||||
} else {
|
||||
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmap_r_factor;
|
||||
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
|
||||
}
|
||||
fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ uniform int rembrandt_enabled;
|
|||
|
||||
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,
|
||||
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 );
|
||||
|
@ -39,7 +39,7 @@ void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float c
|
|||
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,
|
||||
sinRz, cosRz, 0.0, 0.0,
|
||||
0.0 , 0.0 , 1.0, 0.0,
|
||||
0.0 , 0.0 , 0.0, 1.0 );
|
||||
}
|
||||
|
@ -103,7 +103,8 @@ void main(void)
|
|||
}
|
||||
|
||||
if(rembrandt_enabled < 1){
|
||||
gl_FrontColor = gl_FrontMaterial.emission + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||
gl_FrontColor = gl_FrontMaterial.emission + gl_Color
|
||||
* (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||
} else {
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue