- Home /
apply transparent png, material color shine through
I want to do the following: I have some cubes made by script from a prefab. I assigned a material to them with green color. now i want to assign a png textuure on top so that there is still ggreen color, were there is no picture (transparent spaces.)Is there a possibility to achive that? At the moment I have black color where there should be transparency ans the picture is colored green. I have the standard properties of the material. If I change to a transparent material i get a cutout. :(( Any ideas?
Ok I switched to a decal shader and now I see tha transparent png on the cube. The cube has a material with diffuse green color. but somehow the color is mixed with the color of the decals. how can I prevent that??
Answer by ScroodgeM · Jul 14, 2012 at 09:15 AM
you just need to make a one geometry (little smaller to draw behind texture) with solid diffuse green color and the second one with transparency shader and your texture attached
the best way is to write own shader, it's will be a very simple shader. better to take one that can do everyting you want but havn't a color at write 2-3 rows to it with multiply by Color. may be "Transparent/Diffues" or "Transparent/Cutout/Diffuse"?
Thanks for your help, but I'm new to unity and writing a new shader is not exactly what I was going to try first ;) What does it mean to write a one geometry??du i have to double the cube and apply the texture to the outer cube??
Answer by ScroodgeM · Jul 18, 2012 at 09:04 PM
Shader "Diffuse colored in alpha" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGBA)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 250
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_DecalTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = lerp(_Color, c.rgb, c.a);
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
}
Is this a C# Script? I'm currently using Javascript. Do I have to attach this to the material?
it's a shader you asked for. save it to .shader file ti your project and choose this shader 'Diffuse colored in alpha' in material u need
Answer by fschaar · Jul 19, 2012 at 12:23 PM
OK, thank you very much - doesn't look that compicated. I will try it out!