Experimentation with normalpacking and component precision.
This commit is contained in:
@@ -660,6 +660,10 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
|
||||
}
|
||||
}
|
||||
|
||||
static const LLCachedControl<bool> SHPackDeferredNormals("SHPackDeferredNormals",false);
|
||||
if(SHPackDeferredNormals)
|
||||
text[count++] = strdup("#define PACK_NORMALS\n");
|
||||
|
||||
//copy preprocessor definitions into buffer
|
||||
for (std::map<std::string,std::string>::iterator iter = mDefinitions.begin(); iter != mDefinitions.end(); ++iter)
|
||||
{
|
||||
|
||||
@@ -174,5 +174,27 @@
|
||||
<key>Value</key>
|
||||
<integer>0</integer>
|
||||
</map>
|
||||
<key>SHPackDeferredNormals</key>
|
||||
<map>
|
||||
<key>Comment</key>
|
||||
<string>Pack deferred normals into two components.</string>
|
||||
<key>Persist</key>
|
||||
<integer>1</integer>
|
||||
<key>Type</key>
|
||||
<string>Boolean</string>
|
||||
<key>Value</key>
|
||||
<integer>0</integer>
|
||||
</map>
|
||||
<key>SHPrecisionDeferredNormals</key>
|
||||
<map>
|
||||
<key>Comment</key>
|
||||
<string>Enable usage of RGB10A2 for the deferred normalMap format. Reduces normalmapping artifacts.</string>
|
||||
<key>Persist</key>
|
||||
<integer>1</integer>
|
||||
<key>Type</key>
|
||||
<string>Boolean</string>
|
||||
<key>Value</key>
|
||||
<integer>0</integer>
|
||||
</map>
|
||||
</map>
|
||||
</llsd>
|
||||
|
||||
@@ -34,6 +34,17 @@ uniform sampler2D diffuseMap;
|
||||
VARYING vec3 vary_normal;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diff = texture2D(diffuseMap, vary_texcoord0.xy);
|
||||
@@ -46,6 +57,6 @@ void main()
|
||||
frag_data[0] = vec4(diff.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0);
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn), 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,11 +64,25 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 tc = vary_fragcoord.xy;
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(tc); // unpack norm
|
||||
|
||||
vec3 pos = getPosition(tc).xyz;
|
||||
vec4 ccol = texture2DRect(lightMap, tc).rgba;
|
||||
|
||||
|
||||
@@ -39,6 +39,17 @@ VARYING vec3 vary_mat2;
|
||||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb;
|
||||
@@ -52,5 +63,5 @@ void main()
|
||||
frag_data[1] = vertex_color.aaaa; // spec
|
||||
//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
|
||||
vec3 nvn = normalize(tnorm);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn), 0.0);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,11 @@ void main()
|
||||
/// Gamma correct for WL (soft clip effect).
|
||||
frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1);
|
||||
frag_data[1] = vec4(0.0,0.0,0.0,0.0);
|
||||
frag_data[2] = vec4(0,0,1,0);
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
frag_data[2] = vec4(0.5,0.5,0.0,0.0);
|
||||
#else
|
||||
frag_data[2] = vec4(0.0,0.0,1.0,0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,17 @@ VARYING vec3 vary_normal;
|
||||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color;
|
||||
@@ -49,6 +60,6 @@ void main()
|
||||
frag_data[0] = vec4(col.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0); // spec
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,17 @@ uniform float minimum_alpha;
|
||||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color;
|
||||
@@ -48,5 +59,5 @@ void main()
|
||||
frag_data[0] = vec4(col.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0);
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn), 0.0);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,17 @@ uniform sampler2D diffuseMap;
|
||||
VARYING vec3 vary_normal;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture2D(diffuseMap, vary_texcoord0.xy);
|
||||
@@ -49,6 +60,6 @@ void main()
|
||||
frag_data[0] = vec4(col.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0); // spec
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,17 @@ VARYING vec3 vary_normal;
|
||||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb;
|
||||
@@ -42,6 +53,6 @@ void main()
|
||||
frag_data[1] = vertex_color.aaaa; // spec
|
||||
//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,17 @@ VARYING vec3 vary_normal;
|
||||
VARYING vec4 vertex_color;
|
||||
VARYING vec2 vary_texcoord0;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
|
||||
@@ -41,5 +52,5 @@ void main()
|
||||
frag_data[1] = vertex_color.aaaa; // spec
|
||||
//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res;
|
||||
@@ -78,9 +92,8 @@ void main()
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
norm = normalize(norm);
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
vec4 spec = texture2DRect(specularRect, frag.xy);
|
||||
vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb;
|
||||
float noise = texture2D(noiseMap, frag.xy/128.0).b;
|
||||
|
||||
@@ -125,6 +125,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = vary_fragcoord;
|
||||
@@ -141,10 +155,9 @@ void main()
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0, norm.z);
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
|
||||
norm = normalize(norm);
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
float l_dist = -dot(lv, proj_n);
|
||||
|
||||
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
|
||||
|
||||
@@ -67,6 +67,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = vary_fragcoord;
|
||||
@@ -83,15 +97,14 @@ void main()
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
float da = dot(norm, lv);
|
||||
if (da < 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
norm = normalize(norm);
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
lv = normalize(lv);
|
||||
da = dot(norm, lv);
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ void main()
|
||||
/// Gamma correct for WL (soft clip effect).
|
||||
frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0);
|
||||
frag_data[1] = vec4(0.0,0.0,0.0,0.0);
|
||||
frag_data[2] = vec4(0,0,1,0);
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
frag_data[2] = vec4(0.5,0.5,0.0,0.0);
|
||||
#else
|
||||
frag_data[2] = vec4(0.0,0.0,1.0,0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -271,13 +271,26 @@ vec3 scaleSoftClip(vec3 light)
|
||||
return light;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 tc = vary_fragcoord.xy;
|
||||
float depth = texture2DRect(depthMap, tc.xy).r;
|
||||
vec3 pos = getPosition_d(tc, depth).xyz;
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(tc); // unpack norm
|
||||
|
||||
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
|
||||
|
||||
|
||||
@@ -127,6 +127,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = vary_fragcoord;
|
||||
@@ -143,10 +157,9 @@ void main()
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0, norm.z);
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
|
||||
norm = normalize(norm);
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
float l_dist = -dot(lv, proj_n);
|
||||
|
||||
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
|
||||
|
||||
@@ -40,5 +40,10 @@ void main()
|
||||
|
||||
frag_data[0] = col;
|
||||
frag_data[1] = vec4(0,0,0,0);
|
||||
frag_data[2] = vec4(0,0,1,0);
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
frag_data[2] = vec4(0.5,0.5,0.0,0.0);
|
||||
#else
|
||||
frag_data[2] = vec4(0.0,0.0,1.0,0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -114,6 +114,19 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm)
|
||||
return min(ret, 1.0);
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
void main()
|
||||
{
|
||||
vec2 pos_screen = vary_fragcoord.xy;
|
||||
@@ -122,8 +135,7 @@ void main()
|
||||
|
||||
vec4 pos = getPosition(pos_screen);
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, pos_screen).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(pos_screen); // unpack norm
|
||||
|
||||
frag_color[0] = 1.0;
|
||||
frag_color[1] = calcAmbientOcclusion(pos, norm);
|
||||
|
||||
@@ -39,6 +39,17 @@ VARYING vec3 vary_normal;
|
||||
VARYING vec4 vary_texcoord0;
|
||||
VARYING vec4 vary_texcoord1;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
/// Note: This should duplicate the blending functionality currently used for the terrain rendering.
|
||||
@@ -56,6 +67,6 @@ void main()
|
||||
frag_data[0] = vec4(outColor.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0);
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,17 @@ VARYING vec2 vary_texcoord0;
|
||||
|
||||
uniform float minimum_alpha;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture2D(diffuseMap, vary_texcoord0.xy);
|
||||
@@ -48,5 +59,5 @@ void main()
|
||||
frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);
|
||||
frag_data[1] = vec4(0,0,0,0);
|
||||
vec3 nvn = normalize(vary_normal);
|
||||
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
|
||||
frag_data[2] = vec4(pack(nvn),0.0);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,17 @@ VARYING vec4 littleWave;
|
||||
VARYING vec4 view;
|
||||
VARYING vec4 vary_position;
|
||||
|
||||
vec3 pack(vec3 norm)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
float p = sqrt(8.0*norm.z+8.0);
|
||||
return vec3(norm.xy/p + 0.5, 0.0);
|
||||
#else
|
||||
return norm.xyz*0.5+0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
@@ -161,5 +172,5 @@ void main()
|
||||
|
||||
frag_data[0] = vec4(color.rgb, 0.5); // diffuse
|
||||
frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec
|
||||
frag_data[2] = vec4(screenspacewavef.xy*0.5+0.5, screenspacewavef.z, screenspacewavef.z*0.5); // normalxyz, displace
|
||||
frag_data[2] = vec4(pack(screenspacewavef), 0.5);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = vary_fragcoord;
|
||||
@@ -153,10 +167,9 @@ void main()
|
||||
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
|
||||
norm = normalize(norm);
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
float l_dist = -dot(lv, proj_n);
|
||||
|
||||
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
|
||||
|
||||
@@ -273,13 +273,26 @@ vec3 scaleSoftClip(vec3 light)
|
||||
return light;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 tc = vary_fragcoord.xy;
|
||||
float depth = texture2DRect(depthMap, tc.xy).r;
|
||||
vec3 pos = getPosition_d(tc, depth).xyz;
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(tc); // unpack norm
|
||||
|
||||
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
|
||||
|
||||
|
||||
@@ -126,6 +126,20 @@ vec4 getPosition(vec2 pos_screen)
|
||||
return pos;
|
||||
}
|
||||
|
||||
vec3 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec2 enc = texture2DRect(normalMap, tc).xy;
|
||||
enc = enc*4.0-2.0;
|
||||
float prod = dot(enc,enc);
|
||||
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
|
||||
#else
|
||||
vec3 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return norm*2.0-1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = vary_fragcoord;
|
||||
@@ -153,10 +167,9 @@ void main()
|
||||
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
|
||||
}
|
||||
|
||||
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
|
||||
norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
|
||||
vec3 norm = unpack(frag.xy); // unpack norm
|
||||
|
||||
norm = normalize(norm);
|
||||
//norm = normalize(norm); // may be superfluous
|
||||
float l_dist = -dot(lv, proj_n);
|
||||
|
||||
vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
|
||||
|
||||
@@ -116,6 +116,20 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)
|
||||
return shadow*0.2;
|
||||
}
|
||||
|
||||
vec4 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec4 enc = texture2DRect(normalMap, tc).xyzw;
|
||||
enc = vec4((enc.xy*4.0)-2.0,0.0,enc.w);
|
||||
float prod = dot(enc.xy,enc.xy);
|
||||
return vec4(enc.xy*sqrt(1.0-prod*.25),1.0-prod*.5,enc.w);
|
||||
#else
|
||||
vec4 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return vec4(norm.xyz*2.0-1.0,norm.w);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos_screen = vary_fragcoord.xy;
|
||||
@@ -124,9 +138,8 @@ void main()
|
||||
|
||||
vec4 pos = getPosition(pos_screen);
|
||||
|
||||
vec4 nmap4 = texture2DRect(normalMap, pos_screen);
|
||||
nmap4 = vec4((nmap4.xy-0.5)*2.0,nmap4.z,nmap4.w); // unpack norm
|
||||
float displace = nmap4.w;
|
||||
vec4 nmap4 = unpack(pos_screen) // unpack norm
|
||||
float displace = nmap4.w*norm.z;
|
||||
vec3 norm = nmap4.xyz;
|
||||
|
||||
/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL
|
||||
|
||||
@@ -177,6 +177,20 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)
|
||||
return shadow*0.2;
|
||||
}
|
||||
|
||||
vec4 unpack(vec2 tc)
|
||||
{
|
||||
//#define PACK_NORMALS
|
||||
#ifdef PACK_NORMALS
|
||||
vec4 enc = texture2DRect(normalMap, tc).xyzw;
|
||||
enc = vec4((enc.xy*4.0)-2.0,0.0,enc.w);
|
||||
float prod = dot(enc.xy,enc.xy);
|
||||
return vec4(enc.xy*sqrt(1.0-prod*.25),1.0-prod*.5,enc.w);
|
||||
#else
|
||||
vec4 norm = texture2DRect(normalMap, tc).xyz;
|
||||
return vec4(norm.xyz*2.0-1.0,norm.w);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos_screen = vary_fragcoord.xy;
|
||||
@@ -185,9 +199,8 @@ void main()
|
||||
|
||||
vec4 pos = getPosition(pos_screen);
|
||||
|
||||
vec4 nmap4 = texture2DRect(normalMap, pos_screen);
|
||||
nmap4 = vec4((nmap4.xy-0.5)*2.0,nmap4.z,nmap4.w); // unpack norm
|
||||
float displace = nmap4.w;
|
||||
vec4 nmap4 = unpack(pos_screen); // unpack norm
|
||||
float displace = nmap4.w*norm.z;
|
||||
vec3 norm = nmap4.xyz;
|
||||
|
||||
/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL
|
||||
|
||||
@@ -340,8 +340,9 @@ void validate_framebuffer_object();
|
||||
|
||||
bool addDeferredAttachments(LLRenderTarget& target)
|
||||
{
|
||||
static const LLCachedControl<bool> SHPrecisionDeferredNormals("SHPrecisionDeferredNormals",false);
|
||||
return target.addColorAttachment(GL_RGBA) && //specular
|
||||
target.addColorAttachment(GL_RGBA); //normal+z
|
||||
target.addColorAttachment(SHPrecisionDeferredNormals ? GL_RGB10_A2 : GL_RGBA); //normal+z
|
||||
}
|
||||
|
||||
LLPipeline::LLPipeline() :
|
||||
|
||||
Reference in New Issue
Block a user