Merge a bunch of rendering fixes from Drake Arconis (Alchemy Viewer)
commit
fc9874f00d
|
|
@ -452,9 +452,11 @@ vec3 fullbrightScaleSoftClip(vec3 light)
|
|||
|
||||
void main()
|
||||
{
|
||||
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
|
||||
frag *= screen_res;
|
||||
|
||||
// <FS> Fix impostors failing to render with alpha correctly
|
||||
//vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
|
||||
//frag *= screen_res;
|
||||
// </FS>
|
||||
|
||||
vec4 pos = vec4(vary_position, 1.0);
|
||||
|
||||
float shadow = 1.0;
|
||||
|
|
@ -532,10 +534,12 @@ void main()
|
|||
vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy);
|
||||
#endif
|
||||
|
||||
#ifdef FOR_IMPOSTOR
|
||||
vec4 color;
|
||||
color.rgb = diff.rgb;
|
||||
color.a = 1.0;
|
||||
// <FS> Fix impostors failing to render with alpha correctly
|
||||
//#ifdef FOR_IMPOSTOR
|
||||
// vec4 color;
|
||||
// color.rgb = diff.rgb;
|
||||
// color.a = 1.0;
|
||||
// </FS>
|
||||
|
||||
#ifdef USE_VERTEX_COLOR
|
||||
float final_alpha = diff.a * vertex_color.a;
|
||||
|
|
@ -543,6 +547,10 @@ void main()
|
|||
#else
|
||||
float final_alpha = diff.a;
|
||||
#endif
|
||||
// <FS> Fix impostors failing to render with alpha correctly
|
||||
#ifdef FOR_IMPOSTOR
|
||||
vec4 color = vec4(diff.rgb,final_alpha);
|
||||
// </FS>
|
||||
|
||||
// Insure we don't pollute depth with invis pixels in impostor rendering
|
||||
//
|
||||
|
|
@ -551,14 +559,15 @@ void main()
|
|||
discard;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef USE_VERTEX_COLOR
|
||||
float final_alpha = diff.a * vertex_color.a;
|
||||
diff.rgb *= vertex_color.rgb;
|
||||
#else
|
||||
float final_alpha = diff.a;
|
||||
#endif
|
||||
|
||||
// <FS> Fix impostors failing to render with alpha correctly
|
||||
//#ifdef USE_VERTEX_COLOR
|
||||
// float final_alpha = diff.a * vertex_color.a;
|
||||
// diff.rgb *= vertex_color.rgb;
|
||||
//#else
|
||||
// float final_alpha = diff.a;
|
||||
//#endif
|
||||
// </FS>
|
||||
|
||||
vec4 gamma_diff = diff;
|
||||
diff.rgb = srgb_to_linear(diff.rgb);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ uniform mat4 projection_matrix;
|
|||
ATTRIBUTE vec3 position;
|
||||
ATTRIBUTE vec3 normal;
|
||||
ATTRIBUTE vec2 texcoord0;
|
||||
ATTRIBUTE vec4 clothing;
|
||||
|
||||
mat4 getSkinnedTransform();
|
||||
|
||||
|
|
@ -36,6 +37,15 @@ ATTRIBUTE vec4 weight;
|
|||
VARYING vec3 vary_normal;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
// <FS> Fix avatar cloth failing to work in deferred
|
||||
uniform vec4 gWindDir;
|
||||
uniform vec4 gSinWaveParams;
|
||||
uniform vec4 gGravity;
|
||||
|
||||
const vec4 gMinMaxConstants = vec4(1.0, 0.166666, 0.0083143, .00018542); // #minimax-generated coefficients
|
||||
const vec4 gPiConstants = vec4(0.159154943, 6.28318530, 3.141592653, 1.5707963); // # {1/2PI, 2PI, PI, PI/2}
|
||||
// </FS>
|
||||
|
||||
void main()
|
||||
{
|
||||
vary_texcoord0 = texcoord0;
|
||||
|
|
@ -45,16 +55,86 @@ void main()
|
|||
|
||||
vec4 pos_in = vec4(position.xyz, 1.0);
|
||||
mat4 trans = getSkinnedTransform();
|
||||
pos.x = dot(trans[0], pos_in);
|
||||
pos.y = dot(trans[1], pos_in);
|
||||
pos.z = dot(trans[2], pos_in);
|
||||
pos.w = 1.0;
|
||||
// <FS> Fix avatar cloth failing to work in deferred
|
||||
//pos.x = dot(trans[0], pos_in);
|
||||
//pos.y = dot(trans[1], pos_in);
|
||||
//pos.z = dot(trans[2], pos_in);
|
||||
//pos.w = 1.0;
|
||||
// </FS>
|
||||
|
||||
norm.x = dot(trans[0].xyz, normal);
|
||||
norm.y = dot(trans[1].xyz, normal);
|
||||
norm.z = dot(trans[2].xyz, normal);
|
||||
norm = normalize(norm);
|
||||
|
||||
// <FS> Fix avatar cloth failing to work in deferred
|
||||
#if AVATAR_CLOTH
|
||||
//wind
|
||||
vec4 windEffect;
|
||||
windEffect = vec4(dot(norm, gWindDir.xyz));
|
||||
pos.x = dot(trans[2], pos_in);
|
||||
windEffect.xyz = pos.x * vec3(0.015, 0.015, 0.015)
|
||||
+ windEffect.xyz;
|
||||
windEffect.w = windEffect.w * 2.0 + 1.0; // move wind offset value to [-1, 3]
|
||||
windEffect.w = windEffect.w*gWindDir.w; // modulate wind strength
|
||||
|
||||
windEffect.xyz = windEffect.xyz*gSinWaveParams.xyz
|
||||
+vec3(gSinWaveParams.w); // use sin wave params to scale and offset input
|
||||
|
||||
//reduce to period of 2 PI
|
||||
vec4 temp1, temp0, temp2, offsetPos;
|
||||
temp1.xyz = windEffect.xyz * gPiConstants.x; // change input as multiple of [0-2PI] to [0-1]
|
||||
temp0.y = mod(temp1.x,1.0);
|
||||
windEffect.x = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI]
|
||||
temp1.z = temp1.z - gPiConstants.w; // shift normal oscillation by PI/2
|
||||
temp0.y = mod(temp1.z,1.0);
|
||||
|
||||
windEffect.z = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI]
|
||||
windEffect.xyz = windEffect.xyz + vec3(-3.141592); // offset to [-PI, PI]
|
||||
|
||||
//calculate sinusoid
|
||||
vec4 sinWave;
|
||||
temp1 = windEffect*windEffect;
|
||||
sinWave = -temp1 * gMinMaxConstants.w
|
||||
+ vec4(gMinMaxConstants.z); // y = -(x^2)/7! + 1/5!
|
||||
sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.y); // y = -(x^2) * (-(x^2)/7! + 1/5!) + 1/3!
|
||||
sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.x); // y = -(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1
|
||||
sinWave = sinWave * windEffect; // y = x * (-(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1)
|
||||
|
||||
// sinWave.x holds sin(norm . wind_direction) with primary frequency
|
||||
// sinWave.y holds sin(norm . wind_direction) with secondary frequency
|
||||
// sinWave.z hold cos(norm . wind_direction) with primary frequency
|
||||
sinWave.xyz = sinWave.xyz * gWindDir.w
|
||||
+ vec3(windEffect.w); // multiply by wind strength in gWindDir.w [-wind, wind]
|
||||
|
||||
// add normal facing bias offset [-wind,wind] -> [-wind - .25, wind + 1]
|
||||
temp1 = vec4(dot(norm, gGravity.xyz)); // how much is this normal facing in direction of gGravity?
|
||||
temp1 = min(temp1, vec4(0.2,0.0,0.0,0.0)); // clamp [-1, 1] to [-1, 0.2]
|
||||
temp1 = temp1*vec4(1.5,0.0,0.0,0.0); // scale from [-1,0.2] to [-1.5, 0.3]
|
||||
sinWave.x = sinWave.x + temp1.x; // add gGravity effect to sinwave (only primary frequency)
|
||||
sinWave.xyz = sinWave.xyz * clothing.w; // modulate by clothing coverage
|
||||
|
||||
sinWave.xyz = max(sinWave.xyz, vec3(-1.0, -1.0, -1.0)); // clamp to underlying body shape
|
||||
offsetPos = clothing * sinWave.x; // multiply wind effect times clothing displacement
|
||||
temp2 = gWindDir*sinWave.z + vec4(norm,0); // calculate normal offset due to wind oscillation
|
||||
offsetPos = vec4(1.0,1.0,1.0,0.0)*offsetPos+pos_in; // add to offset vertex position, and zero out effect from w
|
||||
norm += temp2.xyz*2.0; // add sin wave effect on normals (exaggerated)
|
||||
|
||||
//renormalize normal (again)
|
||||
norm = normalize(norm);
|
||||
|
||||
pos.x = dot(trans[0], offsetPos);
|
||||
pos.y = dot(trans[1], offsetPos);
|
||||
pos.z = dot(trans[2], offsetPos);
|
||||
pos.w = 1.0;
|
||||
#else
|
||||
pos.x = dot(trans[0], pos_in);
|
||||
pos.y = dot(trans[1], pos_in);
|
||||
pos.z = dot(trans[2], pos_in);
|
||||
pos.w = 1.0;
|
||||
#endif
|
||||
// </FS>
|
||||
|
||||
vary_normal = norm;
|
||||
|
||||
gl_Position = projection_matrix * pos;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ VARYING vec3 vary_position;
|
|||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
// <FS> Fix fullbright fog failing
|
||||
vec3 fullbrightAtmosTransport(vec3 light);
|
||||
vec3 fullbrightScaleSoftClip(vec3 light);
|
||||
// </FS>
|
||||
|
||||
vec3 srgb_to_linear(vec3 cs)
|
||||
{
|
||||
|
|
@ -78,16 +82,18 @@ vec3 linear_to_srgb(vec3 cl)
|
|||
|
||||
}
|
||||
|
||||
vec3 fullbrightAtmosTransportDeferred(vec3 light)
|
||||
{
|
||||
return light;
|
||||
}
|
||||
// <FS> Fix fullbright fog failing
|
||||
//vec3 fullbrightAtmosTransportDeferred(vec3 light)
|
||||
//{
|
||||
// return light;
|
||||
//}
|
||||
|
||||
vec3 fullbrightScaleSoftClipDeferred(vec3 light)
|
||||
{
|
||||
//soft clip effect:
|
||||
return light;
|
||||
}
|
||||
//vec3 fullbrightScaleSoftClipDeferred(vec3 light)
|
||||
//{
|
||||
// //soft clip effect:
|
||||
// return light;
|
||||
//}
|
||||
// </FS>
|
||||
|
||||
#ifdef HAS_ALPHA_MASK
|
||||
uniform float minimum_alpha;
|
||||
|
|
@ -157,22 +163,32 @@ void main()
|
|||
#endif
|
||||
|
||||
color.rgb *= vertex_color.rgb;
|
||||
color.rgb = srgb_to_linear(color.rgb);
|
||||
color.rgb = fullbrightAtmosTransportDeferred(color.rgb);
|
||||
color.rgb = fullbrightScaleSoftClipDeferred(color.rgb);
|
||||
// <FS> Fix fullbright fog failing
|
||||
//color.rgb = srgb_to_linear(color.rgb);
|
||||
//color.rgb = fullbrightAtmosTransportDeferred(color.rgb);
|
||||
//color.rgb = fullbrightScaleSoftClipDeferred(color.rgb);
|
||||
|
||||
color.rgb = linear_to_srgb(color.rgb);
|
||||
//color.rgb = linear_to_srgb(color.rgb);
|
||||
color.rgb = fullbrightAtmosTransport(color.rgb);
|
||||
color.rgb = fullbrightScaleSoftClip(color.rgb);
|
||||
// </FS>
|
||||
|
||||
#ifdef WATER_FOG
|
||||
vec3 pos = vary_position;
|
||||
vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha));
|
||||
color.rgb = fogged.rgb;
|
||||
color.a = fogged.a;
|
||||
// <FS> Fix fullbright fog failing
|
||||
//vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha));
|
||||
//color.rgb = fogged.rgb;
|
||||
//color.a = fogged.a;
|
||||
color = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha));
|
||||
// </FS>
|
||||
#else
|
||||
color.a = final_alpha;
|
||||
#endif
|
||||
|
||||
frag_color.rgb = color.rgb;
|
||||
frag_color.a = color.a;
|
||||
// <FS> Fix fullbright fog failing
|
||||
//frag_color.rgb = color.rgb;
|
||||
//frag_color.a = color.a;
|
||||
frag_color = color;
|
||||
// </FS>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,10 @@ void main()
|
|||
|
||||
vec4 fb = texture2D(screenTex, distort);
|
||||
|
||||
frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse
|
||||
// <FS> Fix gamma in underwater
|
||||
//frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse
|
||||
frag_data[0] = vec4(fb.rgb, 1.0); // diffuse
|
||||
// </FS>
|
||||
frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec
|
||||
frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,10 @@ void main()
|
|||
|
||||
vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz);
|
||||
|
||||
frag_data[0] = vec4(color.rgb, color); // diffuse
|
||||
// <FS> Fix weird water glow on edge of land due to broken alpha value
|
||||
//frag_data[0] = vec4(color.rgb, color); // diffuse
|
||||
frag_data[0] = vec4(color.rgb, color.a); // diffuse
|
||||
// </FS>
|
||||
frag_data[1] = vec4(0); // speccolor, spec
|
||||
frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1882,6 +1882,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
|
|||
gDeferredAvatarProgram.mShaderFiles.clear();
|
||||
gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarV.glsl", GL_VERTEX_SHADER_ARB));
|
||||
gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarF.glsl", GL_FRAGMENT_SHADER_ARB));
|
||||
gDeferredAvatarProgram.addPermutation("AVATAR_CLOTH", (mVertexShaderLevel[SHADER_AVATAR] == 3) ? "1" : "0"); // <FS> Fix avatar cloth failing to work in deferred
|
||||
gDeferredAvatarProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED];
|
||||
success = gDeferredAvatarProgram.createShader(NULL, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue