Some Trouble with depth texture

Hi everyone!!!
I have some trouble with depth texture.
I achieve a light scan func with screen space postprocess like this, it samples depthMap:


I achieve a build split effect with PBRCustomMaterial like this:


When I make them working together, bo---------om, ghost shadow appears:

This shows “world position” calculated by ScreenSpaceDepth (mod 100).


It seems that custom uniforms splitStep,splitPercent,splitMaxHeight didn’t effect the depth vertex shader.


:point_down:

build can be splitted correctly, gl_Position shouldn’t been wrong. Maybe BBL draws color and depth at different time. When BBL draws depth, it didn’t bind custom uniforms for submesh.

Ping @nasimiasl who owns the custom material.

In your case I would recommend going the NME road instead as we can not guarantee back compat of our shaders internally and those are the kind of things which will be impossible to foresee.

1 Like

let me read that first :slight_smile:
in progress

1 Like

@Moriy hey

i use the different depth parameter that not use LOG
** notice that mathematical function not always make same result in the different GPU specially when you talk about sensitive data

so i prefer use “gl_FragCoord.z”

by this calculate ((2.0 * near * far) / (far + near - (gl_FragCoord.z*2.-1.) * (far - near)))/far

https://www.babylonjs-playground.com/#TBG0FA#2

also if you need more smooth use can use this
https://www.babylonjs-playground.com/#TBG0FA#1

** i know you need them in post process i need try that

1 Like

https://www.babylonjs-playground.com/#TBG0FA#3

3 Likes

I find that nodeMaterial can be created by uniqueURL or file, could it created by a string field? My project will work at local area network , and automatic build program do not support to move each xxxxx.xxx.fx/.json file into public folder, it is very cumbersome to push NME file into built package by hand. These are why I don’t willing to use NME ,maybe I just need static way to create nodeMaterial, once built , never change

if you store the json in code you can use:

const material = new NodeMaterial("AwesomeMat", scene);
material.loadFromSerialization(json);

Thank you for your help!!! Maybe my explanation is not clear enough (my English is very bad), I will try my best to eaplan it clearly :grin: :grin: :grin:
My main problem is that when I change vertexShader of PBRCustomMaterial (like I move a mesh upward with an uniform upwardValue in vertexShader ----- positionUpdated.y += upwardValue;) In Color Space the mesh has been moved up 100 unit, but in Depth Space, the mesh is stand still. When light scaning, it looks like a ghost shadow in original location. It seems that uniforms wasn’t setted into submesh when scene rendered this mesh into depth.
image


Is json exported like picture?

1 Like

Yup it will provide you with the json you can then embed where you want.

Get√ , have a try :grin: :grin: :grin:

Hello sebavan~
It has some mistakes https://playground.babylonjs.com/#F6Q8K2#2

this is NME Babylon.js Node Material Editor

i see

the world position most not calculate the vertex changes you need use the varying and passed that from vertexshader

your code mode
https://cyos.babylonjs.com/#CNG205

correct mode
https://cyos.babylonjs.com/#CNG205#1

but you most init that on Cusom material
u need
Fragment_MainBegin and Fragment_Definitions and Vertex_Definitions

You are not passing a json object but a string containing json in the function.

https://playground.babylonjs.com/#F6Q8K2#4

Ohhhhh, my mistake!!! I always thought JSON is equal to string :sob: :sob: :sob:

1 Like

yes, I read the pbr.vertex.fx, customPBRMaterial use gl_Position.w to calculate depth, gl_Position is calculated by worldPos, worldPos is calculated by positionUpdated. I add code in Vertex_Before_PositionUpdated where positionUpdated is defined but worldPos isn’t defined.

In this order, I change positionUpdated, gl_Position is changed correctly, but depth not change.

This picture is draw with a screen space postprocess Effect, It samplers depth map, calculate world position for each fragment, then output worldposition mod 100.(I think it is best way to show depthMap than linear gray 0-1)
image

1 Like

I have a good idea to show this phenomenon.
I will give you a clearly picture to show this error tomorrow.

2 Likes

any playground can help