Skip to content

Viewer: Add shadow support #16459

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

Merged
merged 115 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
190e6d9
add basic shadow
alexandremottet Mar 13, 2025
5bed6b6
temp add ibl shadows
alexandremottet Mar 18, 2025
de3390e
Merge branch 'master' into add-shadow-support
alexandremottet Mar 18, 2025
43e29e8
fix import
alexandremottet Mar 18, 2025
ec72de2
add testing
alexandremottet Mar 19, 2025
0e8d342
add
alexandremottet Mar 19, 2025
d379ee5
add wgsl shader
alexandremottet Mar 20, 2025
6328c80
add shadow
alexandremottet Mar 25, 2025
13ff791
Merge branch 'master' into add-shadow-support
alexandremottet Mar 25, 2025
bd7d6cb
add build config for materials
alexandremottet Mar 25, 2025
b68b183
fix ground issue
alexandremottet Mar 25, 2025
62a80da
change to WebGPU by default to test
alexandremottet Mar 25, 2025
396a3ad
add shadow only for webgl
alexandremottet Mar 26, 2025
d803a92
fix webgpu shadows
alexandremottet Mar 27, 2025
12149f4
fix snapshotHelper
alexandremottet Mar 27, 2025
25536c1
temp disable snapshotrendering
alexandremottet Mar 28, 2025
4038f54
remove mesh and material on ibl dispose
alexandremottet Mar 28, 2025
afea2b6
fix shadows dispose and snapshot rendering
alexandremottet Mar 31, 2025
ef075ff
fix dispose and add a _updateShadows
alexandremottet Mar 31, 2025
e9997b8
remove unused code
alexandremottet Mar 31, 2025
48d467b
add back markSceneAsMutated
alexandremottet Mar 31, 2025
4232a91
use directionallight instead of spotlight for now
alexandremottet Mar 31, 2025
3da0d2b
use light for only the ground
alexandremottet Mar 31, 2025
25f3523
make ibl shaders works with transparent clearColor
alexandremottet Mar 31, 2025
44184fd
externalize custom ground shaders
alexandremottet Mar 31, 2025
aee2c8c
Merge branch 'master' into add-shadow-support
alexandremottet Apr 1, 2025
5d4a86c
Merge branch 'master' into add-shadow-support
alexandremottet Apr 2, 2025
d5fbb5a
Merge branch 'master' into add-shadow-support
alexandremottet Apr 2, 2025
61aef6d
update shadows when the model change
alexandremottet Apr 2, 2025
e2388ad
Merge branch 'master' into add-shadow-support
alexandremottet Apr 4, 2025
25ba8aa
reset ibl shadow accumulation when env is rotated
alexandremottet Apr 4, 2025
215aa77
update
alexandremottet Apr 4, 2025
e916577
resetModel for shadows
alexandremottet Apr 4, 2025
cb935b1
put back params
alexandremottet Apr 4, 2025
b28a831
ibl shadows only on onShadowTextureReadyObservable is called
alexandremottet Apr 4, 2025
202dcd0
update
alexandremottet Apr 7, 2025
aa869fd
add back menu
alexandremottet Apr 7, 2025
75cfbbe
now skybox is created is environment is asked to be visible
alexandremottet Apr 7, 2025
04feff6
update to shadowQuality with new viewer options
alexandremottet Apr 7, 2025
93fb870
fix shadows
alexandremottet Apr 7, 2025
f55cb05
add ibl shadows render timer
alexandremottet Apr 8, 2025
f7a85a4
create a updateMaterial function to update ibll shadows
alexandremottet Apr 8, 2025
a85ab65
remove log
alexandremottet Apr 8, 2025
88c88ed
remove await
alexandremottet Apr 8, 2025
830f808
now the env visibility is unchecked by default in the demo
alexandremottet Apr 8, 2025
1cf82d9
remove log
alexandremottet Apr 8, 2025
579331b
put back the default ufo asset
alexandremottet Apr 8, 2025
83625e0
reduce classic shadow code
alexandremottet Apr 8, 2025
18d347a
fix environment rotation
alexandremottet Apr 9, 2025
7c41329
add materials dependency for the configurator
alexandremottet Apr 9, 2025
b2e41bd
_updateShadows is now protected
alexandremottet Apr 11, 2025
268e204
now the shadow ground is always bellow the models
alexandremottet Apr 11, 2025
aa0cd1e
remove unused code
alexandremottet Apr 15, 2025
a834d0b
remove code
alexandremottet Apr 15, 2025
f3576c4
mark render flag as true
alexandremottet Apr 15, 2025
8ea6b58
move viewer shaders to viewer package
alexandremottet Apr 15, 2025
f6db020
Merge branch 'master' into add-shadow-support
alexandremottet Apr 16, 2025
185b69f
add missing jsdoc
alexandremottet Apr 16, 2025
8b8dcce
add missing clearTimeout on shadow dispose
alexandremottet Apr 16, 2025
87369c1
remove unnecessary imports
alexandremottet Apr 16, 2025
804c41c
factorise imports for ibl shadows
alexandremottet Apr 16, 2025
1ce309d
refresh package-lock
alexandremottet Apr 16, 2025
22bb7cc
fix change light intensity for shadows
alexandremottet Apr 16, 2025
a3c504a
remove unnecessary null default value
alexandremottet Apr 16, 2025
7f3fd04
move default webgpu options to viewerfactory
alexandremottet Apr 16, 2025
0584a82
decrease max intensity to avoid burning
alexandremottet Apr 16, 2025
470ee06
add comment
alexandremottet Apr 16, 2025
bc595f5
use worldbound as default size for ground
alexandremottet Apr 16, 2025
0c97dd8
now webgpu are directly apply in the constructor to avoid override
alexandremottet Apr 16, 2025
2e8efee
comment debug lines
alexandremottet Apr 16, 2025
24cd3a8
rework async imports for shadows
alexandremottet Apr 16, 2025
c6ddf65
now CreateDisc is loading asynchronously
alexandremottet Apr 17, 2025
86eb705
create a coerceShadowQuality
alexandremottet Apr 17, 2025
fba37a1
add abort controller for shadows
alexandremottet Apr 17, 2025
7a0b398
update reset to respect default shadow quality value
alexandremottet Apr 17, 2025
917be37
add env property bindings
Apr 24, 2025
f20f156
rework auto mode for environment
alexandremottet Apr 28, 2025
9403e10
move shadow ground to the bounds bottom
alexandremottet Apr 28, 2025
45961a3
make sure there is an env for shadows
alexandremottet Apr 28, 2025
9bcee0b
rename material name
alexandremottet Apr 28, 2025
ab2ee08
rename shadows variable between map and env
alexandremottet Apr 28, 2025
62404ef
add comments
alexandremottet Apr 28, 2025
4a60b16
remove unsafe cast
alexandremottet Apr 28, 2025
0aae538
rework the way shadow dispose are done
alexandremottet Apr 28, 2025
69cf996
clear shadow observables on dispose
Apr 28, 2025
d3351d9
add shouldRender comment
Apr 28, 2025
db58fbe
update shadow map ground size on model update
alexandremottet Apr 28, 2025
e8db836
Small fixes
ryantrem Apr 28, 2025
8a9fb7f
Merge pull request #8 from ryantrem/add-shadow-support
alexandremottet Apr 29, 2025
9200ac1
update
Apr 29, 2025
e10f9d4
remove unused method
alexandremottet Apr 29, 2025
6359542
add back updateEnv
alexandremottet Apr 29, 2025
4c9d7b4
add back function for env and shadows
alexandremottet Apr 30, 2025
7788326
update
alexandremottet Apr 30, 2025
f7574a9
Merge remote-tracking branch 'origin/master' into add-shadow-support
ryantrem Apr 30, 2025
d71e7c7
Rework _updateEnvironment
ryantrem May 1, 2025
5a33e33
Add some missing awaits
ryantrem May 1, 2025
11bb999
Add shouldRender for classic shadows
ryantrem May 1, 2025
512ef06
Ignore abort errors from updating shadows as a side effect of updatin…
ryantrem May 2, 2025
2bc13e4
Add explicit imports for shadowOnly shaders
ryantrem May 2, 2025
be8cbd7
Add comment on shadow map readiness
ryantrem May 2, 2025
409064b
Merge pull request #9 from ryantrem/add-shadow-support
alexandremottet May 6, 2025
f3ecea1
prevent env shadow from being enable when there is no mesh
alexandremottet May 6, 2025
43474c6
use spotlight shadow
May 6, 2025
6d5674f
configure shadow to work with different assets
alexandremottet May 9, 2025
377811a
updateShadow on model selection change
alexandremottet May 9, 2025
239bd6d
Merge pull request #10 from alexandremottet/spotlight-shadow
alexandremottet May 12, 2025
55455e3
remove old DirectionalLight code
May 12, 2025
ad32b86
Merge branch 'master' into add-shadow-support
alexandremottet May 12, 2025
f0ec276
fix build issue
alexandremottet May 12, 2025
02464e0
Fix issue where bounds are nan when no models are loaded and it puts …
ryantrem May 15, 2025
b54d5ff
Fix lint error
ryantrem May 15, 2025
9dedfb6
Disable lint error
ryantrem May 15, 2025
ec84014
Merge master
ryantrem May 15, 2025
79d6caf
Fix more lint errors
ryantrem May 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const commonConfig = {
entries: [
{ find: "core", replacement: `@${source}/core/dist` },
{ find: "loaders", replacement: `@${source}/loaders/dist` },
{ find: "materials", replacement: `@${source}/materials/dist` },
],
}),
nodeResolve({ mainFields: ["browser", "module", "main"] }),
Expand Down
2 changes: 1 addition & 1 deletion packages/public/@babylonjs/viewer/rollup.config.lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";

const commonConfig = {
input: "../../../tools/viewer/src/index.ts",
external: (id) => /^@babylonjs\/(core|loaders)(\/|$)/.test(id),
external: (id) => /^@babylonjs\/(core|loaders|materials)(\/|$)/.test(id),
};

const jsConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/tools/viewer-configurator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@dnd-kit/sortable": "^10.0.0",
"@dev/core": "1.0.0",
"@dev/loaders": "1.0.0",
"@dev/materials": "1.0.0",
"@dev/shared-ui-components": "1.0.0",
"@tools/viewer": "1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ export const Configurator: FunctionComponent<{ viewerOptions: ViewerOptions; vie
);

const isEnvironmentLightingUrlValid = useMemo(() => {
return !lightingUrlConfig.configuredState || URL.canParse(lightingUrlConfig.configuredState) || lightingUrlConfig.configuredState === "auto";
return !lightingUrlConfig.configuredState || lightingUrlConfig.configuredState === "auto" || URL.canParse(lightingUrlConfig.configuredState);
}, [lightingUrlConfig.configuredState]);

const onEnvironmentLightingUrlChange = useCallback(
Expand All @@ -964,7 +964,7 @@ export const Configurator: FunctionComponent<{ viewerOptions: ViewerOptions; vie
);

const isEnvironmentSkyboxUrlValid = useMemo(() => {
return !skyboxUrlConfig.configuredState || URL.canParse(skyboxUrlConfig.configuredState);
return !skyboxUrlConfig.configuredState || skyboxUrlConfig.configuredState === "auto" || URL.canParse(skyboxUrlConfig.configuredState);
}, [skyboxUrlConfig.configuredState]);

const onEnvironmentSkyboxUrlChange = useCallback(
Expand Down
1 change: 1 addition & 0 deletions packages/tools/viewer-configurator/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"paths": {
"core/*": ["dev/core/dist/*"],
"loaders/*": ["dev/loaders/dist/*"],
"materials/*": ["dev/materials/dist/*"],
"shared-ui-components/*": ["dev/sharedUiComponents/dist/*"],
"viewer/*": ["tools/viewer/dist/*"],
"viewer": ["tools/viewer/dist/tsbuild/index"]
Expand Down
1 change: 1 addition & 0 deletions packages/tools/viewer-configurator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"paths": {
"core/*": ["dev/core/src/*"],
"loaders/*": ["dev/loaders/src/*"],
"materials/*": ["dev/materials/src/*"],
"shared-ui-components/*": ["dev/sharedUiComponents/src/*"],
"viewer/*": ["tools/viewer/src/*"],
"viewer": ["tools/viewer/src/index"]
Expand Down
1 change: 1 addition & 0 deletions packages/tools/viewer-configurator/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = (env) => {
alias: {
core: path.resolve("../../dev/core/dist"),
loaders: path.resolve("../../dev/loaders/dist"), // "src" results in unknown babylonjs-gltf2interface
materials: path.resolve("../../dev/materials/dist"),
viewer: path.resolve("../../tools/viewer/dist/tsbuild"), // "src" results in runtime viewer error
"shared-ui-components": path.resolve("../../dev/sharedUiComponents/src"),
},
Expand Down
1 change: 1 addition & 0 deletions packages/tools/viewer/rollup.config.common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function createConfig(outDir) {
entries: [
{ find: "core", replacement: `@${source}/core/dist` },
{ find: "loaders", replacement: `@${source}/loaders/dist` },
{ find: "materials", replacement: `@${source}/materials/dist` },
],
}),
nodeResolve({ mainFields: ["browser", "module", "main"] }),
Expand Down
23 changes: 23 additions & 0 deletions packages/tools/viewer/src/Shaders/envShadowGround.fragment.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
precision highp float;

// Sampler
uniform sampler2D shadowTexture;
uniform vec2 renderTargetSize;
uniform float shadowOpacity;
// Varying
varying vec2 vUV;

void main(void) {
float uvBasedOpacity = clamp(length(vUV * vec2(2.0) - vec2(1.0)), 0.0, 1.0);
uvBasedOpacity = uvBasedOpacity * uvBasedOpacity;
uvBasedOpacity = 1.0 - uvBasedOpacity;

vec2 screenUv = gl_FragCoord.xy / renderTargetSize;
vec3 shadowValue = texture2D(shadowTexture, screenUv).rrr;

float totalOpacity = shadowOpacity * uvBasedOpacity;
vec3 invertedShadowValue = vec3(1.0) - shadowValue;

gl_FragColor.rgb = shadowValue;
gl_FragColor.a = invertedShadowValue.r * totalOpacity;
}
16 changes: 16 additions & 0 deletions packages/tools/viewer/src/Shaders/envShadowGround.vertex.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
precision highp float;

// Attributes
attribute vec3 position;
attribute vec2 uv;

// Uniforms
uniform mat4 worldViewProjection;

// Varying
varying vec2 vUV;

void main(void) {
gl_Position = worldViewProjection * vec4(position, 1.0);
vUV = uv;
}
17 changes: 17 additions & 0 deletions packages/tools/viewer/src/ShadersWGSL/envShadowGround.fragment.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var shadowTextureSampler: sampler;
var shadowTexture : texture_2d<f32>;

uniform shadowOpacity : f32;
uniform renderTargetSize: vec2<f32>;

@fragment
fn main(input: FragmentInputs) -> FragmentOutputs {
let uvBasedOpacity = 1.0 - pow(clamp(length(input.vUV * vec2<f32>(2.0) - vec2<f32>(1.0)), 0.0, 1.0), 2.0);
let screenUv = fragmentInputs.position.xy / uniforms.renderTargetSize;

let shadowValue = textureSampleLevel(shadowTexture, shadowTextureSampler, screenUv, 0.0).rrr;
let totalOpacity = uniforms.shadowOpacity * uvBasedOpacity;
let finalShadowValue = mix(vec3<f32>(1.0), shadowValue, totalOpacity);
let invertedShadowValue = vec3(1.0) - shadowValue;
fragmentOutputs.color = vec4f(finalShadowValue, invertedShadowValue.r * totalOpacity);
}
14 changes: 14 additions & 0 deletions packages/tools/viewer/src/ShadersWGSL/envShadowGround.vertex.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
attribute position: vec3f;
attribute uv: vec2f;

uniform viewProjection: mat4x4f;
uniform worldViewProjection: mat4x4f;

// Output
varying vUV: vec2f;

@vertex
fn main(input : VertexInputs) -> FragmentInputs {
vertexOutputs.position = uniforms.worldViewProjection * vec4f(input.position, 1.0);
vertexOutputs.vUV = input.uv;
}
Loading