Problems with Custom Shader Finding a texture in standalone

Hi,

At first I would like to mention I’ve went through the forums and read a lot of posts (as I always do) to solve out my problem without bothering anybody with my issue.

What I did:

  1. I wanted to create a custom shader that would project a new texture onto an existing one so I could mark certain tiles of my RPG game with a icon
  2. I’ve written a shader that composes of main texture and a “tattoo” texture
  3. Everything seems fine in the editor, but the standalone seems to have trouble in the standalone when I’m switching the shader in the code
  4. The shader (when switched) is rendering the main texture but does not apply the “tattoo” texture.
  5. When I set the custom shader initially up front to the mesh the “tattoo” texture is projected properly in standalone
  6. I cannot understand what can possibly be wrong …

What I’ve tried:

  1. Moving shader and its texture to Resource folder (but it seems both the shader and the texture can be properly found as the shader works when initially set up to an object)
  2. Loading the “tattoo” texture from resources at runtime and setting it along with the shader

Both ideas did not work and the shader is still not projecting the “tattoo” texture.
Just to mention again, everything I’ve tried works properly in the editor.

Please help … I’ve run out of options here :frowning:

I’m not sure if this is the case, I don’t know if Unity “works” this way, but what could be the issue is that, because you are initially not using the shader and only set it in the script, it doesn’t include it when composing your standalone and so doesn’t compile it, because it’s never directly used (unless like you mentioned, put it directly on a mesh).

When you go to edit → project settings → graphics you can add shaders that should always be included, perhaps this will solve the issue.

Nope … It’s not that mate. I’ve just tried it. Moreover when I set it on a bunch of objects initially, those objects render properly, but the ones that are set by script render without this overlay texture :frowning:

https://dl.dropboxusercontent.com/u/5169250/WebPlayer.html

If you rotate the screen right (right mouse key) you’ll see a bunch of tiles properly rendered (initially set). There should be the same texture applied on the ones around the player … those are set by the script.

Can you show how you’re trying to do it?

YES !!

Solved it … but still don’t know why it doesn’t work in the first place in standalone. I need to force set the overlay texture:

hex.renderer.material.shader = Resources.Load (“TattoShader”) as Shader;
hex.renderer.material.SetTexture (“_Tattoo”, Resources.Load (“ToM_EnsoCircle_p”) as Texture);

Good! :slight_smile:

Still if I could ask a bit. How can I make the shader not sum up the color but instead put the full “tatto” texture in places where it’s not white, meaning:

void surf (Input IN, inout SurfaceOutput o)
{
fixed4 basecol = tex2D (_MainTex, IN.uv_MainTex);
fixed4 tatcol = tex2D (_Tattoo, IN.uv_MainTex);
if (tatcol is white pixel) {
o.Albedo = _Color * tatcol;
} else {
o.Albedo = basecol * _Color;
}
o.Alpha = basecol.a;
}

I cannot write shaders yet :frowning: But I promise I’ll learn.

Ok … this is simple alpha blending pattern:

SubShader {
Pass {
// Apply base texture
SetTexture [_MainTex] {
combine texture
}
// Blend in the alpha texture using the lerp operator
SetTexture [_BlendTex] {
combine texture lerp (texture) previous
}
}
}

trivial if you know what you’re doing :slight_smile:

But now I don’t have diffuse :frowning: eghhh … I still have sooo much to learn.