Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Bond committed Nov 26, 2024
1 parent 424db08 commit 534693e
Show file tree
Hide file tree
Showing 17 changed files with 1,208 additions and 1,394 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
"editor.formatOnSave": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,12 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {
#endif
#ifdef REALTIME_FILTERING
, ${this._vReflectionFilteringInfoName}
, icdfxSampler // ** not handled **
${isWebGPU ? `, icdfxSamplerSampler` : ""}
, icdfySampler // ** not handled **
${isWebGPU ? `, icdfySamplerSampler` : ""}
#ifdef IBL_CDF_FILTERING
, icdfxSampler // ** not handled **
${isWebGPU ? `, icdfxSamplerSampler` : ""}
, icdfySampler // ** not handled **
${isWebGPU ? `, icdfySamplerSampler` : ""}
#endif
#endif
);
#endif\n`;
Expand Down
7 changes: 5 additions & 2 deletions packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class PBRMaterialDefines extends MaterialDefines implements IImageProcess

public NUM_SAMPLES = "0";
public REALTIME_FILTERING = false;
public IBL_CDF_FILTERING = false;

public MAINUV1 = false;
public MAINUV2 = false;
Expand Down Expand Up @@ -1655,6 +1656,9 @@ export abstract class PBRBaseMaterial extends PushMaterial {
}

defines.REALTIME_FILTERING = true;
if (this.getScene().useEnvironmentCDFMaps) {
defines.IBL_CDF_FILTERING = true;
}
} else {
defines.REALTIME_FILTERING = false;
}
Expand Down Expand Up @@ -2302,8 +2306,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {

//if realtime filtering
//set the needed cdf maps
if (this.realTimeFiltering) {
this.getScene().useEnvironmentCDFMaps = true;
if (this.realTimeFiltering && this.getScene().useEnvironmentCDFMaps) {
ubo.setTexture("icdfxSampler", this.getScene().importanceSamplingRenderer?.getIcdfxTexture());
ubo.setTexture("icdfySampler", this.getScene().importanceSamplingRenderer?.getIcdfyTexture());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HDRFiltering {
private _effectRenderer: EffectRenderer;
private _effectWrapper: EffectWrapper;

private _lodGenerationOffset: number = -2;
private _lodGenerationOffset: number = 0;
private _lodGenerationScale: number = 0.8;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@

#define inline
vec3 irradiance(samplerCube inputTexture, vec3 inputN, vec2 filteringInfo
#ifdef REALTIME_FILTERING
#ifdef IBL_CDF_FILTERING
, sampler2D icdfxSampler, sampler2D icdfySampler
#endif
)
{
vec3 n = normalize(inputN);
vec3 result = vec3(0.0);

#ifndef REALTIME_FILTERING
#ifndef IBL_CDF_FILTERING
vec3 tangent = abs(n.z) < 0.999 ? vec3(0., 0., 1.) : vec3(1., 0., 0.);
tangent = normalize(cross(tangent, n));
vec3 bitangent = cross(n, tangent);
Expand All @@ -212,7 +212,7 @@
{
vec2 Xi = hammersley(i, NUM_SAMPLES);

#ifdef REALTIME_FILTERING
#ifdef IBL_CDF_FILTERING
vec2 T;
T.x = textureCubeLodEXT(icdfxSampler, vec2(Xi.x, 0.0), 0.0).x;
T.y = textureCubeLodEXT(icdfySampler, vec2(T.x, Xi.y), 0.0).x;
Expand All @@ -233,7 +233,7 @@
float l = log4(omegaS) - log4(omegaP) + log4(K);
float mipLevel = clamp(l, 0.0, maxLevel);

#ifdef REALTIME_FILTERING
#ifdef IBL_CDF_FILTERING
vec3 c = textureCubeLodEXT(inputTexture, Ls, mipLevel).rgb;
#else
vec3 c = textureCubeLodEXT(inputTexture, tbn * Ls, mipLevel).rgb;
Expand All @@ -242,7 +242,7 @@
c = toLinearSpace(c);
#endif

#ifdef REALTIME_FILTERING
#ifdef IBL_CDF_FILTERING
result += c * NoL;
#else
result += c;
Expand All @@ -256,11 +256,7 @@
}

#define inline
vec3 radiance(float alphaG, samplerCube inputTexture, vec3 inputN, vec2 filteringInfo
#ifdef REALTIME_FILTERING
, sampler2D icdfxSampler, sampler2D icdfySampler
#endif
)
vec3 radiance(float alphaG, samplerCube inputTexture, vec3 inputN, vec2 filteringInfo)
{
vec3 n = normalize(inputN);
vec3 c = textureCube(inputTexture, n).rgb; // Don't put it in the "if (alphaG == 0.)" branch for uniformity (analysis) reasons!
Expand Down Expand Up @@ -307,7 +303,6 @@
float mipLevel = clamp(float(l), 0.0, maxLevel);

weight += NoL;

vec3 c = textureCubeLodEXT(inputTexture, tbn * L, mipLevel).rgb;
#ifdef GAMMA_INPUT
c = toLinearSpace(c);
Expand Down
26 changes: 18 additions & 8 deletions packages/dev/core/src/Shaders/ShadersInclude/pbrBlockReflection.fx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@
#endif
#ifdef REALTIME_FILTERING
in vec2 vReflectionFilteringInfo,
in sampler2D icdfxSampler,
in sampler2D icdfySampler,
#ifdef IBL_CDF_FILTERING
in sampler2D icdfxSampler,
in sampler2D icdfySampler,
#endif
#endif
out vec4 environmentRadiance
)
Expand Down Expand Up @@ -120,7 +122,7 @@
float requestedReflectionLOD = reflectionLOD;
#endif
#ifdef REALTIME_FILTERING
environmentRadiance = vec4(radiance(alphaG, reflectionSampler, reflectionCoords, vReflectionFilteringInfo, icdfxSampler, icdfySampler), 1.0);
environmentRadiance = vec4(radiance(alphaG, reflectionSampler, reflectionCoords, vReflectionFilteringInfo), 1.0);
#else
environmentRadiance = sampleReflectionLod(reflectionSampler, reflectionCoords, reflectionLOD);
#endif
Expand Down Expand Up @@ -206,8 +208,10 @@
#endif
#ifdef REALTIME_FILTERING
, in vec2 vReflectionFilteringInfo
, in sampler2D icdfxSampler
, in sampler2D icdfySampler
#ifdef IBL_CDF_FILTERING
, in sampler2D icdfxSampler
, in sampler2D icdfySampler
#endif
#endif
)
{
Expand Down Expand Up @@ -254,8 +258,10 @@
#endif
#ifdef REALTIME_FILTERING
vReflectionFilteringInfo,
icdfxSampler,
icdfySampler,
#ifdef IBL_CDF_FILTERING
icdfxSampler,
icdfySampler,
#endif
#endif
environmentRadiance
);
Expand All @@ -282,7 +288,11 @@
#endif

#if defined(REALTIME_FILTERING)
environmentIrradiance = irradiance(reflectionSampler, irradianceVector, vReflectionFilteringInfo, icdfxSampler, icdfySampler);
environmentIrradiance = irradiance(reflectionSampler, irradianceVector, vReflectionFilteringInfo
#ifdef IBL_CDF_FILTERING
, icdfxSampler, icdfySampler
#endif
);
#else
environmentIrradiance = computeEnvironmentIrradiance(irradianceVector);
#endif
Expand Down
24 changes: 22 additions & 2 deletions packages/dev/core/src/Shaders/ShadersInclude/pbrBlockSubSurface.fx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ struct subSurfaceOutParams
#endif
#ifdef REALTIME_FILTERING
, in vec2 vRefractionFilteringInfo
#ifdef IBL_CDF_FILTERING
, in sampler2D icdfxSampler
, in sampler2D icdfySampler
#endif
#endif
#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
, in vec3 refractionPosition
Expand Down Expand Up @@ -120,7 +124,7 @@ struct subSurfaceOutParams
#endif

#if defined(REALTIME_FILTERING) && defined(SS_REFRACTIONMAP_3D)
environmentRefraction = vec4(radiance(alphaG, refractionSampler, refractionCoords, vRefractionFilteringInfo, sampler2D icdfxSampler, sampler2D icdfySampler), 1.0);
environmentRefraction = vec4(radiance(alphaG, refractionSampler, refractionCoords, vRefractionFilteringInfo), 1.0);
#else
environmentRefraction = sampleRefractionLod(refractionSampler, refractionCoords, requestedRefractionLOD);
#endif
Expand Down Expand Up @@ -180,6 +184,10 @@ struct subSurfaceOutParams
#if defined(REALTIME_FILTERING)
, in samplerCube reflectionSampler
, in vec2 vReflectionFilteringInfo
#ifdef IBL_CDF_FILTERING
, in sampler2D icdfxSampler
, in sampler2D icdfySampler
#endif
#endif
#endif
#ifdef USEIRRADIANCEMAP
Expand Down Expand Up @@ -230,6 +238,10 @@ struct subSurfaceOutParams
#endif
#ifdef REALTIME_FILTERING
, in vec2 vRefractionFilteringInfo
#ifdef IBL_CDF_FILTERING
, in sampler2D icdfxSampler
, in sampler2D icdfySampler
#endif
#endif
#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
, in vec3 refractionPosition
Expand Down Expand Up @@ -386,6 +398,10 @@ struct subSurfaceOutParams
#endif
#ifdef REALTIME_FILTERING
, vRefractionFilteringInfo
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
, refractionPosition
Expand Down Expand Up @@ -490,7 +506,11 @@ struct subSurfaceOutParams

#if defined(USESPHERICALFROMREFLECTIONMAP)
#if defined(REALTIME_FILTERING)
vec3 refractionIrradiance = irradiance(reflectionSampler, -irradianceVector, vReflectionFilteringInfo, icdfxSampler, icdfySampler);
vec3 refractionIrradiance = irradiance(reflectionSampler, -irradianceVector, vReflectionFilteringInfo
#ifdef IBL_CDF_FILTERING
, icdfxSampler, icdfySampler
#endif
);
#else
vec3 refractionIrradiance = computeEnvironmentIrradiance(-irradianceVector);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@
#endif
#endif

#ifdef REALTIME_FILTERING
uniform sampler2D icdfxSampler;
uniform sampler2D icdfySampler;
#endif

#ifdef REFLECTIONMAP_SKYBOX
varying vec3 vPositionUVW;
#else
Expand Down Expand Up @@ -120,4 +115,9 @@
#include<samplerFragmentDeclaration>(_DEFINENAME_,SS_REFRACTIONINTENSITY_TEXTURE,_VARYINGNAME_,RefractionIntensity,_SAMPLERNAME_,refractionIntensity)
#include<samplerFragmentDeclaration>(_DEFINENAME_,SS_TRANSLUCENCYINTENSITY_TEXTURE,_VARYINGNAME_,TranslucencyIntensity,_SAMPLERNAME_,translucencyIntensity)
#include<samplerFragmentDeclaration>(_DEFINENAME_,SS_TRANSLUCENCYCOLOR_TEXTURE,_VARYINGNAME_,TranslucencyColor,_SAMPLERNAME_,translucencyColor)
#endif

#ifdef IBL_CDF_FILTERING
uniform sampler2D icdfxSampler;
uniform sampler2D icdfySampler;
#endif
30 changes: 20 additions & 10 deletions packages/dev/core/src/Shaders/pbr.fragment.fx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ void main(void) {
#endif
#ifdef REALTIME_FILTERING
, vReflectionFilteringInfo
, icdfxSampler
, icdfySampler
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
);
#else
Expand Down Expand Up @@ -358,8 +360,10 @@ void main(void) {
#endif
#ifdef REALTIME_FILTERING
, vReflectionFilteringInfo
, icdfxSampler
, icdfySampler
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
#if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
, seo
Expand Down Expand Up @@ -479,8 +483,10 @@ void main(void) {
#endif
#ifdef REALTIME_FILTERING
, vReflectionFilteringInfo
, icdfxSampler
, icdfySampler
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
#endif
#if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
Expand Down Expand Up @@ -539,8 +545,10 @@ void main(void) {
#if defined(REALTIME_FILTERING)
, reflectionSampler
, vReflectionFilteringInfo
, icdfxSampler
, icdfySampler
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
#endif
#ifdef USEIRRADIANCEMAP
Expand Down Expand Up @@ -579,8 +587,10 @@ void main(void) {
#endif
#ifdef REALTIME_FILTERING
, vRefractionFilteringInfo
, icdfxSampler
, icdfySampler
#ifdef IBL_CDF_FILTERING
, icdfxSampler
, icdfySampler
#endif
#endif
#ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
, vRefractionPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@
return result;
}

fn radiance(alphaG: f32, inputTexture: texture_cube<f32>, inputSampler: sampler, inputN: vec3f, filteringInfo: vec2f
#ifdef REALTIME_FILTERING
, icdfxSampler: sampler, icdfySampler: sampler
#endif
) -> vec3f
fn radiance(alphaG: f32, inputTexture: texture_cube<f32>, inputSampler: sampler, inputN: vec3f, filteringInfo: vec2f) -> vec3f
{
var n: vec3f = normalize(inputN);
var c: vec3f = textureSample(inputTexture, inputSampler, n).rgb; // Don't put it in the "if (alphaG == 0.)" branch for uniformity (analysis) reasons!
Expand Down
Loading

0 comments on commit 534693e

Please sign in to comment.