- Home /
Problems with two sided textured shader
I have a simple plane I made in Blender, exported to a fbx file and imported to Unity. Then I made a shader, that should allow a two sided textured plane (if I'm reading the past two sided shader discussions right).
Now when I look the plane in the editor, it looks fine. Both sides look like they are supposed to, but when I run the game, the other side is completely black. Is it because of the normals or the lighting or what? I'm kinda new to writing shaders.
Here are some images from the editor: http://imageshack.us/g/43/plane1.png/
Here is the shader code:
Shader "Shader test" {
Properties {
_AmbientColor ("Ambient Color", Color) = (1, 1, 1, 1)
_DiffuseColor ("Diffuse Color", Color) = (0, 0, 0, 0)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_SideOne ("Side 1", 2D) = "white" {}
_SideTwo ("Side 2", 2D) = "white" {}
}
SubShader {
Pass {
Material {
Diffuse [_DiffuseColor]
Ambient [_AmbientColor]
}
Cull Off
Lighting On
SetTexture [_SideOne] {
Combine Primary * Texture
}
}
Pass {
Material {
Diffuse [_DiffuseColor]
Ambient [_AmbientColor]
}
Lighting On
SetTexture [_SideTwo] {
Combine Primary * Texture
}
}
}
}
Answer by jonas-echterhoff · Jun 09, 2011 at 08:24 AM
Not 100% sure this is your problem, but in your first pass, you have "Cull Off". That makes the first pass show both sides. If you want to have one pass to only show the back sides, change it to "Cull Front".
Seems like the Cull Front has the exact same effect as Cull Off. And btw, I'm using $$anonymous$$acBook Pro and Unity 3.3.
Answer by muchitto · Jun 13, 2011 at 06:04 AM
Has anyone got any suggestions? I still haven't found a solution to this.
Answer by testure · Jun 13, 2011 at 07:26 AM
I'd wager that the problem you're having is lighting-related. The thing with a two sided shader is that you can still only receive light on one side. It's not "really" two sided, it's just one side being drawn twice. Most people have the exact opposite problem, where both sides are super bright.. you're probably not having that problem because of the nature of your two texture implementation.
Personally, I don't mess with two sided shaders.. I see zero benefit from it- those backfacing triangles still count. In your case, you could potentially save a draw call by using a single material- but you could still get away with a single draw call if you combine your textures into a single atlas and adjust the UVs on both sides to match up with the atlas. You lose the ability to tile in this case, but based on the images in your screenshot that doesn't look like it would be an issue..
When I'm working on models, I'll keep all of the stuff that will eventually be two sided on a separate layer so they're easily accessable, and then when I'm ready to export to an FBX I'll duplicate the layer, flip the normals, export to FBX, then delete the 'other side' layer. I use modo, so it was easy to write a script that did that for me- now i just name my layer "two-sided" and when I run my exporter script it does all that for me.
Just my two cents, hope you find the solution you're looking for.
Your answer
Follow this Question
Related Questions
3D Texture and normals 0 Answers
colorize mesh based on dot product 1 Answer
Camera spaced normals for a surface shader 1 Answer
Weird sphere normals??? 2 Answers
A shader that ignores the direction of normals, but takes distance into account 0 Answers