diff --git a/packages/effect/grass/shader/GrassBaseShader.ts b/packages/effect/grass/shader/GrassBaseShader.ts index b3490c1b..df49e6a6 100644 --- a/packages/effect/grass/shader/GrassBaseShader.ts +++ b/packages/effect/grass/shader/GrassBaseShader.ts @@ -11,15 +11,10 @@ export let GrassBaseShader = /*wgsl*/ ` @location(4) vWorldPos: vec4, @location(5) vWorldNormal: vec3, @location(6) vColor: vec4, - - #if USE_SHADOWMAPING - @location(7) vShadowPos: vec4, - #endif - - #if USE_TANGENT - @location(8) TANGENT: vec4, - #endif - + @location(7) vShadowPos: vec4, + #if USE_TANGENT + @location(8) TANGENT: vec4, + #endif @builtin(front_facing) face: bool, @builtin(position) fragCoord : vec4 }; diff --git a/packages/effect/grass/shader/GrassVertexAttributeShader.ts b/packages/effect/grass/shader/GrassVertexAttributeShader.ts index d78f5208..8eebfab4 100644 --- a/packages/effect/grass/shader/GrassVertexAttributeShader.ts +++ b/packages/effect/grass/shader/GrassVertexAttributeShader.ts @@ -21,9 +21,7 @@ export let GrassVertexAttributeShader: string = /*wgsl*/ ` @location(5) varying_WPos: vec4, @location(6) varying_WNormal: vec3, @location(7) varying_Color: vec4, - #if USE_SHADOWMAPING - @location(8) varying_ShadowPos: vec4, - #endif + @location(8) varying_ShadowPos: vec4, @builtin(position) member: vec4 }; diff --git a/samples/lights/Sample_ShadowToggle.ts b/samples/lights/Sample_ShadowToggle.ts new file mode 100644 index 00000000..71cf55d5 --- /dev/null +++ b/samples/lights/Sample_ShadowToggle.ts @@ -0,0 +1,100 @@ +import { GUIHelp } from "@orillusion/debug/GUIHelp"; +import { Scene3D, HoverCameraController, Engine3D, AtmosphericComponent, Object3D, Camera3D, Vector3, View3D, DirectLight, KelvinUtil, LitMaterial, MeshRenderer, BoxGeometry, CameraUtil, SphereGeometry, Color, Object3DUtil, BlendMode } from "@orillusion/core"; +import { GUIUtil } from "@samples/utils/GUIUtil"; + +//sample of toggle shadow +class Sample_ShadowToggle { + scene: Scene3D; + async run() { + Engine3D.setting.shadow.enable = true; + Engine3D.setting.shadow.autoUpdate = true; + Engine3D.setting.shadow.shadowSize = 1024; + await Engine3D.init({}); + + GUIHelp.init(); + + this.scene = new Scene3D(); + let sky = this.scene.addComponent(AtmosphericComponent); + + // init camera3D + let mainCamera = CameraUtil.createCamera3D(null, this.scene); + // mainCamera.enableCSM = true; + mainCamera.perspective(60, Engine3D.aspect, 1, 5000.0); + //set camera data + mainCamera.object3D.z = -15; + mainCamera.object3D.addComponent(HoverCameraController).setCamera(-15, -35, 200); + + sky.relativeTransform = this.initLight(); + this.initScene(); + + let view = new View3D(); + view.scene = this.scene; + view.camera = mainCamera; + + Engine3D.startRenderView(view); + } + + // create direction light + private initLight() { + let lightObj3D = new Object3D(); + lightObj3D.rotationX = 46; + lightObj3D.rotationY = 62; + lightObj3D.rotationZ = 0; + let sunLight = lightObj3D.addComponent(DirectLight); + sunLight.intensity = 15; + sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(6553); + sunLight.castShadow = true; + + this.scene.addChild(lightObj3D); + GUIUtil.renderDirLight(sunLight, false); + return sunLight.transform; + } + + initScene() { + { + let geometry = new SphereGeometry(20, 20, 20); + let material = new LitMaterial(); + material.name = 'Box Material'; + let obj = new Object3D(); + obj.y = 20; + let mr = obj.addComponent(MeshRenderer); + mr.geometry = geometry; + mr.material = material; + + this.scene.addChild(obj); + GUIHelp.addFolder('MeshRenderer - Sphere'); + GUIHelp.add(mr, 'castShadow'); + GUIHelp.open(); + GUIHelp.endFolder(); + GUIUtil.renderLitMaterial(material, true); + } + + //add wall + { + let geometry = new BoxGeometry(40, 10, 80); + let material = new LitMaterial(); + let obj = new Object3D(); + obj.x = 40; + obj.y = 5; + let mr = obj.addComponent(MeshRenderer); + mr.geometry = geometry; + mr.material = material; + this.scene.addChild(obj); + } + + { + let material = new LitMaterial(); + material.name = 'Floor Material'; + + material.baseMap = Engine3D.res.grayTexture; + let floor = new Object3D(); + let mr = floor.addComponent(MeshRenderer); + mr.geometry = new BoxGeometry(10000, 1, 10000); + mr.material = material; + this.scene.addChild(floor); + GUIUtil.renderLitMaterial(material, true); + } + } +} + +new Sample_ShadowToggle().run(); diff --git a/samples/utils/GUIUtil.ts b/samples/utils/GUIUtil.ts index cb0b56c3..4c304db1 100644 --- a/samples/utils/GUIUtil.ts +++ b/samples/utils/GUIUtil.ts @@ -428,7 +428,7 @@ export class GUIUtil { GUIHelp.endFolder(); } - static renderLitMaterial(mat: LitMaterial) { + static renderLitMaterial(mat: LitMaterial, open?: boolean) { GUIHelp.addFolder(mat.name); GUIHelp.addColor(mat, 'baseColor').onChange((v) => { let color = mat.baseColor; @@ -463,6 +463,11 @@ export class GUIUtil { mat.metallic = v; }); + GUIHelp.add(mat, 'castShadow'); + GUIHelp.add(mat, 'acceptShadow'); + + open && GUIHelp.open(); + GUIHelp.endFolder(); } diff --git a/src/assets/shader/compute/DDGILighting_CSShader.ts b/src/assets/shader/compute/DDGILighting_CSShader.ts index 585e4b3e..b7805526 100644 --- a/src/assets/shader/compute/DDGILighting_CSShader.ts +++ b/src/assets/shader/compute/DDGILighting_CSShader.ts @@ -45,24 +45,23 @@ const PointLightType = 1; const DirectLightType = 2; const SpotLightType = 3; -@group(0) @binding(1) var outputBuffer : texture_storage_2d; -@group(0) @binding(2) var prefilterMapSampler: sampler; -@group(0) @binding(3) var prefilterMap: texture_cube; +@group(0) @binding(auto) var outputBuffer : texture_storage_2d; +@group(0) @binding(auto) var prefilterMapSampler: sampler; +@group(0) @binding(auto) var prefilterMap: texture_cube; -@group(1) @binding(0) var positionMapSampler : sampler; -@group(1) @binding(1) var positionMap : texture_2d; +@group(1) @binding(auto) var positionMapSampler : sampler; +@group(1) @binding(auto) var positionMap : texture_2d; -@group(1) @binding(2) var normalMapSampler : sampler; -@group(1) @binding(3) var normalMap : texture_2d; +@group(1) @binding(auto) var normalMapSampler : sampler; +@group(1) @binding(auto) var normalMap : texture_2d; -@group(1) @binding(4) var colorMapSampler : sampler; -@group(1) @binding(5) var colorMap : texture_2d; +@group(1) @binding(auto) var colorMapSampler : sampler; +@group(1) @binding(auto) var colorMap : texture_2d; -@group(1) @binding(6) var shadowMapSampler : sampler_comparison; -@group(1) @binding(7) var shadowMap : texture_depth_2d_array; - -@group(1) @binding(8) var pointShadowMapSampler: sampler; -@group(1) @binding(9) var pointShadowMap: texture_depth_cube_array ; +@group(1) @binding(auto) var shadowMapSampler : sampler_comparison; +@group(1) @binding(auto) var shadowMap : texture_depth_2d_array; +@group(1) @binding(auto) var pointShadowMapSampler: sampler; +@group(1) @binding(auto) var pointShadowMap: texture_depth_cube_array ; @group(2) @binding(0) var lightBuffer: array; @@ -104,24 +103,24 @@ fn directShadowMaping(P:vec3, N:vec3, shadowBias: f32) { let enableCSM:bool = globalUniform.enableCSM > 0.5; var light = lightBuffer[0]; var visibility = 1.0; - var shadowIndex = i32(light.castShadow); - if (shadowIndex >= 0 ) { - var shadowMatrix:mat4x4; - if(enableCSM && csmCount > 1){ - for(var csm:i32 = 0; csm < csmCount; csm ++){ - var csmShadowBias = globalUniform.csmShadowBias[csm]; - shadowMatrix = globalUniform.csmMatrix[csm]; - let csmShadowResult = directShadowMapingIndex(light, shadowMatrix, P, N, csm, csmShadowBias); - if(csmShadowResult.y < 0.5){ - visibility = csmShadowResult.x; - break; + var shadowIndex = i32(light.castShadow); + if (shadowIndex >= 0 ) { + var shadowMatrix:mat4x4; + if(enableCSM && csmCount > 1){ + for(var csm:i32 = 0; csm < csmCount; csm ++){ + var csmShadowBias = globalUniform.csmShadowBias[csm]; + shadowMatrix = globalUniform.csmMatrix[csm]; + let csmShadowResult = directShadowMapingIndex(light, shadowMatrix, P, N, csm, csmShadowBias); + if(csmShadowResult.y < 0.5){ + visibility = csmShadowResult.x; + break; + } } + }else{ + shadowMatrix = globalUniform.shadowMatrix[shadowIndex]; + visibility = directShadowMapingIndex(light, shadowMatrix, P, N, shadowIndex, shadowBias).x; } - }else{ - shadowMatrix = globalUniform.shadowMatrix[shadowIndex]; - visibility = directShadowMapingIndex(light, shadowMatrix, P, N, shadowIndex, shadowBias).x; } - } shadowStrut.directShadowVisibility = visibility; } diff --git a/src/assets/shader/core/struct/FragmentVarying.ts b/src/assets/shader/core/struct/FragmentVarying.ts index 8a0ccc99..aa29bed0 100644 --- a/src/assets/shader/core/struct/FragmentVarying.ts +++ b/src/assets/shader/core/struct/FragmentVarying.ts @@ -9,11 +9,7 @@ export let FragmentVarying: string = /*wgsl*/ ` @location(5) vWorldPos: vec4, @location(6) vWorldNormal: vec3, @location(7) vColor: vec4, - - #if USE_SHADOWMAPING - @location(8) vShadowPos: vec4, - #endif - + @location(8) vShadowPos: vec4, #if USE_TANGENT @location(9) TANGENT: vec4, #endif diff --git a/src/assets/shader/core/struct/VertexAttributeIndexShader.ts b/src/assets/shader/core/struct/VertexAttributeIndexShader.ts index 92cb7336..7315e39b 100644 --- a/src/assets/shader/core/struct/VertexAttributeIndexShader.ts +++ b/src/assets/shader/core/struct/VertexAttributeIndexShader.ts @@ -22,9 +22,7 @@ export let VertexAttributeIndexShader: string = /*wgsl*/ ` @location(5) varying_WPos: vec4, @location(6) varying_WNormal: vec3, @location(7) varying_Color: vec4, - #if USE_SHADOWMAPING - @location(8) varying_ShadowPos: vec4, - #endif + @location(8) varying_ShadowPos: vec4, @builtin(position) member: vec4 }; diff --git a/src/assets/shader/core/struct/VertexAttributes.ts b/src/assets/shader/core/struct/VertexAttributes.ts index 74031a90..06e586a9 100644 --- a/src/assets/shader/core/struct/VertexAttributes.ts +++ b/src/assets/shader/core/struct/VertexAttributes.ts @@ -89,14 +89,11 @@ export let VertexAttributes: string = /*wgsl*/ ` @location(5) varying_WPos: vec4, @location(6) varying_WNormal: vec3, @location(7) varying_Color: vec4, - - #if USE_SHADOWMAPING - @location(8) varying_ShadowPos: vec4, - #endif - + @location(8) varying_ShadowPos: vec4, #if USE_TANGENT @location(9) varying_Tangent: vec4, #endif + @builtin(position) member: vec4 }; diff --git a/src/assets/shader/materials/ColorLitShader.ts b/src/assets/shader/materials/ColorLitShader.ts index b5aa1638..73c70b64 100644 --- a/src/assets/shader/materials/ColorLitShader.ts +++ b/src/assets/shader/materials/ColorLitShader.ts @@ -18,9 +18,7 @@ export let ColorLitShader: string = /*wgsl*/` ORI_ShadingInput.Normal = ORI_VertexVarying.vWorldNormal.rgb ; - #if USE_SHADOWMAPING - useShadow(); - #endif + useShadow(); BxDFShading(); } diff --git a/src/assets/shader/materials/Hair_shader.ts b/src/assets/shader/materials/Hair_shader.ts index 3e5f59d4..9d860039 100644 --- a/src/assets/shader/materials/Hair_shader.ts +++ b/src/assets/shader/materials/Hair_shader.ts @@ -104,9 +104,7 @@ export let Hair_shader_op: string = /*wgsl*/ ` } #endif - #if USE_SHADOWMAPING - useShadow(); - #endif + useShadow(); ORI_ShadingInput.Specular = 1.0 ; diff --git a/src/assets/shader/materials/PBRLItShader.ts b/src/assets/shader/materials/PBRLItShader.ts index df611066..f553f995 100644 --- a/src/assets/shader/materials/PBRLItShader.ts +++ b/src/assets/shader/materials/PBRLItShader.ts @@ -81,9 +81,7 @@ export let PBRLItShader: string = /*wgsl*/ ` } #endif - #if USE_SHADOWMAPING - useShadow(); - #endif + useShadow(); var roughnessChannel:f32 = 1.0 ; #if USE_ROUGHNESS_A diff --git a/src/assets/shader/materials/PBRLitSSSShader.ts b/src/assets/shader/materials/PBRLitSSSShader.ts index 3a8ee687..900b4134 100644 --- a/src/assets/shader/materials/PBRLitSSSShader.ts +++ b/src/assets/shader/materials/PBRLitSSSShader.ts @@ -125,9 +125,7 @@ export let PBRLitSSSShader: string = /*wgsl*/ ` } #endif - #if USE_SHADOWMAPING - useShadow(); - #endif + useShadow(); // maskTex =vec4f( gammaToLiner(maskTex.rgb), maskTex.a ); diff --git a/src/assets/shader/materials/program/ShadowMapping_frag.ts b/src/assets/shader/materials/program/ShadowMapping_frag.ts index 62a839ad..eff82631 100644 --- a/src/assets/shader/materials/program/ShadowMapping_frag.ts +++ b/src/assets/shader/materials/program/ShadowMapping_frag.ts @@ -1,11 +1,8 @@ import { CSM } from "../../../../core/csm/CSM"; export let ShadowMapping_frag: string = /*wgsl*/ ` - #if USE_SHADOWMAPING @group(1) @binding(auto) var shadowMapSampler: sampler; @group(1) @binding(auto) var shadowMap: texture_depth_2d_array; - #endif - @group(1) @binding(auto) var pointShadowMapSampler: sampler; @group(1) @binding(auto) var pointShadowMap: texture_depth_cube_array; @@ -18,8 +15,10 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` fn useShadow(){ shadowStrut.directShadowVisibility = array( 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) ; shadowStrut.pointShadows = array( 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) ; - directShadowMaping(globalUniform.shadowBias); - pointShadowMapCompare(globalUniform.pointShadowBias); + #if USE_SHADOWMAPING + directShadowMaping(globalUniform.shadowBias); + pointShadowMapCompare(globalUniform.pointShadowBias); + #endif } fn calcBasicBias(shadowWorldSize:f32, shadowDepthTexSize:f32, near:f32, far:f32) -> f32{ @@ -33,7 +32,7 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` const csmCount:i32 = ${CSM.Cascades} ; var csmLevel:i32 = -1; fn directShadowMaping(shadowBias: f32) { - #if USE_SHADOWMAPING + let enableCSM:bool = globalUniform.enableCSM > 0.5; for (var i: i32 = 0; i < dirCount ; i = i + 1) { if( i >= globalUniform.nDirShadowStart && i < globalUniform.nDirShadowEnd ){ @@ -97,7 +96,7 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` shadowStrut.directShadowVisibility[i] = visibility; } } - #endif + } fn directShadowMapingIndex(light:LightData, matrix:mat4x4, depthTexIndex:i32, shadowBias:f32) -> vec4 @@ -105,40 +104,38 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` var visibility = 1.0; var isOutSideArea:f32 = 1.0; var varying_shadowUV:vec2 = vec2(0.0); - #if USE_SHADOWMAPING - var shadowPosTmp = matrix * vec4(ORI_VertexVarying.vWorldPos.xyz, 1.0); - var shadowPos = shadowPosTmp.xyz / shadowPosTmp.w; - varying_shadowUV = shadowPos.xy * vec2(0.5, -0.5) + vec2(0.5, 0.5); - if (varying_shadowUV.x <= 1.0 - && varying_shadowUV.x >= 0.0 - && varying_shadowUV.y <= 1.0 - && varying_shadowUV.y >= 0.0 - && shadowPosTmp.z <= 1.0 - && shadowPosTmp.z >= 0.0) - { - visibility = 0.0; - isOutSideArea = 0.0; - var uvOnePixel = 1.0 / vec2(globalUniform.shadowMapSize); - var totalWeight = 0.0; - var NoL = (dot(normalize(ORI_VertexVarying.vWorldNormal), normalize(-light.direction))); - let v = max(NoL, 0.0) ; - var bias = shadowBias / v; - for (var y = -1; y <= 1; y++) { - for (var x = -1; x <= 1; x++) { - var offset = vec2(f32(x), f32(y)) * uvOnePixel; - - // visibility += textureSampleCompare(shadowMap, shadowMapSampler, varying_shadowUV + offset, depthTexIndex, shadowPos.z - bias); - var depth = textureSampleLevel(shadowMap, shadowMapSampler, varying_shadowUV + offset, depthTexIndex, 0); - if ((shadowPos.z - bias ) < depth) { - visibility += 1.0 ; - } - totalWeight += 1.0; + var shadowPosTmp = matrix * vec4(ORI_VertexVarying.vWorldPos.xyz, 1.0); + var shadowPos = shadowPosTmp.xyz / shadowPosTmp.w; + varying_shadowUV = shadowPos.xy * vec2(0.5, -0.5) + vec2(0.5, 0.5); + if (varying_shadowUV.x <= 1.0 + && varying_shadowUV.x >= 0.0 + && varying_shadowUV.y <= 1.0 + && varying_shadowUV.y >= 0.0 + && shadowPosTmp.z <= 1.0 + && shadowPosTmp.z >= 0.0) + { + visibility = 0.0; + isOutSideArea = 0.0; + var uvOnePixel = 1.0 / vec2(globalUniform.shadowMapSize); + var totalWeight = 0.0; + var NoL = (dot(normalize(ORI_VertexVarying.vWorldNormal), normalize(-light.direction))); + let v = max(NoL, 0.0) ; + var bias = shadowBias / v; + for (var y = -1; y <= 1; y++) { + for (var x = -1; x <= 1; x++) { + var offset = vec2(f32(x), f32(y)) * uvOnePixel; + + // visibility += textureSampleCompare(shadowMap, shadowMapSampler, varying_shadowUV + offset, depthTexIndex, shadowPos.z - bias); + var depth = textureSampleLevel(shadowMap, shadowMapSampler, varying_shadowUV + offset, depthTexIndex, 0); + if ((shadowPos.z - bias ) < depth) { + visibility += 1.0 ; } + totalWeight += 1.0; } - visibility /= totalWeight; - visibility += 0.001; } - #endif + visibility /= totalWeight; + visibility += 0.001; + } return vec4(visibility, isOutSideArea, varying_shadowUV); } @@ -159,22 +156,22 @@ export let ShadowMapping_frag: string = /*wgsl*/ ` var len = length(frgToLight); var bias = max(shadowBias * globalUniform.far * (1.0 - dot(ORI_ShadingInput.Normal, dir)), 0.005); - #if USE_PCF_SHADOW - let samples = 4.0; - for (var x: f32 = -offset; x < offset; x += offset / (samples * 0.5)) { - for (var y: f32 = -offset; y < offset; y += offset / (samples * 0.5)) { - for (var z: f32 = -offset; z < offset; z += offset / (samples * 0.5)) { - let offsetDir = normalize(dir.xyz + vec3(x, y, z)); - var depth = textureSampleLevel(pointShadowMap, pointShadowMapSampler, offsetDir, light.castShadow, 0); - depth *= globalUniform.far; - if ((len - bias) > depth) { - shadow += 1.0 * dot(offsetDir, dir.xyz); + #if USE_PCF_SHADOW + let samples = 4.0; + for (var x: f32 = -offset; x < offset; x += offset / (samples * 0.5)) { + for (var y: f32 = -offset; y < offset; y += offset / (samples * 0.5)) { + for (var z: f32 = -offset; z < offset; z += offset / (samples * 0.5)) { + let offsetDir = normalize(dir.xyz + vec3(x, y, z)); + var depth = textureSampleLevel(pointShadowMap, pointShadowMapSampler, offsetDir, light.castShadow, 0); + depth *= globalUniform.far; + if ((len - bias) > depth) { + shadow += 1.0 * dot(offsetDir, dir.xyz); + } } } } - } - shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0); - #endif + shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0); + #endif #if USE_SOFT_SHADOW let vDis = length(globalUniform.CameraPos.xyz - worldPos.xyz); diff --git a/src/components/renderer/RenderNode.ts b/src/components/renderer/RenderNode.ts index 9e7ca94a..fc155b2c 100644 --- a/src/components/renderer/RenderNode.ts +++ b/src/components/renderer/RenderNode.ts @@ -427,6 +427,8 @@ export class RenderNode extends ComponentBase { let worldMatrix = node.object3D.transform._worldMatrix; for (let i = 0; i < this.materials.length; i++) { const material = this.materials[i]; + if (!material.castShadow && passType == PassType.SHADOW) + continue; // material.applyUniform(); let passes = material.getPass(passType); if (!passes || passes.length == 0) @@ -436,7 +438,6 @@ export class RenderNode extends ComponentBase { for (let matPass of passes) { // if (!matPass.enable) // continue; - if (matPass.pipeline) { GPUContext.bindPipeline(encoder, matPass); GPUContext.draw(encoder, 6, 1, 0, worldMatrix.index); @@ -447,7 +448,6 @@ export class RenderNode extends ComponentBase { for (let matPass of passes) { // if (!matPass.enable) // continue; - if (matPass.pipeline) { GPUContext.bindPipeline(encoder, matPass); let subGeometries = node._geometry.subGeometries; diff --git a/src/gfx/graphics/webGpu/shader/RenderShaderPass.ts b/src/gfx/graphics/webGpu/shader/RenderShaderPass.ts index 9a7c9249..c419d428 100644 --- a/src/gfx/graphics/webGpu/shader/RenderShaderPass.ts +++ b/src/gfx/graphics/webGpu/shader/RenderShaderPass.ts @@ -867,7 +867,7 @@ export class RenderShaderPass extends ShaderPassBase { } this.defineValue[`USE_GI`] = useGI; - this.defineValue[`USE_CASTSHADOW`] = this.shaderState.castShadow; + // this.defineValue[`USE_CASTSHADOW`] = this.shaderState.castShadow; this.defineValue[`USE_SHADOWMAPING`] = this.shaderState.acceptShadow; this.defineValue[`USE_LIGHT`] = useLight; this.defineValue[`USE_VERTXCOLOR`] = useVertexColor; diff --git a/src/gfx/renderJob/passRenderer/shadow/ShadowMapPassRenderer.ts b/src/gfx/renderJob/passRenderer/shadow/ShadowMapPassRenderer.ts index 3a5832f8..5e6641da 100644 --- a/src/gfx/renderJob/passRenderer/shadow/ShadowMapPassRenderer.ts +++ b/src/gfx/renderJob/passRenderer/shadow/ShadowMapPassRenderer.ts @@ -250,6 +250,9 @@ export class ShadowMapPassRenderer extends RendererBase { continue; if (!renderNode.enable) continue; + if (!renderNode.castShadow) { + continue; + } renderNode.renderPass2(view, this._rendererType, this.rendererPassState, clusterLightingBuffer, encoder); } } diff --git a/src/materials/Material.ts b/src/materials/Material.ts index ed18b72f..b01dfab3 100644 --- a/src/materials/Material.ts +++ b/src/materials/Material.ts @@ -55,7 +55,23 @@ export class Material { } public set castShadow(value: boolean) { - this._defaultSubShader.shaderState.castShadow = value; + let shaderState = this._defaultSubShader.shaderState; + if (value != shaderState.castShadow) { + shaderState.castShadow = value; + } + } + + public get acceptShadow(): boolean { + return this._defaultSubShader.shaderState.acceptShadow; + } + + public set acceptShadow(value: boolean) { + let shaderState = this._defaultSubShader.shaderState; + if (shaderState.acceptShadow != value) { + shaderState.acceptShadow = value; + this._defaultSubShader.noticeShaderChange(); + this._defaultSubShader.noticeValueChange(); + } } public get blendMode(): BlendMode {