I dag har jeg skrevet en shader som skal brukes til flagg og flersidede plater.
Shaderen fungerer slik at alt renderes i to prosesser, først den ene siden av platen så den andre,
Forsiden er satt opp slik:
//Front “Pass”
Cull back
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
} ;
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
}
ENDCG
og baksiden er satt opp slik:
//Back “Pass”
Cull front
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
} ;
void surf (Input IN, inout SurfaceOutput o) {
IN.uv_MainTex.x = 1.0 – IN.uv_MainTex.x; <= Dette flipper texturen slik at den blir riktig på baksiden.
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
}
ENDCG
I helhet er shaderen slik:
Shader “MarcusRognes/AdvancedSignShader” {
Properties {
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
//Front “Pass”
Cull back
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
} ;
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
}
ENDCG
//Back “Pass”
Cull front
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
} ;
void surf (Input IN, inout SurfaceOutput o) {
IN.uv_MainTex.x = 1.0 – IN.uv_MainTex.x;
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
}
ENDCG
}
FallBack “Diffuse”
}



