Custom VertexShader for DepthRenderer and HightLightLayer

@Evgeni_Popov
Hi!!!
Like DepthRenderer, BBL use one depth shader Effect to draw depth. once I need to achieve some vertex animation by shader, like water surface wave animation, depth will draw wrong.


I change the DepthRenderer code to create custom depth effect(we probably just need to change positionUpdated after vec3 positionUpdated = vec3(position); in this case)

Many postprocess effects and shader effects dependent on correct depth texture. Like Unity, it has DepthPass to keep depth vertex right. I think custom vertex shader for depth effect is necessary and easy to achieve :star_struck: :star_struck: :star_struck:

HighLightLayer custom vertex shader is same as DepthRenderer

Yes, being able to use the vertex/fragment shader of the mesh in the depth renderer/Effect layers would be nice, but I think it would be a little more involved than the changes you did to apply in all cases (something like the ShadowDepthWrapper).

You can create an issue in the Babylon.js repo to keep track of the request.

1 Like

get√

@Moriy would you be willing to do a PR for it ?

The way to add it should not be through custom shaders here but custom materials. We should be able to register a mesh to use a custom material for both the glow/highlight rendering. This would prevent any weird binding tricks or unnecessary convention support + allow usage of NME. That said, the highlight requires some special colors in output but nothing to hard to add in the doc.

Yes I am willing.
Do you mean that I move create effect func to CustomMaterial (extends from customMaterial/pbrCustomMaterial),
In depthRenderer like this?

Reusing a customPBR or PBRMaterial here sounds really hard knowing we are not binding all the required information.

Maybe the simplest is to do like in the glow, a useOwnMaterial property so you can set a custom mat to your meshes and then have some custom inputs to switch between glow/depth/normal mode within the material itself.

I do not want the changes to be to intrusive in this part so reusing the mesh material itself like glow does sounds the most achievable ?

I think I have a way to achieve custom vertexShader, I have a try tonight :star_struck:

My aim target is to make depthRenderer to support this :star_struck:
image

Hello I force to replace depth wrapper, it seems work :grinning:
//no Position Update:main Render pass move depth render path stay still
image


// Position Update: main Render pass and depth render path both move

I don’t find better way to setFloat/XXXX,
It work base on Bug,hahahaha
image

I am totally not sure the way you are going but it sounds hackish :slight_smile: @Evgeni_Popov any good idea for the integration ?

when mainpass is attach to submesh, I check and replace submesh.wrappers[xxxdepth].effect which depthrenderer use to draw depth, it is extends on pbrcustommaterial, only add one field in public😬

It will be handled in the PR I’m currently working on.

As part of the WebGPU fast path implementation, I need to introduce render passes, as we discussed. With those render passes in, it’s easy to provide materials that override the regular material (mesh.material) on a render pass basis.

I have added this method in the RenderTargetTexture class:

public setMaterialForRendering(mesh: AbstractMesh, material?: Material | Material[]): void

It’s already working in my local repo.

I will add a helper proxy method (same name than above: setMaterialForRendering) in the DepthRenderer, EffectLayer, etc classes to avoid having to retrieve the underlying RenderTargetTexture instance (which sometimes is private and not accessible from the outside).

2 Likes

Looking forward to render pass, it is important to achieving more custom shader Effect :grin: