-
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shensi.zxd
committed
Sep 17, 2021
1 parent
8e2e9e7
commit 8e6636b
Showing
11 changed files
with
182 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
packages/core/src/shaderlib/pbr/direct_irradiance_frag.glsl
This file was deleted.
Oops, something went wrong.
94 changes: 73 additions & 21 deletions
94
packages/core/src/shaderlib/pbr/direct_irradiance_frag_define.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,121 @@ | ||
void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { | ||
void addDirectRadiance(vec3 incidentDirection, vec3 color, GeometricContext geometry, PhysicalMaterial material, inout ReflectedLight reflectedLight) { | ||
float dotNL = saturate( dot( geometry.normal, incidentDirection ) ); | ||
|
||
float dotNL = saturate( dot( geometry.normal, directLight.direction ) ); | ||
|
||
vec3 irradiance = dotNL * directLight.color; | ||
vec3 irradiance = dotNL * color; | ||
|
||
#ifndef PHYSICALLY_CORRECT_LIGHTS | ||
|
||
irradiance *= PI; // punctual light | ||
irradiance *= PI; | ||
|
||
#endif | ||
|
||
|
||
|
||
reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness ); | ||
reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( incidentDirection, geometry, material.specularColor, material.roughness); | ||
|
||
reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor ); | ||
|
||
} | ||
|
||
#ifdef O3_DIRECT_LIGHT_COUNT | ||
|
||
void addDirectionalDirectLightRadiance(DirectLight directionalLight, GeometricContext geometry, PhysicalMaterial material, inout ReflectedLight reflectedLight) { | ||
vec3 color = directionalLight.color; | ||
vec3 direction = -directionalLight.direction; | ||
|
||
#ifdef O3_DIRECT_LIGHT_COUNT | ||
addDirectRadiance( direction, color, geometry, material, reflectedLight ); | ||
|
||
void getDirectionalDirectLightIrradiance( const in DirectLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) { | ||
directLight.color = directionalLight.color; | ||
directLight.direction = -directionalLight.direction; | ||
} | ||
|
||
#endif | ||
|
||
#ifdef O3_POINT_LIGHT_COUNT | ||
|
||
// directLight is an out parameter as having it as a return value caused compiler errors on some devices | ||
void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) { | ||
void addPointDirectLightRadiance(PointLight pointLight, GeometricContext geometry, PhysicalMaterial material, inout ReflectedLight reflectedLight) { | ||
|
||
vec3 lVector = pointLight.position - geometry.position; | ||
directLight.direction = normalize( lVector ); | ||
vec3 direction = normalize( lVector ); | ||
|
||
float lightDistance = length( lVector ); | ||
|
||
directLight.color = pointLight.color; | ||
directLight.color *= clamp(1.0 - pow(lightDistance/pointLight.distance, 4.0), 0.0, 1.0); | ||
vec3 color = pointLight.color; | ||
color *= clamp(1.0 - pow(lightDistance/pointLight.distance, 4.0), 0.0, 1.0); | ||
|
||
addDirectRadiance( direction, color, geometry, material, reflectedLight ); | ||
|
||
} | ||
|
||
#endif | ||
|
||
#ifdef O3_SPOT_LIGHT_COUNT | ||
|
||
// directLight is an out parameter as having it as a return value caused compiler errors on some devices | ||
void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) { | ||
void addSpotDirectLightRadiance(SpotLight spotLight, GeometricContext geometry, PhysicalMaterial material, inout ReflectedLight reflectedLight) { | ||
|
||
vec3 lVector = spotLight.position - geometry.position; | ||
directLight.direction = normalize( lVector ); | ||
vec3 direction = normalize( lVector ); | ||
|
||
float lightDistance = length( lVector ); | ||
float angleCos = dot( directLight.direction, -spotLight.direction ); | ||
float angleCos = dot( direction, -spotLight.direction ); | ||
|
||
float spotEffect = smoothstep( spotLight.penumbraCos, spotLight.angleCos, angleCos ); | ||
float decayEffect = clamp(1.0 - pow(lightDistance/spotLight.distance, 4.0), 0.0, 1.0); | ||
|
||
directLight.color = spotLight.color; | ||
directLight.color *= spotEffect * decayEffect; | ||
vec3 color = spotLight.color; | ||
color *= spotEffect * decayEffect; | ||
|
||
addDirectRadiance( direction, color, geometry, material, reflectedLight ); | ||
|
||
} | ||
|
||
|
||
#endif | ||
|
||
void addTotalDirectRadiance(GeometricContext geometry, PhysicalMaterial material, inout ReflectedLight reflectedLight){ | ||
#ifdef O3_DIRECT_LIGHT_COUNT | ||
|
||
DirectLight directionalLight; | ||
|
||
for ( int i = 0; i < O3_DIRECT_LIGHT_COUNT; i ++ ) { | ||
|
||
directionalLight.color = u_directLightColor[i]; | ||
directionalLight.direction = u_directLightDirection[i]; | ||
|
||
addDirectionalDirectLightRadiance( directionalLight, geometry, material, reflectedLight ); | ||
} | ||
|
||
#endif | ||
|
||
#ifdef O3_POINT_LIGHT_COUNT | ||
|
||
PointLight pointLight; | ||
|
||
for ( int i = 0; i < O3_POINT_LIGHT_COUNT; i ++ ) { | ||
|
||
pointLight.color = u_pointLightColor[i]; | ||
pointLight.position = u_pointLightPosition[i]; | ||
pointLight.distance = u_pointLightDistance[i]; | ||
|
||
addPointDirectLightRadiance( pointLight, geometry, material, reflectedLight ); | ||
} | ||
|
||
#endif | ||
|
||
#ifdef O3_SPOT_LIGHT_COUNT | ||
|
||
SpotLight spotLight; | ||
|
||
for ( int i = 0; i < O3_SPOT_LIGHT_COUNT; i ++ ) { | ||
|
||
spotLight.color = u_spotLightColor[i]; | ||
spotLight.position = u_spotLightPosition[i]; | ||
spotLight.direction = u_spotLightDirection[i]; | ||
spotLight.distance = u_spotLightDistance[i]; | ||
spotLight.angleCos = u_spotLightAngleCos[i]; | ||
spotLight.penumbraCos = u_spotLightPenumbraCos[i]; | ||
|
||
addSpotDirectLightRadiance( spotLight, geometry, material, reflectedLight ); | ||
} | ||
|
||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.