Hi,
I want to use multiple textures on an Instanced rendered Object. I’ve tested it with plain Colors and it works but as soon as I add Textures the Texture will be displayed as just one color on the Object:
...
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
StructuredBuffer<Particle> particleBuffer;
#endif
...
void surf (Input IN, inout SurfaceOutputStandard o)
{
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
int colorID = particleBuffer[unity_InstanceID].colorID;
if (colorID == 0) {
//this works:
o.Albedo = _Color.rgb;
//this doesn't work:
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
}
#endif
}
The UV mapping is correct, f.e. this Code works:
void surf (Input IN, inout SurfaceOutputStandard o)
{
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
int colorID = particleBuffer[unity_InstanceID].colorID;
if (colorID == 0) {
o.Albedo = _Color.rgb;
}
#endif
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
}
But doing it this way I can only get one Texture on the object. But I need a switch to change the texture.
So I’ve introduced a helper Variable like this:
void surf (Input IN, inout SurfaceOutputStandard o)
{
int textureSwitch = 0;
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
int colorID = particleBuffer[unity_InstanceID].colorID;
if (colorID == 0) {
o.Albedo = _Color.rgb;
textureSwitch = 1;
}
#endif
if (textureSwitch) {
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
}
}
textureSwitch is never set by what’s inside UNITY_PROCEDURAL_INSTANCING_ENABLED but it’s called.
What’s going on here?
Edit.
This guy is having the exact same problem: