Hello guys!
I’m starting to feel like an idiot here so if you have any clues what might be wrong please help me to solve the problem
So:
- I load a GLB.
- I create two materials (one as main, one as backup) with the same function with different names so I call this function twice and I store the materials in a
Map
:
private _createCustomWindowGlassMaterial(name: string) {
const windowsConfig = this._sceneConfig.getWindows()
const glassMaterial = new PBRMaterial(name, this.scene)
glassMaterial.emissiveColor = new Color3(
windowsConfig.windowTint.r,
windowsConfig.windowTint.g,
windowsConfig.windowTint.b
)
glassMaterial.alpha = windowsConfig.opacity
glassMaterial.transparencyMode = Material.MATERIAL_ALPHABLEND
glassMaterial.alphaMode = BABYLON.Engine.ALPHA_MULTIPLY
glassMaterial.backFaceCulling = false
// glassMaterial.needDepthPrePass = true
return glassMaterial
}
- I get the main material from the
Map
and assign it to some meshes. It’s all ok. Now if I setneedDepthPrePass
totrue
the meshes becomes black. However if I set the material of these meshes with the inspector to the second material the meshes are rendered correctly.
Logically it seems that I’m modifying the first material somewhere in my code because it is not working with the first one however working with the second one. But I am not aware of modifying the first material anywhere, I’ve triple (actually maybe 20 times already) checked my code, I’ve compared the two materials step by step, all the properties and they looks the same to me.
This is already driving me crazy There must be something I am missing. Any hints what can cause a mesh being rendered black with this setup?
My codebase is already 20k+ lines but the material manipulation class is only a few hundred lines but despite of this I am not able to transfer the whole code to the playground. I’ve created a simple PG version but I couldn’t repro the issue. The difference between my code and the PG code is that I’m putting all my shared materials in a Map
and getting them from there not from the scene but it must not cause any problems actually and I use an environment texture (not a HemisphericLight
) and utilizing the DefaultRenderingPipeline
in my app like I did it in the PG.
I’m running BJS 5.13.3. I can provide the PG link with the GLB (not public) for the BJS team if interested but as I said, I couldn’t repro the issue.
Thanks a lot!
R.
To be more precise on what am I doing:
private _setupHDREnvironment(): void {
const envConfig = this._sceneConfig.getHDREnvironment()
if (!envConfig.enabled) {
return
}
this.scene.ambientColor = fromConfigColor3(envConfig.ambientColor)
if (envConfig.filename) {
this.scene.environmentTexture = CubeTexture.CreateFromPrefilteredData(
`${this._sceneConfig.getTextureDir()}${envConfig.filename}`,
this.scene
)
this.scene.createDefaultSkybox(this.scene.environmentTexture, true, 3000, 0.3, false)
this.scene.environmentIntensity = envConfig.intensity
}
}
private _setupPipeline(camera: Camera): DefaultRenderingPipeline | undefined {
const pipelineConfig = this._sceneConfig.getPipeline()
if (!pipelineConfig.enabled) {
return
}
const pipeline = new DefaultRenderingPipeline(
'defaultPipeline',
this._sceneConfig.getHDREnvironment().enabled,
this.scene,
[camera]
)
pipeline.samples = pipelineConfig.samples
pipeline.fxaaEnabled = pipelineConfig.fxaaEnabled
pipeline.imageProcessing.contrast = pipelineConfig.contrast
pipeline.imageProcessing.exposure = pipelineConfig.exposure
pipeline.imageProcessing.toneMappingEnabled = pipelineConfig.toneMappingEnabled
pipeline.imageProcessing.toneMappingType = pipelineConfig.toneMappingType
return pipeline
}