SL-17701 WIP -- Parity for point lights between opaque and transparent PBR materials
parent
ca5a6bb0b8
commit
ff3a28422d
|
|
@ -735,6 +735,24 @@ void LLLightState::setSunPrimary(bool v)
|
|||
}
|
||||
}
|
||||
|
||||
void LLLightState::setSize(F32 v)
|
||||
{
|
||||
if (mSize != v)
|
||||
{
|
||||
++gGL.mLightHash;
|
||||
mSize = v;
|
||||
}
|
||||
}
|
||||
|
||||
void LLLightState::setFalloff(F32 v)
|
||||
{
|
||||
if (mFalloff != v)
|
||||
{
|
||||
++gGL.mLightHash;
|
||||
mFalloff = v;
|
||||
}
|
||||
}
|
||||
|
||||
void LLLightState::setAmbient(const LLColor4& ambient)
|
||||
{
|
||||
if (mAmbient != ambient)
|
||||
|
|
@ -969,6 +987,7 @@ void LLRender::syncLightState()
|
|||
LLVector3 diffuse[LL_NUM_LIGHT_UNITS];
|
||||
LLVector3 diffuse_b[LL_NUM_LIGHT_UNITS];
|
||||
bool sun_primary[LL_NUM_LIGHT_UNITS];
|
||||
LLVector2 size[LL_NUM_LIGHT_UNITS];
|
||||
|
||||
for (U32 i = 0; i < LL_NUM_LIGHT_UNITS; i++)
|
||||
{
|
||||
|
|
@ -980,11 +999,13 @@ void LLRender::syncLightState()
|
|||
diffuse[i].set(light->mDiffuse.mV);
|
||||
diffuse_b[i].set(light->mDiffuseB.mV);
|
||||
sun_primary[i] = light->mSunIsPrimary;
|
||||
size[i].set(light->mSize, light->mFalloff);
|
||||
}
|
||||
|
||||
shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, LL_NUM_LIGHT_UNITS, position[0].mV);
|
||||
shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, LL_NUM_LIGHT_UNITS, direction[0].mV);
|
||||
shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, LL_NUM_LIGHT_UNITS, attenuation[0].mV);
|
||||
shader->uniform2fv(LLShaderMgr::LIGHT_DEFERRED_ATTENUATION, LL_NUM_LIGHT_UNITS, size[0].mV);
|
||||
shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, LL_NUM_LIGHT_UNITS, diffuse[0].mV);
|
||||
shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV);
|
||||
shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0);
|
||||
|
|
|
|||
|
|
@ -246,6 +246,8 @@ public:
|
|||
void setSpotCutoff(const F32& cutoff);
|
||||
void setSpotDirection(const LLVector3& direction);
|
||||
void setSunPrimary(bool v);
|
||||
void setSize(F32 size);
|
||||
void setFalloff(F32 falloff);
|
||||
|
||||
protected:
|
||||
friend class LLRender;
|
||||
|
|
@ -266,6 +268,8 @@ protected:
|
|||
|
||||
F32 mSpotExponent;
|
||||
F32 mSpotCutoff;
|
||||
F32 mSize = 0.f;
|
||||
F32 mFalloff = 0.f;
|
||||
};
|
||||
|
||||
class LLRender
|
||||
|
|
|
|||
|
|
@ -1180,6 +1180,7 @@ void LLShaderMgr::initAttribsAndUniforms()
|
|||
mReservedUniforms.push_back("light_position");
|
||||
mReservedUniforms.push_back("light_direction");
|
||||
mReservedUniforms.push_back("light_attenuation");
|
||||
mReservedUniforms.push_back("light_deferred_attenuation");
|
||||
mReservedUniforms.push_back("light_diffuse");
|
||||
mReservedUniforms.push_back("light_ambient");
|
||||
mReservedUniforms.push_back("light_count");
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public:
|
|||
LIGHT_POSITION, // "light_position"
|
||||
LIGHT_DIRECTION, // "light_direction"
|
||||
LIGHT_ATTENUATION, // "light_attenuation"
|
||||
LIGHT_DEFERRED_ATTENUATION, // "light_deferred_attenuation"
|
||||
LIGHT_DIFFUSE, // "light_diffuse"
|
||||
LIGHT_AMBIENT, // "light_ambient"
|
||||
MULTI_LIGHT_COUNT, // "light_count"
|
||||
|
|
|
|||
|
|
@ -92,12 +92,14 @@ 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);
|
||||
|
||||
// These are in deferredUtil.glsl but we can't set: mFeatures.isDeferred to include it
|
||||
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh );
|
||||
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh );
|
||||
void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
|
||||
vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
|
||||
vec3 scaleSoftClipFrag(vec3 l);
|
||||
|
|
@ -139,29 +141,23 @@ void pbrIbl(out vec3 colorDiffuse, // diffuse color output
|
|||
// la = linear attenuation, light radius
|
||||
// fa = falloff
|
||||
// See: LLRender::syncLightState()
|
||||
vec3 calcPointLightOrSpotLight(vec3 reflect0, vec3 c_diff,
|
||||
vec3 lightColor, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln,
|
||||
float la, float fa, float is_pointlight, float ambiance)
|
||||
vec3 calcPointLightOrSpotLight(vec3 reflect0, vec3 reflect90, float alphaRough, vec3 c_diff,
|
||||
vec3 lightColor, vec3 diffuse, vec3 p, vec3 v, vec3 n, vec4 lp, vec3 ln,
|
||||
float lightSize, float lightFalloff, float is_pointlight, float ambiance)
|
||||
{
|
||||
vec3 intensity = vec3(0);
|
||||
|
||||
vec3 lv = lp.xyz - v;
|
||||
vec3 lv = lp.xyz - p;
|
||||
vec3 h, l;
|
||||
float nh, nl, nv, vh, lightDist;
|
||||
calcHalfVectors(lv,n,v,h,l,nh,nl,nv,vh,lightDist);
|
||||
|
||||
if (lightDist > 0.0)
|
||||
float dist = lightDist/lightSize;
|
||||
|
||||
if (dist <= 1.0 && nl > 0.0)
|
||||
{
|
||||
float falloff_factor = (12.0 * fa) - 9.0;
|
||||
float inverted_la = falloff_factor / la;
|
||||
float dist_atten = calcLegacyDistanceAttenuation(dist,lightFalloff);
|
||||
|
||||
float dist = lightDist / inverted_la;
|
||||
|
||||
float dist_atten = calcLegacyDistanceAttenuation(dist,fa);
|
||||
if (dist_atten <= 0.0)
|
||||
return intensity;
|
||||
|
||||
vec3 reflect90 = vec3(1);
|
||||
float specWeight = 1.0;
|
||||
|
||||
lv = normalize(lv);
|
||||
|
|
@ -169,7 +165,13 @@ vec3 calcPointLightOrSpotLight(vec3 reflect0, vec3 c_diff,
|
|||
nl *= spot * spot;
|
||||
|
||||
if (nl > 0.0)
|
||||
intensity = dist_atten * nl * lightColor * BRDFLambertian(reflect0, reflect90, c_diff, specWeight, vh);
|
||||
{
|
||||
vec3 color = vec3(0);
|
||||
intensity = dist_atten * nl * lightColor;
|
||||
color += intensity * BRDFLambertian(reflect0, reflect90, c_diff, specWeight, vh);
|
||||
color += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return intensity;
|
||||
}
|
||||
|
|
@ -270,7 +272,20 @@ void main()
|
|||
vec3 light = vec3(0);
|
||||
|
||||
// Punctual lights
|
||||
#define LIGHT_LOOP(i) light += srgb_to_linear(vec3(scol)) * calcPointLightOrSpotLight( reflect0, c_diff, srgb_to_linear(2.2*light_diffuse[i].rgb), base.rgb, pos.xyz, n, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w );
|
||||
#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight( \
|
||||
reflect0, \
|
||||
reflect90, \
|
||||
alphaRough, \
|
||||
c_diff, \
|
||||
light_diffuse[i].rgb, \
|
||||
base.rgb, \
|
||||
pos.xyz, \
|
||||
v, \
|
||||
n, \
|
||||
light_position[i], \
|
||||
light_direction[i].xyz, \
|
||||
light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, \
|
||||
light_attenuation[i].z, light_attenuation[i].w );
|
||||
|
||||
LIGHT_LOOP(1)
|
||||
LIGHT_LOOP(2)
|
||||
|
|
@ -280,6 +295,8 @@ void main()
|
|||
LIGHT_LOOP(6)
|
||||
LIGHT_LOOP(7)
|
||||
|
||||
col.rgb += light.rgb;
|
||||
|
||||
col.rgb = linear_to_srgb(col.rgb);
|
||||
col *= atten.r;
|
||||
col += 2.0*additive;
|
||||
|
|
|
|||
|
|
@ -27,11 +27,6 @@
|
|||
|
||||
/*[EXTRA_CODE_HERE]*/
|
||||
|
||||
#define DEBUG_ANY_LIGHT_TYPE 0 // Output red light cone
|
||||
#define DEBUG_PBR_LIGHT_TYPE 0 // Output PBR objects in red
|
||||
#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in red
|
||||
#define DEBUG_POINT_ZERO 0 // Output zero for point lights
|
||||
|
||||
#ifdef DEFINE_GL_FRAGCOLOR
|
||||
out vec4 frag_color;
|
||||
#else
|
||||
|
|
@ -123,9 +118,6 @@ void main()
|
|||
}
|
||||
}
|
||||
|
||||
#if DEBUG_PBR_LIGHT_TYPE
|
||||
colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0);
|
||||
#endif
|
||||
final_color = colorDiffuse + colorSpec;
|
||||
}
|
||||
else
|
||||
|
|
@ -174,18 +166,8 @@ void main()
|
|||
}
|
||||
}
|
||||
}
|
||||
#if DEBUG_LEG_LIGHT_TYPE
|
||||
final_color.rgb = vec3(0.5,0,0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG_POINT_ZERO
|
||||
final_color = vec3(0);
|
||||
#endif
|
||||
#if DEBUG_ANY_LIGHT_TYPE
|
||||
final_color = vec3(0.3333,0,0);
|
||||
#endif
|
||||
|
||||
frag_color.rgb = final_color;
|
||||
frag_color.a = 0.0;
|
||||
#endif // LOCAL_LIGHT_KILL
|
||||
|
|
|
|||
|
|
@ -27,11 +27,6 @@
|
|||
|
||||
/*[EXTRA_CODE_HERE]*/
|
||||
|
||||
#define DEBUG_ANY_LIGHT_TYPE 0 // Output magenta light cone
|
||||
#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green
|
||||
#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in blue
|
||||
#define DEBUG_POINT_ZERO 0 // Output zero for point light
|
||||
|
||||
#ifdef DEFINE_GL_FRAGCOLOR
|
||||
out vec4 frag_color;
|
||||
#else
|
||||
|
|
@ -119,9 +114,6 @@ void main()
|
|||
colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);
|
||||
}
|
||||
|
||||
#if DEBUG_PBR_LIGHT_TYPE
|
||||
colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0);
|
||||
#endif
|
||||
final_color = colorDiffuse + colorSpec;
|
||||
}
|
||||
else
|
||||
|
|
@ -156,19 +148,8 @@ void main()
|
|||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
#if DEBUG_LEG_LIGHT_TYPE
|
||||
final_color.rgb = vec3(0,0.25,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG_POINT_ZERO
|
||||
final_color = vec3(0);
|
||||
#endif
|
||||
#if DEBUG_ANY_LIGHT_TYPE
|
||||
final_color = vec3(0.25,0,0.25);
|
||||
#endif
|
||||
|
||||
frag_color.rgb = final_color;
|
||||
frag_color.a = 0.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6381,6 +6381,9 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
|
|||
light_state->setDiffuse(light_color);
|
||||
light_state->setAmbient(LLColor4::black);
|
||||
light_state->setConstantAttenuation(0.f);
|
||||
light_state->setSize(light->getLightRadius() * 1.5f);
|
||||
light_state->setFalloff(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
|
||||
|
||||
if (sRenderDeferred)
|
||||
{
|
||||
light_state->setLinearAttenuation(linatten);
|
||||
|
|
|
|||
Loading…
Reference in New Issue