Shader Chunk UVs

Feels like there is a simple solution to this, but I’m not finding it.

I’m trying to do some very simple shader chunk stuff. The following code works, it changes the diffuse color of the existing material to red.

uniform sampler2D uDiffuseTex;

void getAlbedo(){

//vec3 image =  texture2D(uDiffuseTex, $UV).$CH;

vec3 color;
color.r = 1.0;
color.g = 0.0;
color.b = 0.0;

dAlbedo = color;

}

If I uncomment the ‘vec3 image…’ line it errors off, it doesn’t like that $UV identifier. All, or most, of the examples on the web are using it with no problem so it appears I am missing something.

Here’s the project:

https://playcanvas.com/project/709453/overview/shader

Any idea?

Thanks,
Joe H

Hi @jhinrichs,

The problem isn’t that you aren’t using the $UV correctly, but the way you access the channels at the end, .$CH.

That is unique to the way Playcanvas pixel shaders are accessing textures, to apply tonemapping.

So you either use gammaCorrectInput() instead of texture2D(), or access the color channels the traditional way, .rgb.

Check a Playcanvas shader chunk on the subject:

Thanks,

I think I might have tried that on one of my attempts, but I tried it again…the code looks like this now:


uniform sampler2D uDiffuseTex;

void getAlbedo(){

//vec3 image =  texture2D(uDiffuseTex, $UV).$CH;

vec3 color;
color.r = 1.0;
color.g = 0.0;
color.b = 0.0;

dAlbedo = color;

dAlbedo *= gammaCorrectInput(addAlbedoDetail(texture2D(uDiffuseTex, $UV).$CH));

Getting the same kind of error though, looks like it is puking on that $UV identifier:

ERROR: 0:194: ‘UV’ : undeclared identifier
ERROR: 0:194: ‘texture’ : no matching overloaded function found
ERROR: 0:194: ‘CH’ : field selection requires structure, vector, or interface block on left hand side
ERROR: 0:194: ‘addAlbedoDetail’ : no matching overloaded function found

Here’s the project:

https://playcanvas.com/project/709453/overview/shader

Thanks,
Joe H.

}

Checking your project, I think the issue isn’t in your shader code, it’s now correct. The missing coordinates error is due to how the final shader is being assembled as the sum of all the required shader chunks.

In your material you aren’t assigning any texture at all, so the relevant coordinates aren’t included in the final shader. Assign any texture (literally any at all) in your diffuse map in editor and the error will go away:

1 Like

L,

You’re awesome! Thanks alot.

Joe H.

1 Like