- Home /
Applying transparent texture to mesh
Hello everyone. I have the following transparent png and i would like to apply it to a mesh without any tiling so that i get a darkness effect. To specify, the mesh is procedurally generated and is used for dynamic 2d shadows. If i set tiling to 0 i only get a black texture.
Any ideas/suggestions? Take care everyone :)
Hello, I do not understand your issue. I mean what is the point with "tilling".
If you need to use this texture on your mesh, create a material with a shader that manage transparency.
I have phrased my question poorly. I do not know a lot about shaders and so on. What i need to do is be able to stretch this texture along a mesh that has the shape of a disk ( circular ).
So for example if i have a disk with radius 100 i want this texture to stretch out so that it's center is at the center of the disk. Same with any disk of any size. The problem is i have tried all shaders individually one by one ( since i dont know how they work ) and even though the texture i provide has some transparency, it is lost within the game and all i get is an 100% opaque black.
If this helps any i am trying to simulate some light source.
If I understand well, you want to apply this texture on a plane and to make the black transparent.
If this is the case just tell me and I could provide you a very simple shader to do that. I don't know all the shaders provided by Unity and Transparent/Cutout won't do what you want.
That is indeed the case. I apologise for draggint this out so much :C
Answer by ArkaneX · Mar 18, 2014 at 02:51 PM
To accomplish what you need, shader supporting transparency is a must, as stated in comments. But additionally, you have to set tiling back to 1, and have your mesh properly UV mapped.
Answer by livevlad · Mar 18, 2014 at 06:12 PM
This the sahder you would need :
Shader "Custom/Custom Transparency" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color("Color",Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" }
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input {
float2 uv_MainTex;
};
uniform sampler2D _MainTex;
uniform float4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
float4 tex = tex2D (_MainTex, IN.uv_MainTex);
tex.rgb *= _Color.rgb;
o.Albedo = tex.rgb;
o.Alpha = tex.a;
}
ENDCG
Use a texture with transparency or set Alpha from grayscale in texture import settings.
If you apply the material on plane created on Unity you will not need to create your own mesh. But as ArkaneX said if you want to apply it on a specific mesh, think about UV mapping.
Hope it helps !