-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Create Option to Have Spotlights Use Rectangular Projection #24589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export default /* glsl */` | ||
export default /* glsl */ ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same unnecessary change |
||
/** | ||
* This is a template that can be used to light a material, it uses pluggable | ||
* RenderEquations (RE)for specific lighting scenarios. | ||
|
@@ -95,8 +95,6 @@ IncidentLight directLight; | |
|
||
spotLight = spotLights[ i ]; | ||
|
||
getSpotLightInfo( spotLight, geometry, directLight ); | ||
|
||
// spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none] | ||
#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) | ||
#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX | ||
|
@@ -105,6 +103,11 @@ IncidentLight directLight; | |
#else | ||
#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) | ||
#endif | ||
#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) | ||
getSpotLightInfo( spotLight, geometry, vSpotLightCoord[ i ], directLight ); | ||
#else | ||
getSpotLightInfo( spotLight, geometry, vec4(0.0), directLight ); | ||
#endif | ||
|
||
#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) | ||
spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export default /* glsl */` | ||
export default /* glsl */ ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unnecessary change |
||
uniform bool receiveShadow; | ||
uniform vec3 ambientLightColor; | ||
uniform vec3 lightProbe[ 9 ]; | ||
|
@@ -144,12 +144,17 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi | |
float decay; | ||
float coneCos; | ||
float penumbraCos; | ||
bool projector; | ||
}; | ||
|
||
uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; | ||
|
||
float sdBox( in vec2 p, in vec2 b ) | ||
{ | ||
vec2 d = abs(p)-b; | ||
return length(max(d,0.0)) + min(max(d.x,d.y),0.0); | ||
} | ||
Comment on lines
+151
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: spacing around the function and remove the newline before the first brace |
||
// light is an out parameter as having it as a return value caused compiler errors on some devices | ||
void getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light ) { | ||
void getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, const in vec4 spotCoord, out IncidentLight light ) { | ||
|
||
vec3 lVector = spotLight.position - geometry.position; | ||
|
||
|
@@ -158,7 +163,10 @@ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosi | |
float angleCos = dot( light.direction, spotLight.direction ); | ||
|
||
float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); | ||
|
||
if (spotLight.projector) { | ||
vec3 spotLightCoord = spotCoord.xyz / spotCoord.w; | ||
spotAttenuation = clamp((-2.0 * sdBox(spotLightCoord.xy - vec2(0.5), vec2(0.5, 0.5))) * (-1.0 / ((1.0 - acos(spotLight.penumbraCos)) - 1.0)), 0.0, 1.0); | ||
} | ||
Comment on lines
+166
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update this to use the three.js code style and remove the unnecessary parentheses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @N8python See the guide here, which includes tools for automatically formatting the code: https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2 |
||
if ( spotAttenuation > 0.0 ) { | ||
|
||
float lightDistance = length( lVector ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ function UniformsCache() { | |
distance: 0, | ||
coneCos: 0, | ||
penumbraCos: 0, | ||
decay: 0 | ||
decay: 0, | ||
projector: false | ||
}; | ||
break; | ||
|
||
|
@@ -126,7 +127,7 @@ function ShadowUniformsCache() { | |
}; | ||
break; | ||
|
||
// TODO (abelnation): set RectAreaLight shadow uniforms | ||
// TODO (abelnation): set RectAreaLight shadow uniforms | ||
|
||
} | ||
|
||
|
@@ -204,7 +205,9 @@ function WebGLLights( extensions, capabilities ) { | |
|
||
function setup( lights, physicallyCorrectLights ) { | ||
|
||
let r = 0, g = 0, b = 0; | ||
let r = 0, | ||
g = 0, | ||
b = 0; | ||
|
||
for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 ); | ||
|
||
|
@@ -289,9 +292,9 @@ function WebGLLights( extensions, capabilities ) { | |
uniforms.distance = distance; | ||
|
||
uniforms.coneCos = Math.cos( light.angle ); | ||
uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) ); | ||
uniforms.penumbraCos = Math.cos( light.angle * ( light.projector ? light.penumbra : 1 - ( light.penumbra ) ) ); | ||
uniforms.decay = light.decay; | ||
|
||
uniforms.projector = light.projector; | ||
state.spot[ spotLength ] = uniforms; | ||
|
||
const shadow = light.shadow; | ||
|
@@ -398,7 +401,7 @@ function WebGLLights( extensions, capabilities ) { | |
|
||
if ( capabilities.isWebGL2 ) { | ||
|
||
// WebGL 2 | ||
// WebGL 2ÍÍ | ||
Comment on lines
-401
to
+404
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like an inadvertent change |
||
|
||
state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1; | ||
state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2; | ||
|
@@ -434,14 +437,14 @@ function WebGLLights( extensions, capabilities ) { | |
const hash = state.hash; | ||
|
||
if ( hash.directionalLength !== directionalLength || | ||
hash.pointLength !== pointLength || | ||
hash.spotLength !== spotLength || | ||
hash.rectAreaLength !== rectAreaLength || | ||
hash.hemiLength !== hemiLength || | ||
hash.numDirectionalShadows !== numDirectionalShadows || | ||
hash.numPointShadows !== numPointShadows || | ||
hash.numSpotShadows !== numSpotShadows || | ||
hash.numSpotMaps !== numSpotMaps ) { | ||
hash.pointLength !== pointLength || | ||
hash.spotLength !== spotLength || | ||
hash.rectAreaLength !== rectAreaLength || | ||
hash.hemiLength !== hemiLength || | ||
hash.numDirectionalShadows !== numDirectionalShadows || | ||
hash.numPointShadows !== numPointShadows || | ||
hash.numSpotShadows !== numSpotShadows || | ||
hash.numSpotMaps !== numSpotMaps ) { | ||
Comment on lines
-437
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few places in the PR where indentation looks off. |
||
|
||
state.directional.length = directionalLength; | ||
state.spot.length = spotLength; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: code style (spaces inside parentheses and newlines within braces)