I’m writing a custom diffuse shader chunk where I want to multiply the diffuse texture RGB channels with the alpha channel from the same texture. But I want to use UV0 for the RGB texture lookup, and UV1 for the alpha channel lookup.
Looking at the shader code which gets created, it looks like $UV gets turned into vUv0 or vUv1 etc. but I can’t seem to set them hardcoded.
So this doesn’t work:
dAlbedo *= gammaCorrectInput(addAlbedoDetail(texture2D(texture_diffuseMap, $UV).$CH));
dAlbedo *= texture2D(texture_diffuseMap, vUv1).a;
It throws: ‘vUv1’ : undeclared identifier
Is there a way to do this?
UPDATE:
OK, I see that as long as some other part of the shader uses UV1 somewhere then that variable will be available. Just wondering if that’s always necessary or there’s some way around it.
Actually no, this was working in a simple test scene with a cube. But is not working with my actual model, which actually has two uv sets. Weird. There’s still something I don’t understand here…
What’s weird is that if I take a look at the shader using Spector, I can see this at the top of the shader:
varying vec2 vUv0;
varying vec2 vUv1;
But then these lines are throwing an error:
dAlbedo *= gammaCorrectInput(addAlbedoDetail(texture2D(texture_diffuseMap, vUv0).rgb));
dAlbedo *= texture2D(texture_diffuseMap, vUv1).a;
Error: ‘vUv1’ : undeclared identifier
Which makes no sense to me. It’s literally declared in the same shader.
Hi @steve_wk,
I think a way to force the standard shader to include both sets of coordinates a common trick is to add a texture in the material for each UV coordinates (any texture/channel will do, one for UV0 and another for UV1).
That’s quite strange, @mvaligursky may know more.
1 Like
Hey,
That’s what I just realised, and have just done. It was working on a simple cube (which actually I don’t think has two UV sets.)
But when I use my actual model which does have two UV sets it doesn’t work. Even if, as you can see in my post above, I can see in the shader that both sets are declared at the top of the shader.
1 Like
Our primitives have a second set of UVs
1 Like
Ah ok.
Still not sure why it’s not working with my own model though.
As a trouble shooting step, are you sure you are exporting with both sets of UVs? Can you check by reimporting into Blender/Max/etc and/or Unity?
Yeah they’re definitely both there. I can switch between them on the diffuse channel for example and see the texture being mapped differently/accordingly.