I am currently writing a couple of shaders and some of them are meant to use the lightmap generated with beast.
And some are also meant to do some basic alpha blending. Now, I want an object using such a shader to throw a shadow with correct transparency.
The documentation states this:
So this basicly means that Unity looks for the keyword “transparent” within the properties and the name.
My name and my properties look like this:
Shader "SlinDev/Mobile/Transparent/TexAlphaBeast"
{
Properties
{
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
}
What could I put into the properties to be able to get rid of the “Transparent” in the name? Why doesn´t Unity just look for the Transparent keyword within the subshaders tags?
Without the “Transparent”, the textures alphachannel is just ignored and I just see the meshs shadow. With the “Transparent”, there is no shadow at all!
It works just fine when using a builtin shader, so how to do the same with a custom shader?
How does Unity choose the texture from which to take the alpha channel?
How does Unity choose the correct uv set and the correct scaling and offset?
My shader looks like this(with fallback to CG and a fixed function effect, but I commented them out for now):
Shader "SlinDev/Mobile/TexAlphaBeast"
{
Properties
{
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
}
//GLSL shader used on devices rendering with OpenGL ES 2.0
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Pass
{
Tags {"LightMode" = "Always"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
GLSLPROGRAM
#pragma fragmentoption ARB_precision_hint_fastest
uniform sampler2D _MainTex;
uniform sampler2D unity_Lightmap;
uniform vec4 unity_LightmapST;
varying vec4 texcoord;
#ifdef VERTEX
void main()
{
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
texcoord.xy = gl_MultiTexCoord0.xy;
texcoord.zw = gl_MultiTexCoord1.xy*unity_LightmapST.xy+unity_LightmapST.zw;
}
#endif
#ifdef FRAGMENT
void main()
{
vec4 Color = texture2D(_MainTex, texcoord.xy);
vec4 Lightmap = texture2D(unity_Lightmap, texcoord.zw);
Color.rgb *= Lightmap.rgb*Lightmap.a*8.0;
gl_FragColor = Color;
}
#endif
ENDGLSL
}
}
}
How do I have to change this shader to make Unity to have the lightmapper generate correct shadows with my alphachannel?
Is there any way to use the GLSL ES precision hints, without making Unity throw errors at me (It would be great if the OpenGL renderer would just ignore them while the OpenGL ES 2.0 renderer would use them, but I would also be willing to write two versions of the same shader, one with precision hints and one without)?
Is this going to be possible with the next update, without having to trust Unity to convert my CG shader correctly to GLSL ES?
I am desperatly looking for a way to access lights from within a shader, is there any way to do that without having to pass them to the shader myself?
Thank you!