How can I access local position and normal in the fragment chunks of the default material?

Hi all!

I’m currently looking to make a shader that blends across a sphere using either local position or normal but I can’t figure out what the right variable for a local position might be! I’ve identified dNormalW but haven’t found an equivalent for local normals that works in the normalMapPS chunk.

So far I’ve tried aPosition, getPosition(), local_normal, and vertex_normal. I’m still having a little trouble working my way through all of the chunks so I might have overlooked something.

Any pointers are very appreciated!

I’d suggest to use SpectorJS chrome plugin - you can capture a frame and inspect existing shaders to see what you need to modify.

I captured a frame of PlayCanvas Examples and looked at vertex shader, and these are the only data we send to fragment shader from vertex shader:

varying vec3 vPositionW;
varying vec3 vNormalW;
varying vec2 vUV0_1;

which means you don’t have vertex_normal in fragment.

You could modify some chunks of the vertex shader to add it as varying.

You could maybe add this to your chunk

uniform mat4 matrix_model;

invert the matrix, and convert world positoin vPositionW back to local one.

I was worried I’d have to do this! Thank you for the SpectorJS recommendation too!

EDIT: This suggestion solved my problem! Thank you again!

1 Like