Just With the following function:
Color
MainTex
Depth
Transparent
NoLight
the built-in shader does fit my needs.
could anyone help me?
Just With the following function:
Color
MainTex
Depth
Transparent
NoLight
the built-in shader does fit my needs.
could anyone help me?
Since your thread got moved from Gossip I had to hunt you down
You could try this shader … it’s cg only, not fixed function, but you can easily do this with fixed function too. It includes vertex colors (not a fixed color), one texture, and z-buffer write and read. Untested, but should work.
Shader "Texture+VertexColor-AlphaBlend" {
//Texture+VertexColor shading with Alphablend blend mode
//Final color is alphablended with the backbuffer
Properties {
_Texture0 ("Texture 0", 2D) = "white" {}
}
SubShader {
Pass {
Cull Off // Back | Front | Off
ZTest LEqual // Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
ZWrite On // On | Off
AlphaTest Off //0.0 // Less | Greater | LEqual | GEqual | Equal | NotEqual | Always (+ThresholdFloat | [_ThresholdVariable])
Lighting Off // On | Off
ColorMask RGB // RGB | A | 0 | any combination of R, G, B, A
//BlendOp Add // Min | Max | Sub | RevSub
Blend SrcAlpha OneMinusSrcAlpha // SrcFactor DstFactor (optionally:, SrcFactorA DstFactorA) = One | Zero | SrcColor | SrcAlpha | DstColor | DstAlpha | OneMinusSrcColor | OneMinusSrcAlpha | OneMinusDstColor | OneMinusDstAlpha
// Blend SrcAlpha OneMinusSrcAlpha = Alpha blending
// Blend One One = Additive
// Blend OneMinusDstColor One = Soft Additive
// Blend DstColor Zero = Multiplicative
// Blend DstColor SrcColor = 2x Multiplicative
CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#include "UnityCG.cginc"
//Unity variables to be made accessible to Vertex and/or Fragment shader
uniform sampler2D _Texture0;
uniform float4 _Texture0_ST; //, _Texture1_ST; //Offset and Scale for the texture(s)
//Data structure communication from Unity to the vertex shader
//Defines what inputs the vertex shader accepts
struct AppData {
float4 vertex : POSITION;
half2 texcoord : TEXCOORD0; //Receive texture coordinates.
//half2 texcoord1 : TEXCOORD1; //Receive texture coordinates
fixed4 color : COLOR; //Receive vertex colors
};
//Data structure for communication from vertex shader to fragment shader
//Defines what inputs the fragment shader accepts
struct VertexToFragment {
float4 pos : POSITION; //Send fragment position to fragment shader
half2 uv : TEXCOORD0; //Send interpolated texture coordinate to fragment shader
//half2 uv2 : TEXCOORD1; //Send interpolated texture coordinate to fragment shader
fixed4 color : COLOR; //Send interpolated gouraud-shaded vertex color to fragment shader
};
//Vertex shader
VertexToFragment vert(AppData v) {
VertexToFragment o; //Create a data structure to pass to fragment shader
o.pos = mul(UNITY_MATRIX_MVP,v.vertex); //Include influence of Modelview + Projection matrices
o.uv = TRANSFORM_TEX(v.texcoord,_Texture0); //Send texture coords from unit 0 to fragment shader
//o.uv2 = TRANSFORM_TEX(v.texcoord1,_Texture1); //Send texture coords from unit 1 to fragment shader
o.color = v.color; //Send interpolated vertex color to fragment shader
//o.color = _Color; //Send solid color to fragment shader
return o; //Transmit data to the fragment shader
}
//Fragment shader
fixed4 frag(VertexToFragment i) : COLOR {
return fixed4(tex2D(_Texture0, i.uv))*i.color; //Output RGBA texture color multiplied by vertex color
}
ENDCG
}
}
}
And here is basically the same thing without vertex colors, but with a single color variable exposed in the editor for you to tweak:
Shader "Texture+Color-AlphaBlend" {
//Texture+Color shading with Alphablend blend mode
//Final color is alphablended with the backbuffer
Properties {
_Texture0 ("Texture 0", 2D) = "white" {}
_Color ("Solid Color", Color) = (1,1,1,1)
}
SubShader {
Pass {
Cull Off // Back | Front | Off
ZTest Off // Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
ZWrite Off // On | Off
AlphaTest Off //0.0 // Less | Greater | LEqual | GEqual | Equal | NotEqual | Always (+ThresholdFloat | [_ThresholdVariable])
Lighting Off // On | Off
ColorMask RGB // RGB | A | 0 | any combination of R, G, B, A
//BlendOp Add // Min | Max | Sub | RevSub
Blend SrcAlpha OneMinusSrcAlpha // SrcFactor DstFactor (optionally:, SrcFactorA DstFactorA) = One | Zero | SrcColor | SrcAlpha | DstColor | DstAlpha | OneMinusSrcColor | OneMinusSrcAlpha | OneMinusDstColor | OneMinusDstAlpha
// Blend SrcAlpha OneMinusSrcAlpha = Alpha blending
// Blend One One = Additive
// Blend OneMinusDstColor One = Soft Additive
// Blend DstColor Zero = Multiplicative
// Blend DstColor SrcColor = 2x Multiplicative
CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#include "UnityCG.cginc"
//Unity variables to be made accessible to Vertex and/or Fragment shader
uniform sampler2D _Texture0;
uniform fixed4 _Color;
uniform float4 _Texture0_ST; //, _Texture1_ST; //Offset and Scale for the texture(s)
//Data structure communication from Unity to the vertex shader
//Defines what inputs the vertex shader accepts
struct AppData {
float4 vertex : POSITION;
half2 texcoord : TEXCOORD0; //Receive texture coordinates.
//half2 texcoord1 : TEXCOORD1; //Receive texture coordinates
//fixed4 color : COLOR; //Receive vertex colors
};
//Data structure for communication from vertex shader to fragment shader
//Defines what inputs the fragment shader accepts
struct VertexToFragment {
float4 pos : POSITION; //Send fragment position to fragment shader
half2 uv : TEXCOORD0; //Send interpolated texture coordinate to fragment shader
//half2 uv2 : TEXCOORD1; //Send interpolated texture coordinate to fragment shader
//fixed4 color : COLOR; //Send interpolated gouraud-shaded vertex color to fragment shader
};
//Vertex shader
VertexToFragment vert(AppData v) {
VertexToFragment o; //Create a data structure to pass to fragment shader
o.pos = mul(UNITY_MATRIX_MVP,v.vertex); //Include influence of Modelview + Projection matrices
o.uv = TRANSFORM_TEX(v.texcoord,_Texture0); //Send texture coords from unit 0 to fragment shader
//o.uv2 = TRANSFORM_TEX(v.texcoord1,_Texture1); //Send texture coords from unit 1 to fragment shader
//o.color = v.color; //Send interpolated vertex color to fragment shader
//o.color = _Color; //Send solid color to fragment shader
return o; //Transmit data to the fragment shader
}
//Fragment shader
fixed4 frag(VertexToFragment i) : COLOR {
return fixed4(tex2D(_Texture0, i.uv))*_Color; //Output RGBA texture color multiplied by a solid color
}
ENDCG
}
}
}
Note that if you’re doing z buffering and alphablending then the geometry needs to get sorted from back to front… so you might want to add a Tag
line in the shader to say that the render queue = transparent, or however that works.
Hello imaginaryhuman.
Really thank you so much! ^-^
Now I am having a test with these two shaders.
shader of “Texture+VertexColor-AlphaBlend” looks show normally.
but the shader of “Texture+Color-AlphaBlend” looks show the wrong face( just like turnning normals )
And since I do the game for mobile , I care the performance very much.
Which is more effective?
shader of “Texture+VertexColor-AlphaBlend” can not work normally On My Android Device.
shader of “Texture+Color-AlphaBlend” can work.