Skip to content
Snippets Groups Projects
Commit 45496cdc authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Backport majority of shader fixes from develop

parent f80883f2
No related branches found
No related tags found
No related merge requests found
Showing
with 145 additions and 146 deletions
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuseMap;
void main() void main()
{ {
frag_color = vec4(1,1,1,1); frag_color = vec4(1,1,1,1);
......
/** /**
* @file blurLightF.glsl * @file blurLightF.glsl
* *
* $LicenseInfo:firstyear=2007&license=viewerlgpl$ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc. * Copyright (C) 2007, Linden Research, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License only. * version 2.1 of the License only.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D normalMap;
uniform sampler2D lightMap; uniform sampler2D lightMap;
uniform float dist_factor; uniform float dist_factor;
...@@ -42,16 +41,16 @@ in vec2 vary_fragcoord; ...@@ -42,16 +41,16 @@ in vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec4 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
void main() void main()
{ {
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
vec4 norm = getNorm(tc); vec4 norm = getNorm(tc);
vec3 pos = getPosition(tc).xyz; vec3 pos = getPosition(tc).xyz;
vec4 ccol = texture(lightMap, tc).rgba; vec4 ccol = texture(lightMap, tc).rgba;
vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);
dlt /= max(-pos.z*dist_factor, 1.0); dlt /= max(-pos.z*dist_factor, 1.0);
vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free'
vec4 col = defined_weight.xyxx * ccol; vec4 col = defined_weight.xyxx * ccol;
...@@ -75,15 +74,15 @@ void main() ...@@ -75,15 +74,15 @@ void main()
k[1] = (k[0]+k[2])*0.5f; k[1] = (k[0]+k[2])*0.5f;
k[3] = (k[2]+k[4])*0.5f; k[3] = (k[2]+k[4])*0.5f;
k[5] = (k[4]+k[6])*0.5f; k[5] = (k[4]+k[6])*0.5f;
for (int i = 1; i < 7; i++) for (int i = 1; i < 7; i++)
{ {
vec2 samptc = tc + k[i].z*dlt*2.0; vec2 samptc = tc + k[i].z*dlt*2.0;
samptc /= screen_res; samptc /= screen_res;
vec3 samppos = getPosition(samptc).xyz; vec3 samppos = getPosition(samptc).xyz;
float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
if (d*d <= pointplanedist_tolerance_pow2) if (d*d <= pointplanedist_tolerance_pow2)
{ {
col += texture(lightMap, samptc)*k[i].xyxx; col += texture(lightMap, samptc)*k[i].xyxx;
...@@ -95,10 +94,10 @@ void main() ...@@ -95,10 +94,10 @@ void main()
{ {
vec2 samptc = tc - k[i].z*dlt*2.0; vec2 samptc = tc - k[i].z*dlt*2.0;
samptc /= screen_res; samptc /= screen_res;
vec3 samppos = getPosition(samptc).xyz; vec3 samppos = getPosition(samptc).xyz;
float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
if (d*d <= pointplanedist_tolerance_pow2) if (d*d <= pointplanedist_tolerance_pow2)
{ {
col += texture(lightMap, samptc)*k[i].xyxx; col += texture(lightMap, samptc)*k[i].xyxx;
...@@ -108,7 +107,7 @@ void main() ...@@ -108,7 +107,7 @@ void main()
col /= defined_weight.xyxx; col /= defined_weight.xyxx;
//col.y *= col.y; //col.y *= col.y;
frag_color = max(col, vec4(0)); frag_color = max(col, vec4(0));
#ifdef IS_AMD_CARD #ifdef IS_AMD_CARD
......
...@@ -102,10 +102,13 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, ...@@ -102,10 +102,13 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v,
{ {
l = normalize(lv); l = normalize(lv);
h = normalize(l + v); h = normalize(l + v);
nh = clamp(dot(n, h), 0.0, 1.0);
nl = clamp(dot(n, l), 0.0, 1.0); // lower bound to avoid divide by zero
nv = clamp(dot(n, v), 0.0, 1.0); float eps = 0.000001;
vh = clamp(dot(v, h), 0.0, 1.0); nh = clamp(dot(n, h), eps, 1.0);
nl = clamp(dot(n, l), eps, 1.0);
nv = clamp(dot(n, v), eps, 1.0);
vh = clamp(dot(v, h), eps, 1.0);
lightDist = length(lv); lightDist = length(lv);
} }
...@@ -484,6 +487,43 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, ...@@ -484,6 +487,43 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
return clamp(color, vec3(0), vec3(10)); return clamp(color, vec3(0), vec3(10));
} }
vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness,
float metallic,
vec3 n, // normal
vec3 p, // pixel position
vec3 v, // view vector (negative normalized pixel position)
vec3 lp, // light position
vec3 ld, // light direction (for spotlights)
vec3 lightColor,
float lightSize, float falloff, float is_pointlight, float ambiance)
{
vec3 color = vec3(0,0,0);
vec3 lv = lp.xyz - p;
float lightDist = length(lv);
float dist = lightDist / lightSize;
if (dist <= 1.0)
{
lv /= lightDist;
float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
// spotlight coefficient.
float spot = max(dot(-ld, lv), is_pointlight);
// spot*spot => GL_SPOT_EXPONENT=2
float spot_atten = spot*spot;
vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials
color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv);
}
return color;
}
void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor) void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor)
{ {
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
......
...@@ -51,8 +51,6 @@ uniform vec4[2] texture_emissive_transform; ...@@ -51,8 +51,6 @@ uniform vec4[2] texture_emissive_transform;
out vec3 vary_fragcoord; out vec3 vary_fragcoord;
uniform float near_clip;
in vec3 position; in vec3 position;
in vec4 diffuse_color; in vec4 diffuse_color;
in vec3 normal; in vec3 normal;
...@@ -88,7 +86,7 @@ void main() ...@@ -88,7 +86,7 @@ void main()
#endif #endif
gl_Position = vert; gl_Position = vert;
vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); vary_fragcoord.xyz = vert.xyz;
base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0);
normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0);
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
// debug stub // debug stub
float random (vec2 uv) float random (vec2 uv)
{ {
return 0.0; return 0.f;
} }
float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness)
{ {
collectedColor = vec4(0); collectedColor = vec4(0);
return 0.0; return 0.f;
} }
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuseMap;
in vec4 post_pos; in vec4 post_pos;
in float target_pos_x; in float target_pos_x;
in vec4 vertex_color; in vec4 vertex_color;
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
*/ */
uniform sampler2D normalMap; uniform sampler2D normalMap;
uniform sampler2D depthMap;
#if defined(SUN_SHADOW) #if defined(SUN_SHADOW)
uniform sampler2DShadow shadowMap0; uniform sampler2DShadow shadowMap0;
......
/** /**
* @file class1/deferred/textureUtilV.glsl * @file class1/deferred/textureUtilV.glsl
* *
* $LicenseInfo:firstyear=2023&license=viewerlgpl$ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc. * Copyright (C) 2023, Linden Research, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License only. * version 2.1 of the License only.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
...@@ -48,6 +48,7 @@ vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offse ...@@ -48,6 +48,7 @@ vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offse
return (transform * vec3(texcoord, 1)).xy; return (transform * vec3(texcoord, 1)).xy;
} }
// A texture transform function for PBR materials applied to shape prims/Collada model prims
// vertex_texcoord - The UV texture coordinates sampled from the vertex at // vertex_texcoord - The UV texture coordinates sampled from the vertex at
// runtime. Per SL convention, this is in a right-handed UV coordinate // runtime. Per SL convention, this is in a right-handed UV coordinate
// system. Collada models also have right-handed UVs. // system. Collada models also have right-handed UVs.
...@@ -93,6 +94,8 @@ vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform) ...@@ -93,6 +94,8 @@ vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform)
// Take the rotation only from both transforms and apply to the tangent. This // Take the rotation only from both transforms and apply to the tangent. This
// accounts for the change of the topology of the normal texture when a texture // accounts for the change of the topology of the normal texture when a texture
// rotation is applied to it. // rotation is applied to it.
// In practice, this applies the inverse of the texture transform to the tangent.
// It is effectively an inverse of the rotation
// *HACK: Assume the imported GLTF model did not have both normal texture // *HACK: Assume the imported GLTF model did not have both normal texture
// transforms and tangent vertices. The use of this function is inconsistent // transforms and tangent vertices. The use of this function is inconsistent
// with the GLTF sample viewer when that is the case. See getNormalInfo in // with the GLTF sample viewer when that is the case. See getNormalInfo in
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
uniform sampler2D exposureMap;
vec3 srgb_to_linear(vec3 cs) vec3 srgb_to_linear(vec3 cs)
{ {
vec3 low_range = cs / vec3(12.92); vec3 low_range = cs / vec3(12.92);
......
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
in vec2 tc; in vec2 tc;
#if defined(COPY_DEPTH)
uniform sampler2D depthMap; uniform sampler2D depthMap;
#endif
uniform sampler2D diffuseMap; uniform sampler2D diffuseMap;
out vec4 frag_color; out vec4 frag_color;
......
...@@ -57,9 +57,9 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou ...@@ -57,9 +57,9 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
vec3 rel_pos_norm = normalize(rel_pos); vec3 rel_pos_norm = normalize(rel_pos);
float rel_pos_len = length(rel_pos); float rel_pos_len = length(rel_pos);
vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color;
// sunlight attenuation effect (hue and brightness) due to atmosphere // sunlight attenuation effect (hue and brightness) due to atmosphere
// this is used later for sunlight modulation at various altitudes // this is used later for sunlight modulation at various altitudes
vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
...@@ -119,16 +119,19 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou ...@@ -119,16 +119,19 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb);
// brightness of surface both sunlight and ambient // brightness of surface both sunlight and ambient
sunlit = sunlight.rgb; sunlit = sunlight.rgb;
amblit = tmpAmbient; amblit = tmpAmbient;
additive *= vec3(1.0 - combined_haze); additive *= vec3(1.0 - combined_haze);
// sanity clamp haze contribution
additive = min(additive, vec3(10));
} }
vec3 srgb_to_linear(vec3 col); vec3 srgb_to_linear(vec3 col);
// provide a touch of lighting in the opposite direction of the sun light // provide a touch of lighting in the opposite direction of the sun light
// so areas in shadow don't lose all detail // so areas in shadow don't lose all detail
float ambientLighting(vec3 norm, vec3 light_dir) float ambientLighting(vec3 norm, vec3 light_dir)
{ {
...@@ -150,7 +153,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou ...@@ -150,7 +153,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou
// (allows for mixing of light sources other than sunlight e.g. reflection probes) // (allows for mixing of light sources other than sunlight e.g. reflection probes)
sunlit *= sky_sunlight_scale; sunlit *= sky_sunlight_scale;
amblit *= sky_ambient_scale; amblit *= sky_ambient_scale;
amblit = srgb_to_linear(amblit); amblit = srgb_to_linear(amblit);
amblit *= ambientLighting(norm, light_dir); amblit *= ambientLighting(norm, light_dir);
} }
/** /**
* @file class1\deferred\pbralphaF.glsl * @file class1\deferred\pbralphaF.glsl
* *
* $LicenseInfo:firstyear=2022&license=viewerlgpl$ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc. * Copyright (C) 2022, Linden Research, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License only. * version 2.1 of the License only.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
...@@ -87,7 +87,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); ...@@ -87,7 +87,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
float calcLegacyDistanceAttenuation(float distance, float falloff); float calcLegacyDistanceAttenuation(float distance, float falloff);
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear);
void mirrorClip(vec3 pos); void mirrorClip(vec3 pos);
...@@ -111,15 +111,15 @@ vec3 pbrBaseLight(vec3 diffuseColor, ...@@ -111,15 +111,15 @@ vec3 pbrBaseLight(vec3 diffuseColor,
vec3 additive, vec3 additive,
vec3 atten); vec3 atten);
vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 v, // surface point to camera vec3 v, // surface point to camera
vec3 l); //surface point to light vec3 l); //surface point to light
vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 p, // pixel position vec3 p, // pixel position
...@@ -127,33 +127,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, ...@@ -127,33 +127,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
vec3 lp, // light position vec3 lp, // light position
vec3 ld, // light direction (for spotlights) vec3 ld, // light direction (for spotlights)
vec3 lightColor, vec3 lightColor,
float lightSize, float falloff, float is_pointlight, float ambiance) float lightSize, float falloff, float is_pointlight, float ambiance);
{
vec3 color = vec3(0,0,0);
vec3 lv = lp.xyz - p;
float lightDist = length(lv);
float dist = lightDist / lightSize;
if (dist <= 1.0)
{
lv /= lightDist;
float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
// spotlight coefficient.
float spot = max(dot(-ld, lv), is_pointlight);
// spot*spot => GL_SPOT_EXPONENT=2
float spot_atten = spot*spot;
vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials
color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv);
}
return color;
}
void main() void main()
{ {
...@@ -181,7 +155,7 @@ void main() ...@@ -181,7 +155,7 @@ void main()
float sign = vary_sign; float sign = vary_sign;
vec3 vN = vary_normal; vec3 vN = vary_normal;
vec3 vT = vary_tangent.xyz; vec3 vT = vary_tangent.xyz;
vec3 vB = sign * cross(vN, vT); vec3 vB = sign * cross(vN, vT);
vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
...@@ -218,7 +192,7 @@ void main() ...@@ -218,7 +192,7 @@ void main()
vec3 irradiance = vec3(0); vec3 irradiance = vec3(0);
vec3 radiance = vec3(0); vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit); sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit);
vec3 diffuseColor = vec3(0); vec3 diffuseColor = vec3(0);
vec3 specularColor = vec3(0); vec3 specularColor = vec3(0);
calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor);
...@@ -230,7 +204,7 @@ void main() ...@@ -230,7 +204,7 @@ void main()
vec3 light = vec3(0); vec3 light = vec3(0);
// Punctual lights // Punctual lights
#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); #define LIGHT_LOOP(i) light += pbrCalcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
LIGHT_LOOP(1) LIGHT_LOOP(1)
LIGHT_LOOP(2) LIGHT_LOOP(2)
...@@ -245,7 +219,7 @@ void main() ...@@ -245,7 +219,7 @@ void main()
color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb; color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb;
float a = basecolor.a*vertex_color.a; float a = basecolor.a*vertex_color.a;
frag_color = max(vec4(color.rgb,a), vec4(0)); frag_color = max(vec4(color.rgb,a), vec4(0));
} }
...@@ -295,7 +269,7 @@ void main() ...@@ -295,7 +269,7 @@ void main()
// emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear
colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb);
float a = basecolor.a*vertex_color.a; float a = basecolor.a*vertex_color.a;
color += colorEmissive; color += colorEmissive;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D normalMap;
// Inputs // Inputs
uniform vec3 sun_dir; uniform vec3 sun_dir;
uniform vec3 moon_dir; uniform vec3 moon_dir;
...@@ -67,16 +65,16 @@ void main() ...@@ -67,16 +65,16 @@ void main()
calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten);
vec3 sunlit_linear = srgb_to_linear(sunlit); vec3 sunlit_linear = srgb_to_linear(sunlit);
// mask off atmospherics below water (when camera is under water) // mask off atmospherics below water (when camera is under water)
bool do_atmospherics = false; bool do_atmospherics = false;
if (dot(vec3(0), waterPlane.xyz) + waterPlane.w > 0.0 || if (dot(vec3(0), waterPlane.xyz) + waterPlane.w > 0.0 ||
dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0)
{ {
do_atmospherics = true; do_atmospherics = true;
} }
vec3 irradiance = vec3(0); vec3 irradiance = vec3(0);
vec3 radiance = vec3(0); vec3 radiance = vec3(0);
...@@ -101,5 +99,5 @@ void main() ...@@ -101,5 +99,5 @@ void main()
} }
frag_color = max(vec4(color.rgb, alpha), vec4(0)); //output linear since local lights will be added to this shader's results frag_color = max(vec4(color.rgb, alpha), vec4(0)); //output linear since local lights will be added to this shader's results
} }
...@@ -77,7 +77,6 @@ uniform float is_mirror; ...@@ -77,7 +77,6 @@ uniform float is_mirror;
uniform vec3 sun_dir; uniform vec3 sun_dir;
uniform vec3 moon_dir; uniform vec3 moon_dir;
in vec2 vary_fragcoord;
uniform mat4 proj_mat; uniform mat4 proj_mat;
uniform mat4 inv_proj; uniform mat4 inv_proj;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D depthMap;
uniform sampler2D diffuseRect; uniform sampler2D diffuseRect;
uniform sampler2D specularRect; uniform sampler2D specularRect;
uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
...@@ -56,8 +55,8 @@ vec3 srgb_to_linear(vec3 c); ...@@ -56,8 +55,8 @@ vec3 srgb_to_linear(vec3 c);
// Util // Util
vec3 hue_to_rgb(float hue); vec3 hue_to_rgb(float hue);
vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 v, // surface point to camera vec3 v, // surface point to camera
...@@ -91,7 +90,7 @@ void main() ...@@ -91,7 +90,7 @@ void main()
float metallic = orm.b; float metallic = orm.b;
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
vec3 baseColor = diffuse.rgb; vec3 baseColor = diffuse.rgb;
vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0);
diffuseColor *= 1.0 - metallic; diffuseColor *= 1.0 - metallic;
......
/** /**
* @file class3\deferred\pointLightF.glsl * @file class3\deferred\pointLightF.glsl
* *
* $LicenseInfo:firstyear=2022&license=viewerlgpl$ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc. * Copyright (C) 2022, Linden Research, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License only. * version 2.1 of the License only.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
/*[EXTRA_CODE_HERE]*/ /*[EXTRA_CODE_HERE]*/
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuseRect; uniform sampler2D diffuseRect;
uniform sampler2D specularRect; uniform sampler2D specularRect;
uniform sampler2D normalMap;
uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
uniform sampler2D lightFunc; uniform sampler2D lightFunc;
uniform sampler2D depthMap;
uniform vec3 env_mat[3]; uniform vec3 env_mat[3];
uniform float sun_wash; uniform float sun_wash;
...@@ -59,8 +57,8 @@ vec2 getScreenCoord(vec4 clip); ...@@ -59,8 +57,8 @@ vec2 getScreenCoord(vec4 clip);
vec3 srgb_to_linear(vec3 c); vec3 srgb_to_linear(vec3 c);
float getDepth(vec2 tc); float getDepth(vec2 tc);
vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 v, // surface point to camera vec3 v, // surface point to camera
...@@ -93,13 +91,13 @@ void main() ...@@ -93,13 +91,13 @@ void main()
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
{ {
vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 colorEmissive = texture(emissiveRect, tc).rgb;
vec3 orm = spec.rgb; vec3 orm = spec.rgb;
float perceptualRoughness = orm.g; float perceptualRoughness = orm.g;
float metallic = orm.b; float metallic = orm.b;
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
vec3 baseColor = diffuse.rgb; vec3 baseColor = diffuse.rgb;
vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0);
diffuseColor *= 1.0 - metallic; diffuseColor *= 1.0 - metallic;
...@@ -136,7 +134,7 @@ void main() ...@@ -136,7 +134,7 @@ void main()
final_color += lit*scol*color.rgb*spec.rgb; final_color += lit*scol*color.rgb*spec.rgb;
} }
} }
if (dot(final_color, final_color) <= 0.0) if (dot(final_color, final_color) <= 0.0)
{ {
discard; discard;
......
...@@ -29,7 +29,6 @@ out vec4 frag_color; ...@@ -29,7 +29,6 @@ out vec4 frag_color;
uniform sampler2D diffuseRect; uniform sampler2D diffuseRect;
uniform sampler2D specularRect; uniform sampler2D specularRect;
uniform sampler2D normalMap;
uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
const float M_PI = 3.14159265; const float M_PI = 3.14159265;
...@@ -38,7 +37,6 @@ const float M_PI = 3.14159265; ...@@ -38,7 +37,6 @@ const float M_PI = 3.14159265;
uniform sampler2D lightMap; uniform sampler2D lightMap;
#endif #endif
uniform sampler2D depthMap;
uniform sampler2D lightFunc; uniform sampler2D lightFunc;
uniform float blur_size; uniform float blur_size;
...@@ -105,8 +103,8 @@ vec3 pbrBaseLight(vec3 diffuseColor, ...@@ -105,8 +103,8 @@ vec3 pbrBaseLight(vec3 diffuseColor,
vec3 additive, vec3 additive,
vec3 atten); vec3 atten);
vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 v, // surface point to camera vec3 v, // surface point to camera
...@@ -169,15 +167,15 @@ void main() ...@@ -169,15 +167,15 @@ void main()
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
{ {
vec3 orm = spec.rgb; vec3 orm = spec.rgb;
float perceptualRoughness = orm.g; float perceptualRoughness = orm.g;
float metallic = orm.b; float metallic = orm.b;
float ao = orm.r; float ao = orm.r;
// PBR IBL // PBR IBL
float gloss = 1.0 - perceptualRoughness; float gloss = 1.0 - perceptualRoughness;
sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear); sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear);
adjustIrradiance(irradiance, ambocc); adjustIrradiance(irradiance, ambocc);
...@@ -205,7 +203,7 @@ void main() ...@@ -205,7 +203,7 @@ void main()
{ {
// legacy shaders are still writng sRGB to gbuffer // legacy shaders are still writng sRGB to gbuffer
baseColor.rgb = srgb_to_linear(baseColor.rgb); baseColor.rgb = srgb_to_linear(baseColor.rgb);
spec.rgb = srgb_to_linear(spec.rgb); spec.rgb = srgb_to_linear(spec.rgb);
float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
...@@ -224,7 +222,7 @@ void main() ...@@ -224,7 +222,7 @@ void main()
vec3 sun_contrib = min(da, scol) * sunlit_linear; vec3 sun_contrib = min(da, scol) * sunlit_linear;
color.rgb += sun_contrib; color.rgb += sun_contrib;
color.rgb *= baseColor.rgb; color.rgb *= baseColor.rgb;
vec3 refnormpersp = reflect(pos.xyz, norm.xyz); vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
if (spec.a > 0.0) if (spec.a > 0.0)
...@@ -254,7 +252,7 @@ void main() ...@@ -254,7 +252,7 @@ void main()
} }
color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a);
if (envIntensity > 0.0) if (envIntensity > 0.0)
{ // add environment map { // add environment map
applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);
......
/** /**
* @file class3\deferred\spotLightF.glsl * @file class3\deferred\spotLightF.glsl
* *
* $LicenseInfo:firstyear=2022&license=viewerlgpl$ * $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc. * Copyright (C) 2022, Linden Research, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; * License as published by the Free Software Foundation;
* version 2.1 of the License only. * version 2.1 of the License only.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$ * $/LicenseInfo$
*/ */
/*[EXTRA_CODE_HERE]*/ /*[EXTRA_CODE_HERE]*/
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuseRect; uniform sampler2D diffuseRect;
uniform sampler2D specularRect; uniform sampler2D specularRect;
uniform sampler2D depthMap;
uniform sampler2D normalMap;
uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
uniform samplerCube environmentMap; uniform samplerCube environmentMap;
uniform sampler2D lightMap; uniform sampler2D lightMap;
uniform sampler2D projectionMap; // rgba
uniform sampler2D lightFunc; uniform sampler2D lightFunc;
uniform mat4 proj_mat; //screen space to light space uniform mat4 proj_mat; //screen space to light space
...@@ -83,8 +80,8 @@ vec4 getPosition(vec2 pos_screen); ...@@ -83,8 +80,8 @@ vec4 getPosition(vec2 pos_screen);
const float M_PI = 3.14159265; const float M_PI = 3.14159265;
vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness, float perceptualRoughness,
float metallic, float metallic,
vec3 n, // normal vec3 n, // normal
vec3 v, // surface point to camera vec3 v, // surface point to camera
...@@ -112,13 +109,13 @@ void main() ...@@ -112,13 +109,13 @@ void main()
} }
float shadow = 1.0; float shadow = 1.0;
if (proj_shadow_idx >= 0) if (proj_shadow_idx >= 0)
{ {
vec4 shd = texture(lightMap, tc); vec4 shd = texture(lightMap, tc);
shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow = (proj_shadow_idx==0)?shd.b:shd.a;
shadow += shadow_fade; shadow += shadow_fade;
shadow = clamp(shadow, 0.0, 1.0); shadow = clamp(shadow, 0.0, 1.0);
} }
vec4 norm = getNorm(tc); vec4 norm = getNorm(tc);
...@@ -149,7 +146,7 @@ void main() ...@@ -149,7 +146,7 @@ void main()
float metallic = orm.b; float metallic = orm.b;
vec3 f0 = vec3(0.04); vec3 f0 = vec3(0.04);
vec3 baseColor = diffuse.rgb; vec3 baseColor = diffuse.rgb;
vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0);
diffuseColor *= 1.0 - metallic; diffuseColor *= 1.0 - metallic;
...@@ -167,7 +164,7 @@ void main() ...@@ -167,7 +164,7 @@ void main()
if (nl > 0.0) if (nl > 0.0)
{ {
amb_da += (nl*0.5 + 0.5) * proj_ambiance; amb_da += (nl*0.5 + 0.5) * proj_ambiance;
dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy );
vec3 intensity = dist_atten * dlit * 3.25 * shadow; // Legacy attenuation, magic number to balance with legacy materials vec3 intensity = dist_atten * dlit * 3.25 * shadow; // Legacy attenuation, magic number to balance with legacy materials
...@@ -205,11 +202,11 @@ void main() ...@@ -205,11 +202,11 @@ void main()
// unshadowed for consistency between forward and deferred? // unshadowed for consistency between forward and deferred?
amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance;
} }
amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy );
final_color += diffuse.rgb * amb_rgb * max(dot(-normalize(lv), n), 0.0); final_color += diffuse.rgb * amb_rgb * max(dot(-normalize(lv), n), 0.0);
} }
if (spec.a > 0.0) if (spec.a > 0.0)
{ {
dlit *= min(nl*6.0, 1.0) * dist_atten; dlit *= min(nl*6.0, 1.0) * dist_atten;
...@@ -218,7 +215,7 @@ void main() ...@@ -218,7 +215,7 @@ void main()
float gtdenom = 2 * nh; float gtdenom = 2 * nh;
float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh));
if (nh > 0.0) if (nh > 0.0)
{ {
float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl);
...@@ -226,26 +223,26 @@ void main() ...@@ -226,26 +223,26 @@ void main()
speccol = clamp(speccol, vec3(0), vec3(1)); speccol = clamp(speccol, vec3(0), vec3(1));
final_color += speccol; final_color += speccol;
} }
} }
if (envIntensity > 0.0) if (envIntensity > 0.0)
{ {
vec3 ref = reflect(normalize(pos), n); vec3 ref = reflect(normalize(pos), n);
//project from point pos in direction ref to plane proj_p, proj_n //project from point pos in direction ref to plane proj_p, proj_n
vec3 pdelta = proj_p-pos; vec3 pdelta = proj_p-pos;
float ds = dot(ref, proj_n); float ds = dot(ref, proj_n);
if (ds < 0.0) if (ds < 0.0)
{ {
vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds;
vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0));
if (stc.z > 0.0) if (stc.z > 0.0)
{ {
stc /= stc.w; stc /= stc.w;
if (stc.x < 1.0 && if (stc.x < 1.0 &&
stc.y < 1.0 && stc.y < 1.0 &&
stc.x > 0.0 && stc.x > 0.0 &&
......
...@@ -28,8 +28,6 @@ out vec4 frag_color; ...@@ -28,8 +28,6 @@ out vec4 frag_color;
// Inputs // Inputs
in vec4 vary_fragcoord; in vec4 vary_fragcoord;
uniform sampler2D normalMap;
vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPositionWithDepth(vec2 pos_screen, float depth);
float getDepth(vec2 pos_screen); float getDepth(vec2 pos_screen);
...@@ -43,7 +41,7 @@ void main() ...@@ -43,7 +41,7 @@ void main()
float depth = getDepth(tc.xy); float depth = getDepth(tc.xy);
if (above_water > 0) if (above_water > 0)
{ {
// we want to depth test when the camera is above water, but some GPUs have a hard time // we want to depth test when the camera is above water, but some GPUs have a hard time
// with depth testing against render targets that are bound for sampling in the same shader // with depth testing against render targets that are bound for sampling in the same shader
// so we do it manually here // so we do it manually here
...@@ -60,5 +58,5 @@ void main() ...@@ -60,5 +58,5 @@ void main()
vec4 fogged = getWaterFogView(pos.xyz); vec4 fogged = getWaterFogView(pos.xyz);
frag_color = max(fogged, vec4(0)); //output linear since local lights will be added to this shader's results frag_color = max(fogged, vec4(0)); //output linear since local lights will be added to this shader's results
} }
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuseMap;
uniform sampler2D bumpMap; uniform sampler2D bumpMap;
#ifdef TRANSPARENT_WATER #ifdef TRANSPARENT_WATER
......
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