-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Showing
37 changed files
with
782 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#define WZ_MAX_POINT_LIGHTS 0 | ||
#define WZ_MAX_INDEXED_POINT_LIGHTS 0 | ||
#define WZ_BUCKED_DIMENSION 0 | ||
|
||
uniform vec4 PointLightsPosition[WZ_MAX_POINT_LIGHTS]; | ||
uniform vec4 PointLightsColorAndEnergy[WZ_MAX_POINT_LIGHTS]; | ||
uniform ivec4 bucketOffsetAndSize[WZ_BUCKED_DIMENSION * WZ_BUCKED_DIMENSION]; | ||
uniform ivec4 PointLightsIndex[WZ_MAX_INDEXED_POINT_LIGHTS]; | ||
uniform float viewportWidth; | ||
uniform float viewportHeight; | ||
|
||
// See https://lisyarus.github.io/blog/graphics/2022/07/30/point-light-attenuation.html for explanation | ||
// we want something that looks somewhat physically correct, but must absolutely be 0 past range | ||
float pointLightEnergyAtPosition(vec3 position, vec3 pointLightWorldPosition, float range) | ||
{ | ||
vec3 pointLightVector = position - pointLightWorldPosition; | ||
float normalizedDistance = length(pointLightVector) / range; | ||
|
||
float sqNormDist = normalizedDistance * normalizedDistance; | ||
float numerator = max(1 - sqNormDist, 0); | ||
return numerator * numerator / ( 1 + 2 * sqNormDist); | ||
} | ||
|
||
vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4 albedo, float gloss, vec3 pointLightWorldPosition, float pointLightEnergy, vec3 pointLightColor, mat3 normalWorldSpaceToLocalSpace) | ||
{ | ||
vec3 pointLightVector = WorldFragPos - pointLightWorldPosition; | ||
vec3 pointLightDir = -normalize(pointLightVector * normalWorldSpaceToLocalSpace); | ||
|
||
float energy = pointLightEnergyAtPosition(WorldFragPos, pointLightWorldPosition, pointLightEnergy); | ||
vec4 lightColor = vec4(pointLightColor * energy, 1); | ||
|
||
float pointLightLambert = max(dot(fragNormal, pointLightDir), 0.0); | ||
|
||
vec3 pointLightHalfVec = normalize(viewVector + pointLightDir); | ||
|
||
float pointLightBlinn = pow(clamp(dot(fragNormal, pointLightHalfVec), 0.f, 1.f), 16.f); | ||
return lightColor * pointLightLambert * (albedo + pointLightBlinn * (gloss * gloss)); | ||
} | ||
|
||
// Unused for now | ||
// vec4 processPointLightScattering(vec3 pointLightWorldPosition, float pointLightEnergy, vec4 pointLightColor) | ||
// { | ||
// // manual integration | ||
// vec3 viewLine = fragPos - cameraPos.xyz; | ||
// vec3 result = vec3(0); | ||
// for (int i = 0; i < 10; i++) | ||
// { | ||
// result += pointLightEnergyAtPosition(fragPos + i * viewLine / 10, pointLightWorldPosition, pointLightEnergy) / 10; | ||
// } | ||
// return vec4(result * pointLightColor.xyz * fogColor.xyz, 1); | ||
// } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// See https://lisyarus.github.io/blog/graphics/2022/07/30/point-light-attenuation.html for explanation | ||
// we want something that looks somewhat physically correct, but must absolutely be 0 past range | ||
float pointLightEnergyAtPosition(vec3 position, vec3 pointLightWorldPosition, float range) | ||
{ | ||
vec3 pointLightVector = position - pointLightWorldPosition; | ||
float normalizedDistance = length(pointLightVector) / range; | ||
|
||
float sqNormDist = normalizedDistance * normalizedDistance; | ||
float numerator = max(1 - sqNormDist, 0); | ||
return numerator * numerator / ( 1 + 2 * sqNormDist); | ||
} | ||
|
||
vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4 albedo, float gloss, vec3 pointLightWorldPosition, float pointLightEnergy, vec3 pointLightColor, mat3 normalWorldSpaceToLocalSpace) | ||
{ | ||
vec3 pointLightVector = WorldFragPos - pointLightWorldPosition; | ||
vec3 pointLightDir = -normalize(pointLightVector * normalWorldSpaceToLocalSpace); | ||
|
||
float energy = pointLightEnergyAtPosition(WorldFragPos, pointLightWorldPosition, pointLightEnergy); | ||
vec4 lightColor = vec4(pointLightColor * energy, 1); | ||
|
||
float pointLightLambert = max(dot(fragNormal, pointLightDir), 0.0); | ||
|
||
vec3 pointLightHalfVec = normalize(viewVector + pointLightDir); | ||
|
||
float pointLightBlinn = pow(clamp(dot(fragNormal, pointLightHalfVec), 0.f, 1.f), 16.f); | ||
return lightColor * pointLightLambert * (albedo + pointLightBlinn * (gloss * gloss)); | ||
} | ||
|
||
// Unused for now | ||
// vec4 processPointLightScattering(vec3 pointLightWorldPosition, float pointLightEnergy, vec4 pointLightColor) | ||
// { | ||
// // manual integration | ||
// vec3 viewLine = fragPos - cameraPos.xyz; | ||
// vec3 result = vec3(0); | ||
// for (int i = 0; i < 10; i++) | ||
// { | ||
// result += pointLightEnergyAtPosition(fragPos + i * viewLine / 10, pointLightWorldPosition, pointLightEnergy) / 10; | ||
// } | ||
// return vec4(result * pointLightColor.xyz * fogColor.xyz, 1); | ||
// } |
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
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.