Skip to content
Snippets Groups Projects
Commit db270df7 authored by Graham Linden's avatar Graham Linden
Browse files

Back out changes causing broken shadows and other render shenanigans.

parent 29299989
No related branches found
No related tags found
No related merge requests found
Showing
with 296 additions and 52 deletions
...@@ -186,23 +186,15 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) ...@@ -186,23 +186,15 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
} }
} }
// NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->calculatesLighting || features->calculatesAtmospherics)
if (features->isDeferred || features->hasShadows)
{
if (!shader->attachObject("deferred/deferredUtil.glsl"))
{
return FALSE;
}
}
if (features->hasIndirect)
{ {
if (!shader->attachObject("deferred/indirect.glsl")) if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl"))
{ {
return FALSE; return FALSE;
} }
} }
// NOTE order of shader object attaching is VERY IMPORTANT!!!
if (features->hasGamma) if (features->hasGamma)
{ {
if (!shader->attachObject("windlight/gammaF.glsl")) if (!shader->attachObject("windlight/gammaF.glsl"))
......
...@@ -38,5 +38,12 @@ mat4 getSkinnedTransform() ...@@ -38,5 +38,12 @@ mat4 getSkinnedTransform()
ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x); ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x);
ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x); ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x);
ret[3] = vec4(0,0,0,1); ret[3] = vec4(0,0,0,1);
return ret; return ret;
#ifdef IS_AMD_CARD
// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
vec4 dummy1 = matrixPalette[0];
vec4 dummy2 = matrixPalette[44];
#endif
} }
...@@ -61,5 +61,12 @@ mat4 getObjectSkinnedTransform() ...@@ -61,5 +61,12 @@ mat4 getObjectSkinnedTransform()
ret[3] = vec4(trans, 1.0); ret[3] = vec4(trans, 1.0);
return ret; return ret;
#ifdef IS_AMD_CARD
// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
mat3x4 dummy1 = matrixPalette[0];
mat3x4 dummy2 = matrixPalette[MAX_JOINTS_PER_MESH_OBJECT-1];
#endif
} }
...@@ -89,7 +89,9 @@ vec2 encode_normal (vec3 n); ...@@ -89,7 +89,9 @@ vec2 encode_normal (vec3 n);
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
vec3 scaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l);
vec3 atmosFragAmbient(vec3 light, vec3 sunlit);
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten);
vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit);
void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)
...@@ -162,8 +164,6 @@ void main() ...@@ -162,8 +164,6 @@ void main()
float shadow = 1.0; float shadow = 1.0;
vec3 norm = vary_norm;
#if HAS_SHADOW #if HAS_SHADOW
vec4 spos = pos; vec4 spos = pos;
...@@ -268,10 +268,13 @@ void main() ...@@ -268,10 +268,13 @@ void main()
vec4 gamma_diff = diff; vec4 gamma_diff = diff;
diff.rgb = srgb_to_linear(diff.rgb); diff.rgb = srgb_to_linear(diff.rgb);
vec3 sunlit; vec3 norm = vary_norm;
vec3 amblit;
vec3 additive; vec3 sunlit;
vec3 atten; vec3 amblit;
vec3 additive;
vec3 atten;
calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten);
vec2 abnormal = encode_normal(norm.xyz); vec2 abnormal = encode_normal(norm.xyz);
...@@ -287,7 +290,7 @@ void main() ...@@ -287,7 +290,7 @@ void main()
vec4 color = vec4(0,0,0,0); vec4 color = vec4(0,0,0,0);
color.rgb = (color.rgb * 0.5) + amblit; color.rgb = atmosFragAmbient(color.rgb, amblit);
color.a = final_alpha; color.a = final_alpha;
float ambient = abs(da); float ambient = abs(da);
...@@ -296,7 +299,7 @@ void main() ...@@ -296,7 +299,7 @@ void main()
ambient = (1.0-ambient); ambient = (1.0-ambient);
color.rgb *= ambient; color.rgb *= ambient;
color.rgb += (final_da * sunlit); color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit);
color.rgb *= gamma_diff.rgb; color.rgb *= gamma_diff.rgb;
//color.rgb = mix(diff.rgb, color.rgb, final_alpha); //color.rgb = mix(diff.rgb, color.rgb, final_alpha);
......
...@@ -73,7 +73,7 @@ void main() ...@@ -73,7 +73,7 @@ void main()
vec3 norm; vec3 norm;
//transform vertex //transform vertex
#if defined(HAS_SKIN) #ifdef HAS_SKIN
mat4 trans = getObjectSkinnedTransform(); mat4 trans = getObjectSkinnedTransform();
trans = modelview_matrix * trans; trans = modelview_matrix * trans;
...@@ -83,7 +83,9 @@ void main() ...@@ -83,7 +83,9 @@ void main()
norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz);
vec4 frag_pos = projection_matrix * pos; vec4 frag_pos = projection_matrix * pos;
gl_Position = frag_pos; gl_Position = frag_pos;
#elif defined(IS_AVATAR_SKIN) #else
#ifdef IS_AVATAR_SKIN
mat4 trans = getSkinnedTransform(); mat4 trans = getSkinnedTransform();
vec4 pos_in = vec4(position.xyz, 1.0); vec4 pos_in = vec4(position.xyz, 1.0);
pos.x = dot(trans[0], pos_in); pos.x = dot(trans[0], pos_in);
...@@ -105,11 +107,14 @@ void main() ...@@ -105,11 +107,14 @@ void main()
gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
#endif #endif
#endif
#ifdef USE_INDEXED_TEX #ifdef USE_INDEXED_TEX
passTextureIndex(); passTextureIndex();
#endif #endif
vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
vary_norm = norm; vary_norm = norm;
vary_position = pos.xyz; vary_position = pos.xyz;
...@@ -117,14 +122,18 @@ void main() ...@@ -117,14 +122,18 @@ void main()
vertex_color = diffuse_color; vertex_color = diffuse_color;
#endif #endif
#if defined(HAS_SKIN) #ifdef HAS_SKIN
vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip);
#elif defined(IS_AVATAR_SKIN) #else
#ifdef IS_AVATAR_SKIN
vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
#else #else
pos = modelview_projection_matrix * vert; pos = modelview_projection_matrix * vert;
vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
#endif #endif
#endif
} }
...@@ -33,6 +33,7 @@ out vec4 frag_color; ...@@ -33,6 +33,7 @@ out vec4 frag_color;
#define frag_color gl_FragColor #define frag_color gl_FragColor
#endif #endif
uniform sampler2DRect depthMap;
uniform sampler2DRect normalMap; uniform sampler2DRect normalMap;
uniform sampler2DRect lightMap; uniform sampler2DRect lightMap;
...@@ -44,7 +45,22 @@ uniform float kern_scale; ...@@ -44,7 +45,22 @@ uniform float kern_scale;
VARYING vec2 vary_fragcoord; VARYING vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen); uniform mat4 inv_proj;
uniform vec2 screen_res;
vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
void main() void main()
...@@ -103,5 +119,11 @@ void main() ...@@ -103,5 +119,11 @@ void main()
col.y *= col.y; col.y *= col.y;
frag_color = col; frag_color = col;
#ifdef IS_AMD_CARD
// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
vec3 dummy1 = kern[0];
vec3 dummy2 = kern[3];
#endif
} }
...@@ -32,9 +32,11 @@ out vec4 frag_data[3]; ...@@ -32,9 +32,11 @@ out vec4 frag_data[3];
#endif #endif
uniform float minimum_alpha; uniform float minimum_alpha;
uniform sampler2D diffuseMap; uniform sampler2D diffuseMap;
uniform sampler2D specularMap;
uniform sampler2D normalMap; uniform sampler2D normalMap;
uniform sampler2D specularMap;
VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord0;
......
...@@ -40,6 +40,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); ...@@ -40,6 +40,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color);
vec3 srgb_to_linear(vec3 cs); vec3 srgb_to_linear(vec3 cs);
vec3 linear_to_srgb(vec3 cl); vec3 linear_to_srgb(vec3 cl);
vec3 atmosFragAmbient(vec3 l, vec3 ambient);
vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
vec3 scaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l);
...@@ -175,6 +176,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe ...@@ -175,6 +176,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
} }
vec4 getPosition_d(vec2 pos_screen, float depth)
{
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
#else #else
#ifdef DEFINE_GL_FRAGCOLOR #ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_data[3]; out vec4 frag_data[3];
...@@ -219,8 +233,6 @@ vec3 decode_normal (vec2 enc); ...@@ -219,8 +233,6 @@ vec3 decode_normal (vec2 enc);
void main() void main()
{ {
vec2 pos_screen = vary_texcoord0.xy;
vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy);
diffcol.rgb *= vertex_color.rgb; diffcol.rgb *= vertex_color.rgb;
...@@ -378,7 +390,7 @@ void main() ...@@ -378,7 +390,7 @@ void main()
final_da = min(final_da, 1.0f); final_da = min(final_da, 1.0f);
final_da = pow(final_da, 1.0/1.3); final_da = pow(final_da, 1.0/1.3);
col.rgb = (col * 0.5) + amblit; col.rgb = atmosFragAmbient(col, amblit);
float ambient = min(abs(da), 1.0); float ambient = min(abs(da), 1.0);
ambient *= 0.5; ambient *= 0.5;
...@@ -432,6 +444,9 @@ void main() ...@@ -432,6 +444,9 @@ void main()
glare += cur_glare; glare += cur_glare;
} }
//col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
//col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
col = atmosFragLighting(col, additive, atten); col = atmosFragLighting(col, additive, atten);
col = scaleSoftClipFrag(col); col = scaleSoftClipFrag(col);
......
...@@ -59,7 +59,18 @@ uniform mat4 inv_proj; ...@@ -59,7 +59,18 @@ uniform mat4 inv_proj;
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
void main() void main()
{ {
...@@ -137,4 +148,12 @@ void main() ...@@ -137,4 +148,12 @@ void main()
frag_color.rgb = out_col; frag_color.rgb = out_col;
frag_color.a = 0.0; frag_color.a = 0.0;
#ifdef IS_AMD_CARD
// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
vec4 dummy1 = light[0];
vec4 dummy2 = light_col[0];
vec4 dummy3 = light[LIGHT_COUNT-1];
vec4 dummy4 = light_col[LIGHT_COUNT-1];
#endif
} }
...@@ -128,7 +128,19 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) ...@@ -128,7 +128,19 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
return ret; return ret;
} }
vec4 getPosition(vec2 pos_screen);
vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
void main() void main()
{ {
......
...@@ -57,7 +57,19 @@ uniform mat4 inv_proj; ...@@ -57,7 +57,19 @@ uniform mat4 inv_proj;
uniform vec4 viewport; uniform vec4 viewport;
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
vec4 getPosition(vec2 pos_screen);
vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = (pos_screen.xy-viewport.xy)*2.0;
sc /= viewport.zw;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
void main() void main()
{ {
......
/** /**
* @file pointLightV.glsl * @file pointLightF.glsl
* *
* $LicenseInfo:firstyear=2007&license=viewerlgpl$ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
......
...@@ -49,7 +49,18 @@ VARYING vec2 vary_fragcoord; ...@@ -49,7 +49,18 @@ VARYING vec2 vary_fragcoord;
uniform mat4 inv_proj; uniform mat4 inv_proj;
uniform vec2 screen_res; uniform vec2 screen_res;
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).a;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
void main() void main()
{ {
...@@ -90,4 +101,10 @@ void main() ...@@ -90,4 +101,10 @@ void main()
col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z; col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z;
frag_color.rgb = col; frag_color.rgb = col;
#ifdef IS_AMD_CARD
// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
vec2 dummy1 = kern[0];
vec2 dummy2 = kern[31];
#endif
} }
...@@ -69,17 +69,33 @@ vec3 srgb_to_linear(vec3 cs); ...@@ -69,17 +69,33 @@ vec3 srgb_to_linear(vec3 cs);
vec3 linear_to_srgb(vec3 cl); vec3 linear_to_srgb(vec3 cl);
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
vec3 scaleSoftClipFrag(vec3 l);
vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten);
vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition_d(vec2 pos_screen, float depth)
{
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
vec4 getPosition(vec2 pos_screen)
{ //get position in screen space (world units) given window coordinate and depth map
float depth = texture2DRect(depthMap, pos_screen.xy).a;
return getPosition_d(pos_screen, depth);
}
void main() void main()
{ {
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
float depth = texture2DRect(depthMap, tc.xy).r; float depth = texture2DRect(depthMap, tc.xy).r;
vec4 pos = getPositionWithDepth(tc, depth); vec3 pos = getPosition_d(tc, depth).xyz;
vec4 norm = texture2DRect(normalMap, tc); vec4 norm = texture2DRect(normalMap, tc);
float envIntensity = norm.z; float envIntensity = norm.z;
norm.xyz = decode_normal(norm.xy); // unpack norm norm.xyz = decode_normal(norm.xy); // unpack norm
...@@ -140,25 +156,27 @@ void main() ...@@ -140,25 +156,27 @@ void main()
if (envIntensity > 0.0) if (envIntensity > 0.0)
{ //add environmentmap { //add environmentmap
vec3 env_vec = env_mat * refnormpersp; vec3 env_vec = env_mat * refnormpersp;
vec3 refcol = textureCube(environmentMap, env_vec).rgb; vec3 refcol = textureCube(environmentMap, env_vec).rgb;
col = mix(col.rgb, refcol, envIntensity);
col = mix(col.rgb, refcol,
envIntensity);
} }
if (norm.w < 0.5) if (norm.w < 0.5)
{ {
col = atmosFragLighting(col, additive, atten); col = atmosFragLighting(col, additive, atten);
col = scaleSoftClipFrag(col);
} }
#ifdef WATER_FOG #ifdef WATER_FOG
vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); vec4 fogged = applyWaterFogView(pos,vec4(col, bloom));
col = fogged.rgb; col = fogged.rgb;
bloom = fogged.a; bloom = fogged.a;
#endif #endif
col = srgb_to_linear(col); col = srgb_to_linear(col);
//col = vec3(1,0,1);
//col.g = envIntensity; //col.g = envIntensity;
} }
......
...@@ -30,7 +30,6 @@ ATTRIBUTE vec3 position; ...@@ -30,7 +30,6 @@ ATTRIBUTE vec3 position;
uniform vec2 screen_res; uniform vec2 screen_res;
VARYING vec2 vary_fragcoord; VARYING vec2 vary_fragcoord;
void main() void main()
{ {
//transform vertex //transform vertex
......
...@@ -132,7 +132,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) ...@@ -132,7 +132,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
} }
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
void main() void main()
{ {
......
...@@ -48,6 +48,7 @@ vec3 srgb_to_linear(vec3 cs) ...@@ -48,6 +48,7 @@ vec3 srgb_to_linear(vec3 cs)
bvec3 lte = lessThanEqual(cs,vec3(0.04045)); bvec3 lte = lessThanEqual(cs,vec3(0.04045));
return mix(high_range, low_range, lte); return mix(high_range, low_range, lte);
} }
vec3 linear_to_srgb(vec3 cl) vec3 linear_to_srgb(vec3 cl)
...@@ -58,4 +59,6 @@ vec3 linear_to_srgb(vec3 cl) ...@@ -58,4 +59,6 @@ vec3 linear_to_srgb(vec3 cl)
bvec3 lt = lessThan(cl,vec3(0.0031308)); bvec3 lt = lessThan(cl,vec3(0.0031308));
return mix(high_range, low_range, lt); return mix(high_range, low_range, lt);
} }
...@@ -35,26 +35,102 @@ out vec4 frag_color; ...@@ -35,26 +35,102 @@ out vec4 frag_color;
//class 1 -- no shadow, SSAO only //class 1 -- no shadow, SSAO only
uniform sampler2DRect depthMap;
uniform sampler2DRect normalMap; uniform sampler2DRect normalMap;
uniform sampler2D noiseMap;
// Inputs // Inputs
uniform float ssao_radius;
uniform float ssao_max_radius;
uniform float ssao_factor;
uniform float ssao_factor_inv;
VARYING vec2 vary_fragcoord; VARYING vec2 vary_fragcoord;
uniform mat4 inv_proj;
uniform vec2 screen_res;
vec3 decode_normal (vec2 enc); vec3 decode_normal (vec2 enc);
vec3 getNorm(vec2 pos_screen);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen)
{
float depth = texture2DRect(depthMap, pos_screen.xy).r;
vec2 sc = pos_screen.xy*2.0;
sc /= screen_res;
sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc;
pos /= pos.w;
pos.w = 1.0;
return pos;
}
//calculate decreases in ambient lighting when crowded out (SSAO) //calculate decreases in ambient lighting when crowded out (SSAO)
float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); float calcAmbientOcclusion(vec4 pos, vec3 norm)
{
float ret = 1.0;
vec2 kern[8];
// exponentially (^2) distant occlusion samples spread around origin
kern[0] = vec2(-1.0, 0.0) * 0.125*0.125;
kern[1] = vec2(1.0, 0.0) * 0.250*0.250;
kern[2] = vec2(0.0, 1.0) * 0.375*0.375;
kern[3] = vec2(0.0, -1.0) * 0.500*0.500;
kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625;
kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750;
kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875;
kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000;
vec2 pos_screen = vary_fragcoord.xy;
vec3 pos_world = pos.xyz;
vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy;
float angle_hidden = 0.0;
int points = 0;
float scale = min(ssao_radius / -pos_world.z, ssao_max_radius);
// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?)
for (int i = 0; i < 8; i++)
{
vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect);
vec3 samppos_world = getPosition(samppos_screen).xyz;
vec3 diff = pos_world - samppos_world;
float dist2 = dot(diff, diff);
// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area
// --> solid angle shrinking by the square of distance
//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2
//(k should vary inversely with # of samples, but this is taken care of later)
angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv);
// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"
points = points + int(diff.z > -1.0);
}
angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0);
ret = (1.0 - (float(points != 0) * angle_hidden));
return min(ret, 1.0);
}
void main() void main()
{ {
vec2 pos_screen = vary_fragcoord.xy; vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = getPosition(pos_screen);
vec3 norm = getNorm(pos_screen); //try doing an unproject here
vec4 pos = getPosition(pos_screen);
vec3 norm = texture2DRect(normalMap, pos_screen).xyz;
norm = decode_normal(norm.xy);
frag_color[0] = 1.0; frag_color[0] = 1.0;
frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); frag_color[1] = calcAmbientOcclusion(pos, norm);
frag_color[2] = 1.0; frag_color[2] = 1.0;
frag_color[3] = 1.0; frag_color[3] = 1.0;
} }
...@@ -41,6 +41,15 @@ uniform sampler2D bumpMap2; ...@@ -41,6 +41,15 @@ uniform sampler2D bumpMap2;
uniform float blend_factor; uniform float blend_factor;
uniform sampler2D screenTex; uniform sampler2D screenTex;
uniform sampler2D refTex; uniform sampler2D refTex;
uniform sampler2DRectShadow shadowMap0;
uniform sampler2DRectShadow shadowMap1;
uniform sampler2DRectShadow shadowMap2;
uniform sampler2DRectShadow shadowMap3;
uniform sampler2D noiseMap;
uniform mat4 shadow_matrix[6];
uniform vec4 shadow_clip;
uniform float sunAngle; uniform float sunAngle;
uniform float sunAngle2; uniform float sunAngle2;
uniform vec3 lightDir; uniform vec3 lightDir;
......
...@@ -23,10 +23,21 @@ ...@@ -23,10 +23,21 @@
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
vec3 atmosFragAmbient(vec3 light, vec3 sunlit)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)
{ {
/* stub function for fallback compatibility on class1 hardware */ /* stub function for fallback compatibility on class1 hardware */
return light; return light;
}
vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit)
{
return light * sunlit;
} }
vec3 atmosLighting(vec3 light) vec3 atmosLighting(vec3 light)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment