Skip to content

Commit

Permalink
Propagated assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanedds committed Nov 9, 2024
1 parent 03b4b8b commit 7e13841
Show file tree
Hide file tree
Showing 65 changed files with 2,444 additions and 650 deletions.
79 changes: 62 additions & 17 deletions Nu/Nu.Pipe/Assets/Default/PhysicallyBasedDeferredLighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,41 @@ const float PI = 3.141592654;
const float REFLECTION_LOD_MAX = 7.0;
const float ATTENUATION_CONSTANT = 1.0;
const int LIGHTS_MAX = 32;
const int SHADOWS_MAX = 16;
const int SHADOW_TEXTURES_MAX = 16;
const int SHADOW_MAPS_MAX = 8;
const float SHADOW_FOV_MAX = 2.1;
const float SHADOW_SEAM_INSET = 0.001;
const float SHADOW_POINT_SAMPLE_SCALAR = 0.0025;
const int SHADOW_POINT_SAMPLE_OFFSETS_COUNT = 20;
const vec3 SHADOW_POINT_SAMPLE_OFFSETS[SHADOW_POINT_SAMPLE_OFFSETS_COUNT] =
vec3[](
vec3(1, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 0, 1)* SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 0, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 0, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 0, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR);

const vec4 SSVF_DITHERING[4] =
vec4[4](
vec4(0.0, 0.5, 0.125, 0.625),
vec4(0.75, 0.22, 0.875, 0.375),
vec4(0.1875, 0.6875, 0.0625, 0.5625),
vec4(0.9375, 0.4375, 0.8125, 0.3125));
vec4[4](
vec4(0.0, 0.5, 0.125, 0.625),
vec4(0.75, 0.22, 0.875, 0.375),
vec4(0.1875, 0.6875, 0.0625, 0.5625),
vec4(0.9375, 0.4375, 0.8125, 0.3125));

uniform vec3 eyeCenter;
uniform mat4 view;
Expand Down Expand Up @@ -67,20 +93,21 @@ uniform sampler2D ambientTexture;
uniform sampler2D irradianceTexture;
uniform sampler2D environmentFilterTexture;
uniform sampler2D ssaoTexture;
uniform sampler2D shadowTextures[SHADOWS_MAX];
uniform sampler2D shadowTextures[SHADOW_TEXTURES_MAX];
uniform samplerCube shadowMaps[SHADOW_MAPS_MAX];
uniform vec3 lightOrigins[LIGHTS_MAX];
uniform vec3 lightDirections[LIGHTS_MAX];
uniform vec3 lightColors[LIGHTS_MAX];
uniform float lightBrightnesses[LIGHTS_MAX];
uniform float lightAttenuationLinears[LIGHTS_MAX];
uniform float lightAttenuationQuadratics[LIGHTS_MAX];
uniform float lightCutoffs[LIGHTS_MAX];
uniform int lightDirectionals[LIGHTS_MAX];
uniform int lightTypes[LIGHTS_MAX];
uniform float lightConeInners[LIGHTS_MAX];
uniform float lightConeOuters[LIGHTS_MAX];
uniform int lightShadowIndices[LIGHTS_MAX];
uniform int lightsCount;
uniform mat4 shadowMatrices[SHADOWS_MAX];
uniform mat4 shadowMatrices[SHADOW_TEXTURES_MAX];

in vec2 texCoordsOut;

Expand Down Expand Up @@ -160,7 +187,7 @@ float depthViewToDepthBuffer(float depthView)
return (-depthView - nearPlane) / (farPlane - nearPlane);
}

float computeShadowScalar(vec4 position, bool lightDirectional, float lightConeOuter, mat4 shadowMatrix, sampler2D shadowTexture)
float computeShadowTextureScalar(vec4 position, bool lightDirectional, float lightConeOuter, mat4 shadowMatrix, sampler2D shadowTexture)
{
vec4 positionShadow = shadowMatrix * position;
vec3 shadowTexCoordsProj = positionShadow.xyz / positionShadow.w;
Expand All @@ -180,11 +207,26 @@ float computeShadowScalar(vec4 position, bool lightDirectional, float lightConeO
return 1.0;
}

float computeShadowMapScalar(vec4 position, vec3 lightOrigin, samplerCube shadowMap)
{
vec3 positionShadow = position.xyz - lightOrigin;
float shadowZ = length(positionShadow);
float shadowZExp = exp(-lightShadowExponent * 0.1 * shadowZ);
float shadowDepthExp = 0.0;
for (int i = 0; i < SHADOW_POINT_SAMPLE_OFFSETS_COUNT; ++i)
{
// NOTE: we divide at each step to avoid overflow with an already large number.
shadowDepthExp += texture(shadowMap, positionShadow / shadowZ + SHADOW_POINT_SAMPLE_OFFSETS[i]).y / SHADOW_POINT_SAMPLE_OFFSETS_COUNT;
}
float shadowScalar = clamp(shadowZExp * shadowDepthExp, 0.0, 1.0);
return pow(shadowScalar, lightShadowDensity);
}

vec3 computeFogAccumDirectional(vec4 position, int lightIndex)
{
vec3 result = vec3(0.0);
int shadowIndex = lightShadowIndices[lightIndex];
if (lightsCount > 0 && lightDirectionals[lightIndex] != 0 && shadowIndex >= 0)
if (lightsCount > 0 && lightTypes[lightIndex] == 2 && shadowIndex >= 0)
{
// compute shadow space
mat4 shadowMatrix = shadowMatrices[shadowIndex];
Expand Down Expand Up @@ -377,11 +419,12 @@ void main()
for (int i = 0; i < lightsCount; ++i)
{
// per-light radiance
bool lightDirectional = lightDirectionals[i] == 1;
vec3 lightOrigin = lightOrigins[i];
bool lightDirectional = lightTypes[i] == 2;
vec3 l, h, radiance;
if (!lightDirectional)
{
vec3 d = lightOrigins[i] - position.xyz;
vec3 d = lightOrigin - position.xyz;
l = normalize(d);
h = normalize(v + l);
float distanceSquared = dot(d, d);
Expand All @@ -407,10 +450,12 @@ void main()

// shadow scalar
int shadowIndex = lightShadowIndices[i];
float shadowScalar =
shadowIndex >= 0 ?
computeShadowScalar(position, lightDirectional, lightConeOuters[i], shadowMatrices[shadowIndex], shadowTextures[shadowIndex]) :
1.0;
float shadowScalar = 1.0f;
if (shadowIndex >= 0)
shadowScalar =
shadowIndex < SHADOW_TEXTURES_MAX ?
computeShadowTextureScalar(position, lightDirectional, lightConeOuters[i], shadowMatrices[shadowIndex], shadowTextures[shadowIndex]) :
computeShadowMapScalar(position, lightOrigin, shadowMaps[shadowIndex - SHADOW_TEXTURES_MAX]);

// cook-torrance brdf
float hDotV = max(dot(h, v), 0.0);
Expand Down
79 changes: 62 additions & 17 deletions Nu/Nu.Pipe/Assets/Default/PhysicallyBasedForwardStatic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,41 @@ const float GAMMA = 2.2;
const float ATTENUATION_CONSTANT = 1.0f;
const int LIGHT_MAPS_MAX = 2;
const int LIGHTS_MAX = 8;
const int SHADOWS_MAX = 16;
const int SHADOW_TEXTURES_MAX = 16;
const int SHADOW_MAPS_MAX = 4;
const float SHADOW_FOV_MAX = 2.1;
const float SHADOW_SEAM_INSET = 0.001;
const float SHADOW_POINT_SAMPLE_SCALAR = 0.0025;
const int SHADOW_POINT_SAMPLE_OFFSETS_COUNT = 20;
const vec3 SHADOW_POINT_SAMPLE_OFFSETS[SHADOW_POINT_SAMPLE_OFFSETS_COUNT] =
vec3[](
vec3(1, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, -1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, -1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 1, 0) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 0, 1)* SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 0, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(1, 0, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(-1, 0, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, 1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, -1, 1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, -1, -1) * SHADOW_POINT_SAMPLE_SCALAR,
vec3(0, 1, -1) * SHADOW_POINT_SAMPLE_SCALAR);

const vec4 SSVF_DITHERING[4] =
vec4[4](
vec4(0.0, 0.5, 0.125, 0.625),
vec4(0.75, 0.22, 0.875, 0.375),
vec4(0.1875, 0.6875, 0.0625, 0.5625),
vec4(0.9375, 0.4375, 0.8125, 0.3125));
vec4[4](
vec4(0.0, 0.5, 0.125, 0.625),
vec4(0.75, 0.22, 0.875, 0.375),
vec4(0.1875, 0.6875, 0.0625, 0.5625),
vec4(0.9375, 0.4375, 0.8125, 0.3125));

uniform vec3 eyeCenter;
uniform float lightCutoffMargin;
Expand All @@ -97,7 +123,8 @@ uniform samplerCube irradianceMap;
uniform samplerCube environmentFilterMap;
uniform samplerCube irradianceMaps[LIGHT_MAPS_MAX];
uniform samplerCube environmentFilterMaps[LIGHT_MAPS_MAX];
uniform sampler2D shadowTextures[SHADOWS_MAX];
uniform sampler2D shadowTextures[SHADOW_TEXTURES_MAX];
uniform samplerCube shadowMaps[SHADOW_MAPS_MAX];
uniform vec3 lightMapOrigins[LIGHT_MAPS_MAX];
uniform vec3 lightMapMins[LIGHT_MAPS_MAX];
uniform vec3 lightMapSizes[LIGHT_MAPS_MAX];
Expand All @@ -111,12 +138,12 @@ uniform float lightBrightnesses[LIGHTS_MAX];
uniform float lightAttenuationLinears[LIGHTS_MAX];
uniform float lightAttenuationQuadratics[LIGHTS_MAX];
uniform float lightCutoffs[LIGHTS_MAX];
uniform int lightDirectionals[LIGHTS_MAX];
uniform int lightTypes[LIGHTS_MAX];
uniform float lightConeInners[LIGHTS_MAX];
uniform float lightConeOuters[LIGHTS_MAX];
uniform int lightShadowIndices[LIGHTS_MAX];
uniform int lightsCount;
uniform mat4 shadowMatrices[SHADOWS_MAX];
uniform mat4 shadowMatrices[SHADOW_TEXTURES_MAX];

in vec4 positionOut;
in vec2 texCoordsOut;
Expand Down Expand Up @@ -225,7 +252,7 @@ vec3 fresnelSchlickRoughness(float cosTheta, vec3 f0, float roughness)
return f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}

float computeShadowScalar(vec4 position, bool lightDirectional, float lightConeOuter, mat4 shadowMatrix, sampler2D shadowTexture)
float computeShadowTextureScalar(vec4 position, bool lightDirectional, float lightConeOuter, mat4 shadowMatrix, sampler2D shadowTexture)
{
vec4 positionShadow = shadowMatrix * position;
vec3 shadowTexCoordsProj = positionShadow.xyz / positionShadow.w;
Expand All @@ -245,11 +272,26 @@ float computeShadowScalar(vec4 position, bool lightDirectional, float lightConeO
return 1.0;
}

float computeShadowMapScalar(vec4 position, vec3 lightOrigin, samplerCube shadowMap)
{
vec3 positionShadow = position.xyz - lightOrigin;
float shadowZ = length(positionShadow);
float shadowZExp = exp(-lightShadowExponent * 0.1 * shadowZ);
float shadowDepthExp = 0.0;
for (int i = 0; i < SHADOW_POINT_SAMPLE_OFFSETS_COUNT; ++i)
{
// NOTE: we divide at each step to avoid overflow with an already large number.
shadowDepthExp += texture(shadowMap, positionShadow / shadowZ + SHADOW_POINT_SAMPLE_OFFSETS[i]).y / SHADOW_POINT_SAMPLE_OFFSETS_COUNT;
}
float shadowScalar = clamp(shadowZExp * shadowDepthExp, 0.0, 1.0);
return pow(shadowScalar, lightShadowDensity);
}

vec3 computeFogAccumDirectional(vec4 position, int lightIndex)
{
vec3 result = vec3(0.0);
int shadowIndex = lightShadowIndices[lightIndex];
if (lightsCount > 0 && lightDirectionals[lightIndex] != 0 && shadowIndex >= 0)
if (lightsCount > 0 && lightTypes[lightIndex] == 2 && shadowIndex >= 0)
{
// compute shadow space
mat4 shadowMatrix = shadowMatrices[shadowIndex];
Expand Down Expand Up @@ -353,11 +395,12 @@ void main()
for (int i = 0; i < lightsCount; ++i)
{
// per-light radiance
bool lightDirectional = lightDirectionals[i] == 1;
vec3 lightOrigin = lightOrigins[i];
bool lightDirectional = lightTypes[i] == 2;
vec3 l, h, radiance;
if (!lightDirectional)
{
vec3 d = lightOrigins[i] - position.xyz;
vec3 d = lightOrigin - position.xyz;
l = normalize(d);
h = normalize(v + l);
float distanceSquared = dot(d, d);
Expand All @@ -383,10 +426,12 @@ void main()

// shadow scalar
int shadowIndex = lightShadowIndices[i];
float shadowScalar =
shadowIndex >= 0 ?
computeShadowScalar(position, lightDirectional, lightConeOuters[i], shadowMatrices[shadowIndex], shadowTextures[shadowIndex]) :
1.0;
float shadowScalar = 1.0f;
if (shadowIndex >= 0)
shadowScalar =
shadowIndex < SHADOW_TEXTURES_MAX ?
computeShadowTextureScalar(position, lightDirectional, lightConeOuters[i], shadowMatrices[shadowIndex], shadowTextures[shadowIndex]) :
computeShadowMapScalar(position, lightOrigin, shadowMaps[shadowIndex - SHADOW_TEXTURES_MAX]);

// cook-torrance brdf
float hDotV = max(dot(h, v), 0.0);
Expand Down
26 changes: 21 additions & 5 deletions Nu/Nu.Pipe/Assets/Default/PhysicallyBasedShadowAnimated.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ layout(location = 3) in vec4 boneIds;
layout(location = 4) in vec4 weights;
layout(location = 5) in mat4 model;

out vec4 positionOut;
out float depthDirectionalOut;

void main()
Expand All @@ -27,23 +28,38 @@ void main()

// compute output values
vec4 positionBlended = boneBlended * vec4(position, 1.0);
vec4 positionWorld = model * positionBlended;
gl_Position = projection * view * positionWorld;
positionOut = model * positionBlended;
gl_Position = projection * view * positionOut;
depthDirectionalOut = gl_Position.z / gl_Position.w;
}

#shader fragment
#version 410

uniform int lightShadowDirectional;
uniform vec3 eyeCenter;
uniform int lightType;
uniform float lightShadowExponent;

layout(location = 0) out vec2 depths;

in vec4 positionOut;
in float depthDirectionalOut;

void main()
{
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * (lightShadowDirectional == 0 ? gl_FragCoord.z : depthDirectionalOut));
switch (lightType)
{
case 0: // point light
depths.x = length(positionOut.xyz - eyeCenter);
depths.y = exp(lightShadowExponent * 0.1 * depths.x);
break;
case 1: // spot light
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * depths.x);
break;
case 2: // directional light
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * depthDirectionalOut);
break;
}
}
26 changes: 21 additions & 5 deletions Nu/Nu.Pipe/Assets/Default/PhysicallyBasedShadowStatic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,43 @@ uniform mat4 projection;
layout(location = 0) in vec3 position;
layout(location = 3) in mat4 model;

out vec4 positionOut;
out float depthDirectionalOut;

void main()
{
vec4 positionWorld = model * vec4(position, 1.0);
gl_Position = projection * view * positionWorld;
positionOut = model * vec4(position, 1.0);
gl_Position = projection * view * positionOut;
depthDirectionalOut = gl_Position.z / gl_Position.w;
}

#shader fragment
#version 410

uniform int lightShadowDirectional;
uniform vec3 eyeCenter;
uniform int lightType;
uniform float lightShadowExponent;

layout(location = 0) out vec2 depths;

in vec4 positionOut;
in float depthDirectionalOut;

void main()
{
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * (lightShadowDirectional == 0 ? gl_FragCoord.z : depthDirectionalOut));
switch (lightType)
{
case 0: // point light
depths.x = length(positionOut.xyz - eyeCenter);
depths.y = exp(lightShadowExponent * 0.1 * depths.x);
break;
case 1: // spot light
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * depths.x);
break;
case 2: // directional light
depths.x = gl_FragCoord.z;
depths.y = exp(lightShadowExponent * depthDirectionalOut);
break;
}
}
Loading

0 comments on commit 7e13841

Please sign in to comment.