- Home /
Question by
Velotri · Jul 24, 2014 at 08:17 PM ·
shadertransparencyconvertcullingcustom-shader
How to write Diffuse shader with Pass{} instead of surface?
Hello guys,
Sorry for my question, im newbie with shaders.
I need two Pass{} in Diffuse shader for two faces - front and back (Using Cull Front and Cull Back, what is impossible to change with surface). In some cases I wanna make back face semi-transparent and front face transparent. So... How to transform "surface-based" shader into "Pass{}-based"?
TY for help
Comment
Best Answer
Answer by tanoshimi · Jul 24, 2014 at 08:18 PM
You can set Cull Front and Cull Back using surface shaders...
Shader "Custom/DoubleSided" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
// Render back faces first
Cull Front
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
// Flip normal for back faces
void vert (inout appdata_full v) {
v.normal *= -1;
}
// Red back faces
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = fixed3(1,0,0);
o.Alpha = c.a;
}
ENDCG
// Now render front faces
Cull Back
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
// Green front faces
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = fixed3(0,1,0);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Your answer
Follow this Question
Related Questions
Is there a 'do not draw' shader? 1 Answer
Backface Transparent Diffuse Shader 1 Answer
double-sided plane with texture? 4 Answers
glass sphere with reflective/specular shader? 2 Answers
Adding transparency to a shadow 1 Answer