Global.position in frag shader

Hello ,

I try to make a global/world uv map shader (usulay I use texCoord.xy)
and use the Global.position.xyz as a 3d texCoord to generate a 3d noise texture

but if I do so, the shader does not work at all, it compiles with no error but the frag color is all white

ShaderNode ZoneFrag {
  Definition : ZoneFrag : Shaders/Zone/ZoneFrag.j3sn
  InputMappings 
  {
       texCoord=Global.position.xyz 
...

so I cant use globals for input ?

if i use the input variable from my vert shader node :

ShaderNode ZoneVert
{
  Definition : ZoneVert : Shaders/Zone/ZoneVert.j3sn
  InputMappings
  {
   modelPosition = Global.position.xyz
   ....

then

texCoord=ZoneVert.modelPosition.xyz 

then it works

  • how come I cant do it directly with Global.position ?
  • will that position be interpolated through all fragments ?

thanks

Global.position is a vertex shader input. it’s initialised with the inPosition attribute (vertex data from the mesh).
You can’t use it in a fragment shader (as you can’t use attributes).

In the second case it works because the attribute value is transferred to the fragment shader as a varying. That’s the standard way of doing it in glsl.

maybe it should not be called global, it’s confusing

Even if it was made global it wouldn’t make any sense. The fragment shader typically expects the position to be in projection space not model space.

yes but what about global uv maps then…
in the end I feed the vertex position to the 3D noise function and it works
I just have to use a variable from the vertex shader that holds the Global.position

The thing is…you can’t pass mesh data to a fragment shader directly. Not only using shader nodes, but in glsl in general.
The only shader getting mesh vertex data is the vertex shader.
Global uv maps as you say are also passed as a varying.

Maybe “Global” is a bad prefix for “VertexData”?

Well actually VertexData is also a bad prefix. Because Global.position is actually a global variable fed with vertex data, not the vertex data attibute (inPosition). Meaning it’s valid to assign a value to it.
But the “global” here means it’s global to all the nodes in the vertex shader.
This is the yellow rail in the shaderNodes editor.

So maybe VertexGlobal, and FragmentGlobal would be better…