- Home /
Fragment Shader with Alpha in Texture
Hey Guys, I really need your help.
I'm working on a Game for (New) Nintendo 3DS right now but Unity for N3DS has limited Shader support.
This shaders are supported: Stereoscopic Rendering, Vertex Shaders, Fragment Shaders (Limited), Lightmap, Fog, Gamma Pipeline
This shaders are not supported: Standard Shaders, Surface Shaders, Compute Shaders, Pixel Lighting, HDR Rendering, Linear Rendering, Image Effects
Unity for Nintendo 3DS has vertex shader support based on OpenGL ES 2.0.
I want to add some models to my game which need Shaders with AlphaCutout, which isn't supported by Unity for N3DS. The Shader I use looks like this:
The same problem happens when I use "Legacy Shaders/Transparent/VertexLit". The Alpha works but all Textures are transparent and everything shines through it.
Example:
I really need help with that :S Is there a workaround to get Alpha to work without making the whole Texture transparent? Without AlphaCutout?
I've tried this without luck: https://forum.unity.com/threads/alpha-value-in-fragment-shader.366876/
Is there a way to get a working alpha to work like in "Legacy Shaders/Transparent/VertexLit" without making the rest transparent?
Video of some tests on Hardware: https://www.youtube.com/edit?o=U&video_id=QIi-JE9eU-E
This is the shader I use the most of the time:
// Simplified VertexLit shader by Cellenseres.
// - no per-material color
// - no specular
// - no emission
Shader "N3DS/DoubleSided/VertexLitCullOff"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Off
LOD 80
// Non-lightmapped
Pass {
Tags { "LightMode" = "Vertex" }
Material
{
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
}
Lighting On
SetTexture [_MainTex] {
constantColor (1,1,1,1)
Combine texture * primary DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
}
}
// Lightmapped, encoded as dLDR
Pass
{
Tags { "LightMode" = "VertexLM" }
Cull Off
BindChannels {
Bind "Vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture
}
SetTexture [_MainTex] {
constantColor (1,1,1,1)
combine texture * previous DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
}
}
// Lightmapped, encoded as RGBM
Pass
{
Tags { "LightMode" = "VertexLMRGBM" }
Cull Off
BindChannels {
Bind "Vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] {
constantColor (1,1,1,1)
combine texture * previous QUAD, constant // UNITY_OPAQUE_ALPHA_FFP
}
}
// Pass to render object as a shadow caster
Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On ZTest LEqual Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
v2f vert( appdata_base v )
{
v2f o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag( v2f i ) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
}
http://answers.unity3d.com/storage/temp/104380-img-3-4.png This looks more like mesh (triangle order) sorting issue - not shader specific necessarily
How can I edit that? When I use Legacy Shaders/Transparent/Cutout/Diffuse, it looks correct. With Legacy Shaders/Transparent/VertexLit it doesn't.
it should look like:
but it looks like:
is there a way to create a workaround for that?
Alpha Cutout isn't supported by the hardware yet :S
These issues here are all as old as computer graphics itself. You can find people posting about this and giving advice probably from like early 2000 onward. It's generally referred as "transparency sorting" or "alpha blending" + "sorting issues"