summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llrender/llgl.cpp6
-rw-r--r--indra/llrender/llshadermgr.cpp2
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl117
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl104
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl32
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl162
6 files changed, 117 insertions, 306 deletions
diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index 1725990e8f..72d9c14ccf 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -86,9 +86,9 @@ void APIENTRY gl_debug_callback(GLenum source,
const GLchar* message,
GLvoid* userParam)
{
- if (severity != GL_DEBUG_SEVERITY_HIGH &&
- severity != GL_DEBUG_SEVERITY_MEDIUM &&
- severity != GL_DEBUG_SEVERITY_LOW
+ if (severity != GL_DEBUG_SEVERITY_HIGH //&&
+ //severity != GL_DEBUG_SEVERITY_MEDIUM &&
+ //severity != GL_DEBUG_SEVERITY_LOW
)
{ //suppress out-of-spec messages sent by nvidia driver (mostly vertexbuffer hints)
return;
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 44b8ea164b..6001b011ee 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -262,7 +262,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
}
}
- if (features->hasGamma)
+ if (features->hasGamma || features->isDeferred)
{
if (!shader->attachFragmentObject("windlight/gammaF.glsl"))
{
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
index 6763e2de7b..8fdb5e7154 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
@@ -23,124 +23,11 @@
* $/LicenseInfo$
*/
-#extension GL_ARB_texture_rectangle : enable
+ // debug stub
-/*[EXTRA_CODE_HERE]*/
-
-#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
-#else
-#define frag_color gl_FragColor
-#endif
-
-uniform sampler2D depthMap;
-uniform sampler2D diffuseRect;
-uniform sampler2D specularRect;
-uniform sampler2D noiseMap;
-uniform sampler2D lightFunc;
-
-uniform vec3 env_mat[3];
-uniform float sun_wash;
-uniform int light_count;
-uniform vec4 light[LIGHT_COUNT];
-uniform vec4 light_col[LIGHT_COUNT];
-
-uniform vec2 screen_res;
-uniform float far_z;
-uniform mat4 inv_proj;
-
-VARYING vec4 vary_fragcoord;
-
-vec4 getPosition(vec2 pos_screen);
-vec3 getNorm(vec2 pos_screen);
-vec3 srgb_to_linear(vec3 c);
-float getDepth(vec2 tc);
-vec2 getScreenCoord(vec4 clip);
void main()
{
-#if defined(LOCAL_LIGHT_KILL)
- discard; // Bail immediately
-#endif
-
- vec3 out_col = vec3(0, 0, 0);
- vec2 frag = getScreenCoord(vary_fragcoord);
- vec3 pos = getPosition(frag.xy).xyz;
- if (pos.z < far_z)
- {
- discard;
- }
-
- vec3 norm = getNorm(frag.xy);
-
- vec4 spec = texture2D(specularRect, frag.xy);
- vec3 diff = texture2D(diffuseRect, frag.xy).rgb;
-
- float noise = texture2D(noiseMap, frag.xy).b;
- vec3 npos = normalize(-pos);
-
- // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop
- for (int i = 0; i < LIGHT_COUNT; ++i)
- {
- vec3 lv = light[i].xyz - pos;
- float dist = length(lv);
- dist /= light[i].w;
- if (dist <= 1.0)
- {
- float da = dot(norm, lv);
- if (da > 0.0)
- {
- lv = normalize(lv);
- da = dot(norm, lv);
-
- float fa = light_col[i].a + 1.0;
- float dist_atten = clamp(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 0.0, 1.0);
- dist_atten *= dist_atten;
-
- // Tweak falloff slightly to match pre-EEP attenuation
- // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit
- dist_atten *= 2.0;
-
- dist_atten *= noise;
-
- float lit = da * dist_atten;
-
- vec3 col = light_col[i].rgb * lit * diff;
-
- if (spec.a > 0.0)
- {
- lit = min(da * 6.0, 1.0) * dist_atten;
- vec3 h = normalize(lv + npos);
- float nh = dot(norm, h);
- float nv = dot(norm, npos);
- float vh = dot(npos, h);
- float sa = nh;
- float fres = pow(1 - dot(h, npos), 5) * 0.4 + 0.5;
-
- float gtdenom = 2 * nh;
- float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-
- if (nh > 0.0)
- {
- float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * da);
- col += lit * scol * light_col[i].rgb * spec.rgb;
- }
- }
-
- out_col += col;
- }
- }
- }
-
- frag_color.rgb = out_col;
- 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
+ frag_color = vec4(0.5, 0.5, 0.0, 0.0);
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
index f07ef92b26..a025c4a1b4 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
@@ -22,111 +22,11 @@
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
-#extension GL_ARB_texture_rectangle : enable
-/*[EXTRA_CODE_HERE]*/
-
-#ifdef DEFINE_GL_FRAGCOLOR
+// debug stub
out vec4 frag_color;
-#else
-#define frag_color gl_FragColor
-#endif
-
-uniform sampler2D diffuseRect;
-uniform sampler2D specularRect;
-uniform sampler2D normalMap;
-uniform sampler2D noiseMap;
-uniform sampler2D lightFunc;
-uniform sampler2D depthMap;
-
-uniform vec3 env_mat[3];
-uniform float sun_wash;
-
-uniform vec3 color;
-uniform float falloff;
-uniform float size;
-
-VARYING vec4 vary_fragcoord;
-VARYING vec3 trans_center;
-
-uniform vec2 screen_res;
-
-uniform mat4 inv_proj;
-uniform vec4 viewport;
-
-vec3 getNorm(vec2 pos_screen);
-vec4 getPosition(vec2 pos_screen);
-float getDepth(vec2 pos);
-vec3 srgb_to_linear(vec3 c);
void main()
{
- vec4 frag = vary_fragcoord;
- frag.xyz /= frag.w;
- frag.xyz = frag.xyz*0.5+0.5;
-
- vec3 pos = getPosition(frag.xy).xyz;
- vec3 lv = trans_center.xyz-pos;
- float dist = length(lv);
- dist /= size;
- if (dist > 1.0)
- {
- discard;
- }
-
- vec3 norm = getNorm(frag.xy);
-
- float da = dot(norm, lv);
- if (da < 0.0)
- {
- discard;
- }
-
- lv = normalize(lv);
- da = dot(norm, lv);
-
- float noise = texture2D(noiseMap, frag.xy).b;
-
- vec3 col = texture2D(diffuseRect, frag.xy).rgb;
-
- float fa = falloff+1.0;
- float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
- dist_atten *= dist_atten;
- dist_atten *= 2.0;
-
- float lit = da * dist_atten * noise;
-
- col = color.rgb*lit*col;
-
- vec4 spec = texture2D(specularRect, frag.xy);
- if (spec.a > 0.0)
- {
- lit = min(da*6.0, 1.0) * dist_atten;
-
- vec3 npos = -normalize(pos);
- vec3 h = normalize(lv+npos);
- float nh = dot(norm, h);
- float nv = dot(norm, npos);
- float vh = dot(npos, h);
- float sa = nh;
- float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5;
- float gtdenom = 2 * nh;
- float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh)));
-
- if (nh > 0.0)
- {
- float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
- col += lit*scol*color.rgb*spec.rgb;
- }
- }
-
- if (dot(col, col) <= 0.0)
- {
- discard;
- }
- final_color.rgb = vec3(getDepth(frag.xy));
-
- frag_color.rgb = col;
- frag_color.a = 0.0;
+ frag_color = vec4(0.0, 0.5, 0.5, 0.0);
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl
index d48aeb98b6..4813e6c2d9 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl
@@ -58,8 +58,12 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth);
vec4 getPosition(vec2 pos_screen);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity);
bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame);
+
float random (vec2 uv);
-void main() {
+
+
+void main()
+{
vec2 tc = vary_fragcoord.xy;
float depth = linearDepth01(getDepth(tc), zNear, zFar);
vec3 n = vec3(0, 0, 1);
@@ -74,7 +78,8 @@ void main() {
vec4 diffuse = texture2D(diffuseRect, tc);
vec3 specCol = spec.rgb;
- if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) {
+ if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
+ {
vec3 orm = specCol.rgb;
float perceptualRoughness = orm.g;
float metallic = orm.b;
@@ -86,12 +91,12 @@ void main() {
specCol = mix(f0, baseColor.rgb, metallic);
}
- vec2 uv2 = tc * screen_res;
- float c = (uv2.x + uv2.y) * 0.125;
- float jitter = mod( c, 1.0);
+ vec2 uv2 = tc * screen_res;
+ float c = (uv2.x + uv2.y) * 0.125;
+ float jitter = mod( c, 1.0);
vec3 firstBasis = normalize(cross(vec3(1.f, 1.f, 1.f), rayDirection));
- vec3 secondBasis = normalize(cross(rayDirection, firstBasis));
+ vec3 secondBasis = normalize(cross(rayDirection, firstBasis));
frag_color = texture(diffuseMap, tc);
vec4 collectedColor;
@@ -100,17 +105,22 @@ void main() {
float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1);
vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1);
vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1);
+
int totalSamples = 4;
- for (int i = 0; i < totalSamples; i++) {
- vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0)));
- vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y;
+
+ for (int i = 0; i < totalSamples; i++)
+ {
+ vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0)));
+ vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y;
bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseMap);
- if (hit) {
+
+ if (hit)
+ {
collectedColor += hitpoint;
collectedColor.rgb *= specCol.rgb;
}
- }
+ }
collectedColor *= vignette;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl
index f8c6e5701a..b6c789ad40 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl
@@ -37,17 +37,19 @@ float linearDepth(float depth, float near, float far);
float getDepth(vec2 pos_screen);
float linearDepth01(float d, float znear, float zfar);
-float random (vec2 uv) {
- return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function
+float random (vec2 uv)
+{
+ return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function
}
// Based off of https://github.com/RoundedGlint585/ScreenSpaceReflection/
// A few tweaks here and there to suit our needs.
-vec2 generateProjectedPosition(vec3 pos){
- vec4 samplePosition = projection_matrix * vec4(pos, 1.f);
- samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5;
- return samplePosition.xy;
+vec2 generateProjectedPosition(vec3 pos)
+{
+ vec4 samplePosition = projection_matrix * vec4(pos, 1.f);
+ samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5;
+ return samplePosition.xy;
}
bool isBinarySearchEnabled = true;
@@ -60,79 +62,91 @@ float distanceBias = 0.02;
float depthRejectBias = 0.001;
float epsilon = 0.1;
-bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) {
- vec3 step = rayStep * reflection;
- vec3 marchingPosition = position + step;
- float delta;
- float depthFromScreen;
- vec2 screenPosition;
+bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame)
+{
+ vec3 step = rayStep * reflection;
+ vec3 marchingPosition = position + step;
+ float delta;
+ float depthFromScreen;
+ vec2 screenPosition;
bool hit = false;
hitColor = vec4(0);
-
- int i = 0;
- if (depth > depthRejectBias) {
- for (; i < iterationCount && !hit; i++) {
- screenPosition = generateProjectedPosition(marchingPosition);
- depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar);
- delta = abs(marchingPosition.z) - depthFromScreen;
-
- if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) {
- break;
- }
+
+ int i = 0;
+ if (depth > depthRejectBias)
+ {
+ for (; i < iterationCount && !hit; i++)
+ {
+ screenPosition = generateProjectedPosition(marchingPosition);
+ depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar);
+ delta = abs(marchingPosition.z) - depthFromScreen;
+
+ if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon)
+ {
+ break;
+ }
- if (abs(delta) < distanceBias) {
- vec4 color = vec4(1);
- if(debugDraw)
- color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0);
- hitColor = texture(textureFrame, screenPosition) * color;
- hitDepth = depthFromScreen;
- hit = true;
- break;
- }
- if (isBinarySearchEnabled && delta > 0) {
- break;
- }
- if (isAdaptiveStepEnabled){
- float directionSign = sign(abs(marchingPosition.z) - depthFromScreen);
- //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging
- //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement
- step = step * (1.0 - rayStep * max(directionSign, 0.0));
- marchingPosition += step * (-directionSign);
- }
- else {
- marchingPosition += step;
- }
+ if (abs(delta) < distanceBias)
+ {
+ vec4 color = vec4(1);
+ if(debugDraw)
+ color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0);
+ hitColor = texture(textureFrame, screenPosition) * color;
+ hitDepth = depthFromScreen;
+ hit = true;
+ break;
+ }
+ if (isBinarySearchEnabled && delta > 0)
+ {
+ break;
+ }
+ if (isAdaptiveStepEnabled)
+ {
+ float directionSign = sign(abs(marchingPosition.z) - depthFromScreen);
+ //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging
+ //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement
+ step = step * (1.0 - rayStep * max(directionSign, 0.0));
+ marchingPosition += step * (-directionSign);
+ }
+ else
+ {
+ marchingPosition += step;
+ }
- if (isExponentialStepEnabled){
- step *= 1.05;
- }
- }
- if(isBinarySearchEnabled){
- for(; i < iterationCount && !hit; i++){
-
- step *= 0.5;
- marchingPosition = marchingPosition - step * sign(delta);
-
- screenPosition = generateProjectedPosition(marchingPosition);
- depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar);
- delta = abs(marchingPosition.z) - depthFromScreen;
+ if (isExponentialStepEnabled)
+ {
+ step *= 1.05;
+ }
+ }
+ if(isBinarySearchEnabled)
+ {
+ for(; i < iterationCount && !hit; i++)
+ {
+ step *= 0.5;
+ marchingPosition = marchingPosition - step * sign(delta);
+
+ screenPosition = generateProjectedPosition(marchingPosition);
+ depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar);
+ delta = abs(marchingPosition.z) - depthFromScreen;
- if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) {
- break;
- }
+ if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon)
+ {
+ break;
+ }
- if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) {
- vec4 color = vec4(1);
- if(debugDraw)
- color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0);
- hitColor = texture(textureFrame, screenPosition) * color;
- hitDepth = depthFromScreen;
- hit = true;
- break;
- }
- }
- }
- }
-
+ if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias))
+ {
+ vec4 color = vec4(1);
+ if(debugDraw)
+ color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0);
+ hitColor = texture(textureFrame, screenPosition) * color;
+ hitDepth = depthFromScreen;
+ hit = true;
+ break;
+ }
+ }
+ }
+ }
+
return hit;
}