Unity - Pixel/Fragment Shader
Shader "Custom/SamplePixelShader" {
Properties{
_Color ("Main Color", Color) = (1,0,1,1)
_MainTex ("Texture RGBA", 2D) = "white" {}
//_Alpha("Alpha" ,Range(0,1)) = 0.5
//_SpecColor ("Spec Color", Color) = (1,1,1,0)
//_Emission ("Emissive Color", Color) = (0,0,0,0)
//_Shininess ("Shininess", Range (0.1, 1)) = 0.7
}
Category{
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Pass{
ZWrite On
ColorMask 0
}
Pass
{
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//user defined variables
uniform float4 _Color;
uniform sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float2 texco : TEXCOORD0;
};
//vertex function
vertexOutput vert(vertexInput v){
vertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.texco = v.texcoord;
return o;
}
//fragment/pixel function
fixed4 frag(vertexOutput i) : COLOR {
float4 c = tex2D(_MainTex, i.texco ) * _Color;
float3 emissive = c.rgb ;
float3 finalColor = emissive;
float alpha = c.a * _Color.a;
return fixed4(finalColor,alpha);
}
ENDCG
}
}
}
//Fallback "Diffuse"
}
Properties{
_Color ("Main Color", Color) = (1,0,1,1)
_MainTex ("Texture RGBA", 2D) = "white" {}
//_Alpha("Alpha" ,Range(0,1)) = 0.5
//_SpecColor ("Spec Color", Color) = (1,1,1,0)
//_Emission ("Emissive Color", Color) = (0,0,0,0)
//_Shininess ("Shininess", Range (0.1, 1)) = 0.7
}
Category{
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Pass{
ZWrite On
ColorMask 0
}
Pass
{
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//user defined variables
uniform float4 _Color;
uniform sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float2 texco : TEXCOORD0;
};
//vertex function
vertexOutput vert(vertexInput v){
vertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.texco = v.texcoord;
return o;
}
//fragment/pixel function
fixed4 frag(vertexOutput i) : COLOR {
float4 c = tex2D(_MainTex, i.texco ) * _Color;
float3 emissive = c.rgb ;
float3 finalColor = emissive;
float alpha = c.a * _Color.a;
return fixed4(finalColor,alpha);
}
ENDCG
}
}
}
//Fallback "Diffuse"
}
Blending Types :
Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
Blend One One // Additive
Blend OneMinusDstColor One // Soft Additive
Blend DstColor Zero // Multiplicative
Blend DstColor SrcColor // 2x Multiplicative
Comments