Apertura del repositorio

This commit is contained in:
2025-05-24 18:09:39 -03:00
parent 76e6359dad
commit d883ddd0d0
35253 changed files with 2891973 additions and 2 deletions
@@ -0,0 +1,314 @@
/**
* @file alphaF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
//class2/deferred/alphaF.glsl
/*[EXTRA_CODE_HERE]*/
#define INDEXED 1
#define NON_INDEXED 2
#define NON_INDEXED_NO_COLOR 3
out vec4 frag_color;
uniform mat3 env_mat;
uniform vec3 sun_dir;
uniform vec3 moon_dir;
uniform int classic_mode;
#ifdef USE_DIFFUSE_TEX
uniform sampler2D diffuseMap;
#endif
in vec3 vary_fragcoord;
in vec3 vary_position;
in vec2 vary_texcoord0;
in vec3 vary_norm;
#ifdef USE_VERTEX_COLOR
in vec4 vertex_color; //vertex color should be treated as sRGB
#endif
#ifdef HAS_ALPHA_MASK
uniform float minimum_alpha;
#endif
uniform mat4 proj_mat;
uniform mat4 inv_proj;
uniform vec2 screen_res;
uniform int sun_up_factor;
uniform vec4 light_position[8];
uniform vec3 light_direction[8];
uniform vec4 light_attenuation[8];
uniform vec3 light_diffuse[8];
void waterClip(vec3 pos);
vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c);
vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
#ifdef HAS_SUN_SHADOW
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
#endif
float getAmbientClamp();
void mirrorClip(vec3 pos);
void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear);
vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance)
{
// SL-14895 inverted attenuation work-around
// This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct
// that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights()
// to recover the `adjusted_radius` value previously being sent as la.
float falloff_factor = (12.0 * fa) - 9.0;
float inverted_la = falloff_factor / la;
// Yes, it makes me want to cry as well. DJH
vec3 col = vec3(0);
//get light vector
vec3 lv = lp.xyz-v;
//get distance
float dist = length(lv);
float da = 1.0;
/*if (dist > inverted_la)
{
return col;
}
clip to projector bounds
vec4 proj_tc = proj_mat * lp;
if (proj_tc.z < 0
|| proj_tc.z > 1
|| proj_tc.x < 0
|| proj_tc.x > 1
|| proj_tc.y < 0
|| proj_tc.y > 1)
{
return col;
}*/
if (dist > 0.0 && inverted_la > 0.0)
{
dist /= inverted_la;
//normalize light vector
lv = normalize(lv);
//distance attenuation
float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0f;
if (dist_atten <= 0.0)
{
return col;
}
// spotlight coefficient.
float spot = max(dot(-ln, lv), is_pointlight);
da *= spot*spot; // GL_SPOT_EXPONENT=2
//angular attenuation
da *= dot(n, lv);
da = max(0.0, da);
float lit = 0.0f;
float amb_da = 0.0;//ambiance;
if (da > 0)
{
lit = clamp(da * dist_atten, 0.0, 1.0);
col = lit * light_col * diffuse;
amb_da += (da*0.5+0.5) * ambiance;
}
amb_da += (da*da*0.5 + 0.5) * ambiance;
amb_da *= dist_atten;
amb_da = min(amb_da, 1.0f - lit);
// SL-10969 ... need to work out why this blows out in many setups...
//col.rgb += amb_da * light_col * diffuse;
// no spec for alpha shader...
}
float final_scale = 1.0;
if (classic_mode > 0)
final_scale = 0.9;
col = max(col * final_scale, vec3(0));
return col;
}
void main()
{
mirrorClip(vary_position);
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
vec4 pos = vec4(vary_position, 1.0);
#ifndef IS_AVATAR_SKIN
// clip against water plane unless this is a legacy avatar skin
waterClip(pos.xyz);
#endif
vec3 norm = vary_norm;
float shadow = 1.0f;
#ifdef HAS_SUN_SHADOW
shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag);
#endif
#ifdef USE_DIFFUSE_TEX
vec4 diffuse_tap = texture(diffuseMap,vary_texcoord0.xy);
#endif
#ifdef USE_INDEXED_TEX
vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy);
#endif
vec4 diffuse_srgb = diffuse_tap;
#ifdef FOR_IMPOSTOR
vec4 color;
color.rgb = diffuse_srgb.rgb;
color.a = 1.0;
float final_alpha = diffuse_srgb.a * vertex_color.a;
diffuse_srgb.rgb *= vertex_color.rgb;
// Insure we don't pollute depth with invis pixels in impostor rendering
//
if (final_alpha < minimum_alpha)
{
discard;
}
color.rgb = diffuse_srgb.rgb;
color.a = final_alpha;
#else // FOR_IMPOSTOR
vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; // TODO -- factor out "sun_up_factor" and just send in the appropriate light vector
float final_alpha = diffuse_linear.a;
#ifdef USE_VERTEX_COLOR
final_alpha *= vertex_color.a;
if (final_alpha < minimum_alpha)
{ // TODO: figure out how to get invisible faces out of
// render batches without breaking glow
discard;
}
diffuse_srgb.rgb *= vertex_color.rgb;
diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb);
#endif // USE_VERTEX_COLOR
vec3 sunlit;
vec3 amblit;
vec3 additive;
vec3 atten;
calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten);
if (classic_mode > 0)
sunlit *= 1.35;
vec3 sunlit_linear = sunlit;
vec3 amblit_linear = amblit;
vec3 irradiance = amblit;
vec3 glossenv;
vec3 legacyenv;
sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0, true, amblit_linear);
float da = dot(norm.xyz, light_dir.xyz);
da = clamp(da, -1.0, 1.0);
float final_da = da;
final_da = clamp(final_da, 0.0f, 1.0f);
vec4 color = vec4(0.0);
color.a = final_alpha;
color.rgb = irradiance;
if (classic_mode > 0)
{
final_da = pow(final_da,1.2);
vec3 sun_contrib = vec3(min(final_da, shadow));
color.rgb = srgb_to_linear(color.rgb * 0.9 + linear_to_srgb(sun_contrib) * sunlit_linear * 0.7);
sunlit_linear = srgb_to_linear(sunlit_linear);
}
else
{
vec3 sun_contrib = min(final_da, shadow) * sunlit_linear;
color.rgb += sun_contrib;
}
color.rgb *= diffuse_linear.rgb;
vec4 light = vec4(0,0,0,0);
#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
LIGHT_LOOP(1)
LIGHT_LOOP(2)
LIGHT_LOOP(3)
LIGHT_LOOP(4)
LIGHT_LOOP(5)
LIGHT_LOOP(6)
LIGHT_LOOP(7)
// sum local light contrib in linear colorspace
color.rgb += light.rgb;
color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, color).rgb;
#endif // #else // FOR_IMPOSTOR
float final_scale = 1;
if (classic_mode > 0)
final_scale = 1.1;
#ifdef IS_HUD
color.rgb = linear_to_srgb(color.rgb);
final_scale = 1;
#endif
color.rgb *= final_scale;
frag_color = max(color, vec4(0));
}
@@ -0,0 +1,277 @@
/**
* @file class1\deferred\pbralphaF.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
/*[EXTRA_CODE_HERE]*/
#ifndef IS_HUD
uniform sampler2D diffuseMap; //always in sRGB space
uniform sampler2D bumpMap;
uniform sampler2D emissiveMap;
uniform sampler2D specularMap; // PBR: Packed: Occlusion, Metal, Roughness
uniform float metallicFactor;
uniform float roughnessFactor;
uniform vec3 emissiveColor;
#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)
uniform sampler2D lightMap;
#endif
uniform int sun_up_factor;
uniform vec3 sun_dir;
uniform vec3 moon_dir;
uniform int classic_mode;
out vec4 frag_color;
in vec3 vary_fragcoord;
#ifdef HAS_SUN_SHADOW
uniform vec2 screen_res;
#endif
in vec3 vary_position;
in vec2 base_color_texcoord;
in vec2 normal_texcoord;
in vec2 metallic_roughness_texcoord;
in vec2 emissive_texcoord;
in vec4 vertex_color;
in vec3 vary_normal;
in vec3 vary_tangent;
flat in float vary_sign;
#ifdef HAS_ALPHA_MASK
uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
#endif
// Lights
// See: LLRender::syncLightState()
uniform vec4 light_position[8];
uniform vec3 light_direction[8]; // spot direction
uniform vec4 light_attenuation[8]; // linear, quadratic, is omni, unused, See: LLPipeline::setupHWLights() and syncLightState()
uniform vec3 light_diffuse[8];
uniform vec2 light_deferred_attenuation[8]; // light size and falloff
vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
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);
float calcLegacyDistanceAttenuation(float distance, float falloff);
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear);
void mirrorClip(vec3 pos);
void waterClip(vec3 pos);
void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor);
vec3 pbrBaseLight(vec3 diffuseColor,
vec3 specularColor,
float metallic,
vec3 pos,
vec3 norm,
float perceptualRoughness,
vec3 light_dir,
vec3 sunlit,
float scol,
vec3 radiance,
vec3 irradiance,
vec3 colorEmissive,
float ao,
vec3 additive,
vec3 atten);
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);
void main()
{
mirrorClip(vary_position);
vec3 color = vec3(0,0,0);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
vec3 pos = vary_position;
waterClip(pos);
vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
basecolor.rgb = srgb_to_linear(basecolor.rgb);
#ifdef HAS_ALPHA_MASK
if (basecolor.a < minimum_alpha)
{
discard;
}
#endif
vec3 col = vertex_color.rgb * basecolor.rgb;
vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0;
float sign = vary_sign;
vec3 vN = vary_normal;
vec3 vT = vary_tangent.xyz;
vec3 vB = sign * cross(vN, vT);
vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
norm *= gl_FrontFacing ? 1.0 : -1.0;
float scol = 1.0;
vec3 sunlit;
vec3 amblit;
vec3 additive;
vec3 atten;
calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten);
if (classic_mode > 0)
sunlit *= 1.35;
vec3 sunlit_linear = sunlit;
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
#ifdef HAS_SUN_SHADOW
scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag);
#endif
vec3 orm = texture(specularMap, metallic_roughness_texcoord.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space
float perceptualRoughness = orm.g * roughnessFactor;
float metallic = orm.b * metallicFactor;
float ao = orm.r;
// emissiveColor is the emissive color factor from GLTF and is already in linear space
vec3 colorEmissive = emissiveColor;
// emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear
colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb);
// PBR IBL
float gloss = 1.0 - perceptualRoughness;
vec3 irradiance = amblit;
vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit);
vec3 diffuseColor;
vec3 specularColor;
calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor);
vec3 v = -normalize(pos.xyz);
color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten);
vec3 light = vec3(0);
// Punctual lights
#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(2)
LIGHT_LOOP(3)
LIGHT_LOOP(4)
LIGHT_LOOP(5)
LIGHT_LOOP(6)
LIGHT_LOOP(7)
color.rgb += light.rgb;
color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb;
float a = basecolor.a*vertex_color.a;
float final_scale = 1;
if (classic_mode > 0)
final_scale = 1.1;
frag_color = max(vec4(color.rgb * final_scale,a), vec4(0));
}
#else
uniform sampler2D diffuseMap; //always in sRGB space
uniform sampler2D emissiveMap;
uniform vec3 emissiveColor;
out vec4 frag_color;
in vec3 vary_position;
in vec2 base_color_texcoord;
in vec2 emissive_texcoord;
in vec4 vertex_color;
#ifdef HAS_ALPHA_MASK
uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
#endif
vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c);
void main()
{
vec3 color = vec3(0,0,0);
vec3 pos = vary_position;
vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
basecolor.rgb = srgb_to_linear(basecolor.rgb);
#ifdef HAS_ALPHA_MASK
if (basecolor.a < minimum_alpha)
{
discard;
}
#endif
color = vertex_color.rgb * basecolor.rgb;
// emissiveColor is the emissive color factor from GLTF and is already in linear space
vec3 colorEmissive = emissiveColor;
// emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear
colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb);
float a = basecolor.a*vertex_color.a;
color += colorEmissive;
color = linear_to_srgb(color);
frag_color = max(vec4(color.rgb,a), vec4(0));
}
#endif
@@ -0,0 +1,81 @@
/**
* @file class2/deferred/reflectionProbeF.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
// Implementation for when reflection probes are disabled
uniform float reflection_probe_ambiance;
uniform samplerCube environmentMap;
uniform mat3 env_mat;
vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c);
void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear)
{
ambenv = mix(ambenv, vec3(reflection_probe_ambiance * 0.25), reflection_probe_ambiance);
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
vec3 env_vec = env_mat * refnormpersp;
glossenv = srgb_to_linear(texture(environmentMap, env_vec).rgb);
}
void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, vec3 amblit_linear)
{
sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, false, amblit_linear);
}
vec4 sampleReflectionProbesDebug(vec3 pos)
{
// show nothing in debug display
return vec4(0, 0, 0, 0);
}
void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv,
vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear)
{
ambenv = mix(ambenv, vec3(reflection_probe_ambiance * 0.25), reflection_probe_ambiance);
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
vec3 env_vec = env_mat * refnormpersp;
legacyenv = texture(environmentMap, env_vec).rgb;
glossenv = legacyenv;
}
void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm)
{
}
void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity)
{
color = srgb_to_linear(mix(linear_to_srgb(color.rgb), legacyenv*2.0, envIntensity));
}
@@ -0,0 +1,47 @@
/**
* @file softenLightF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
in vec3 position;
uniform vec2 screen_res;
out vec2 vary_fragcoord;
// forwards
void setAtmosAttenuation(vec3 c);
void setAdditiveColor(vec3 c);
void main()
{
//transform vertex
vec4 pos = vec4(position.xyz, 1.0);
gl_Position = pos;
// appease OSX GLSL compiler/linker by touching all the varyings we said we would
setAtmosAttenuation(vec3(1));
setAdditiveColor(vec3(0));
vary_fragcoord = (pos.xy*0.5+0.5);
}
@@ -0,0 +1,57 @@
/**
* @file sunLightF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
//class 2, shadows, no SSAO
// Inputs
in vec2 vary_fragcoord;
uniform vec3 sun_dir;
uniform float shadow_bias;
vec4 getNorm(vec2 pos_screen);
vec4 getPosition(vec2 pos_screen);
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen);
void main()
{
vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = getPosition(pos_screen);
vec4 norm = getNorm(pos_screen);
vec4 col;
col.r = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen);
col.g = 1.0f;
col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen);
col.a = sampleSpotShadow(pos.xyz, norm.xyz, 1, pos_screen);
frag_color = clamp(col, vec4(0), vec4(1));
}
@@ -0,0 +1,54 @@
/**
* @file class2/deferred/sunLightSSAOF.glsl
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
//class 2 -- shadows and SSAO
// Inputs
in vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen);
vec4 getNorm(vec2 pos_screen);
float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen);
float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen);
float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen);
void main()
{
vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = getPosition(pos_screen);
vec4 norm = getNorm(pos_screen);
vec4 col;
col.r = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen);
col.g = calcAmbientOcclusion(pos, norm.xyz, pos_screen);
col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen);
col.a = sampleSpotShadow(pos.xyz, norm.xyz, 1, pos_screen);
frag_color = clamp(col, vec4(0), vec4(1));
}
@@ -0,0 +1,39 @@
/**
* @file sunLightV.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
in vec3 position;
out vec2 vary_fragcoord;
uniform vec2 screen_res;
void main()
{
//transform vertex
vec4 pos = vec4(position.xyz, 1.0);
gl_Position = pos;
vary_fragcoord = (pos.xy * 0.5 + 0.5);
}
@@ -0,0 +1,214 @@
/**
* @file irradianceGenF.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
uniform samplerCubeArray reflectionProbes;
uniform int sourceIdx;
uniform float max_probe_lod;
in vec3 vary_dir;
// Code below is derived from the Khronos GLTF Sample viewer:
// https://github.com/KhronosGroup/glTF-Sample-Viewer/blob/master/source/shaders/ibl_filtering.frag
#define MATH_PI 3.1415926535897932384626433832795
float u_roughness = 1.0;
int u_sampleCount = 32;
float u_lodBias = 2.0;
int u_width = 64;
// Hammersley Points on the Hemisphere
// CC BY 3.0 (Holger Dammertz)
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
// with adapted interface
float radicalInverse_VdC(uint bits)
{
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
// hammersley2d describes a sequence of points in the 2d unit square [0,1)^2
// that can be used for quasi Monte Carlo integration
vec2 hammersley2d(int i, int N) {
return vec2(float(i)/float(N), radicalInverse_VdC(uint(i)));
}
// Hemisphere Sample
// TBN generates a tangent bitangent normal coordinate frame from the normal
// (the normal must be normalized)
mat3 generateTBN(vec3 normal)
{
vec3 bitangent = vec3(0.0, 1.0, 0.0);
float NdotUp = dot(normal, vec3(0.0, 1.0, 0.0));
float epsilon = 0.0000001;
/*if (1.0 - abs(NdotUp) <= epsilon)
{
// Sampling +Y or -Y, so we need a more robust bitangent.
if (NdotUp > 0.0)
{
bitangent = vec3(0.0, 0.0, 1.0);
}
else
{
bitangent = vec3(0.0, 0.0, -1.0);
}
}*/
vec3 tangent = normalize(cross(bitangent, normal));
bitangent = cross(normal, tangent);
return mat3(tangent, bitangent, normal);
}
struct MicrofacetDistributionSample
{
float pdf;
float cosTheta;
float sinTheta;
float phi;
};
MicrofacetDistributionSample Lambertian(vec2 xi, float roughness)
{
MicrofacetDistributionSample lambertian;
// Cosine weighted hemisphere sampling
// http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#Cosine-WeightedHemisphereSampling
lambertian.cosTheta = sqrt(1.0 - xi.y);
lambertian.sinTheta = sqrt(xi.y); // equivalent to `sqrt(1.0 - cosTheta*cosTheta)`;
lambertian.phi = 2.0 * MATH_PI * xi.x;
lambertian.pdf = lambertian.cosTheta / MATH_PI; // evaluation for solid angle, therefore drop the sinTheta
return lambertian;
}
// getImportanceSample returns an importance sample direction with pdf in the .w component
vec4 getImportanceSample(int sampleIndex, vec3 N, float roughness)
{
// generate a quasi monte carlo point in the unit square [0.1)^2
vec2 xi = hammersley2d(sampleIndex, u_sampleCount);
MicrofacetDistributionSample importanceSample;
// generate the points on the hemisphere with a fitting mapping for
// the distribution (e.g. lambertian uses a cosine importance)
importanceSample = Lambertian(xi, roughness);
// transform the hemisphere sample to the normal coordinate frame
// i.e. rotate the hemisphere to the normal direction
vec3 localSpaceDirection = normalize(vec3(
importanceSample.sinTheta * cos(importanceSample.phi),
importanceSample.sinTheta * sin(importanceSample.phi),
importanceSample.cosTheta
));
mat3 TBN = generateTBN(N);
vec3 direction = TBN * localSpaceDirection;
return vec4(direction, importanceSample.pdf);
}
// Mipmap Filtered Samples (GPU Gems 3, 20.4)
// https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-20-gpu-based-importance-sampling
// https://cgg.mff.cuni.cz/~jaroslav/papers/2007-sketch-fis/Final_sap_0073.pdf
float computeLod(float pdf)
{
// // Solid angle of current sample -- bigger for less likely samples
// float omegaS = 1.0 / (float(u_sampleCount) * pdf);
// // Solid angle of texel
// // note: the factor of 4.0 * MATH_PI
// float omegaP = 4.0 * MATH_PI / (6.0 * float(u_width) * float(u_width));
// // Mip level is determined by the ratio of our sample's solid angle to a texel's solid angle
// // note that 0.5 * log2 is equivalent to log4
// float lod = 0.5 * log2(omegaS / omegaP);
// babylon introduces a factor of K (=4) to the solid angle ratio
// this helps to avoid undersampling the environment map
// this does not appear in the original formulation by Jaroslav Krivanek and Mark Colbert
// log4(4) == 1
// lod += 1.0;
// We achieved good results by using the original formulation from Krivanek & Colbert adapted to cubemaps
// https://cgg.mff.cuni.cz/~jaroslav/papers/2007-sketch-fis/Final_sap_0073.pdf
float lod = 0.5 * log2( 6.0 * float(u_width) * float(u_width) / (float(u_sampleCount) * pdf));
return lod;
}
vec4 filterColor(vec3 N)
{
vec4 color = vec4(0.f);
for(int i = 0; i < u_sampleCount; ++i)
{
vec4 importanceSample = getImportanceSample(i, N, 1.0);
vec3 H = vec3(importanceSample.xyz);
float pdf = importanceSample.w;
// mipmap filtered samples (GPU Gems 3, 20.4)
float lod = computeLod(pdf);
// apply the bias to the lod
lod += u_lodBias;
lod = clamp(lod, 0, max_probe_lod);
// sample lambertian at a lower resolution to avoid fireflies
vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod);
color += lambertian;
}
color /= float(u_sampleCount);
return color;
}
// entry point
void main()
{
vec4 color = vec4(0);
color = filterColor(vary_dir);
frag_color = max(color, vec4(0));
}
@@ -0,0 +1,42 @@
/**
* @file reflectionprobeF.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
out vec4 frag_color;
in vec2 vary_fragcoord;
vec4 getPositionWithDepth(vec2 pos_screen, float depth);
float getDepth(vec2 pos_screen);
vec4 sampleReflectionProbesDebug(vec3 pos);
void main()
{
vec2 tc = vary_fragcoord.xy;
float depth = getDepth(tc.xy);
vec4 pos = getPositionWithDepth(tc, depth);
frag_color = max(sampleReflectionProbesDebug(pos.xyz), vec4(0));
}
@@ -0,0 +1,38 @@
/**
* @file reflectionprobeV.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2011, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
in vec3 position;
out vec2 vary_fragcoord;
void main()
{
//transform vertex
vec4 pos = vec4(position.xyz, 1.0);
gl_Position = pos;
vary_fragcoord = (pos.xy*0.5+0.5);
}