- Home /
Can someone add a Main Color attribute to this shader?
I don't know how.
Shader "Example/RimWorldRefl" { Properties { _MainTex ("Texture", 2D) = "white" {} _Cube ("Cubemap", CUBE) = "" {} _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0 _Color ("Main Color", Color) = (1,0.5,0.5,1)
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float3 worldRefl;
float3 viewDir;
};
sampler2D _MainTex;
samplerCUBE _Cube;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * 1;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = texCUBE (_Cube, IN.worldRefl).rgb * pow(rim,_RimPower);
}
ENDCG
}
Fallback "Diffuse"
}
Answer by efge · Apr 24, 2011 at 10:08 PM
Looks like the mixed "Rim Lighting" and "Cubemap Reflection" shaders from the Surface Shader Examples.
Shader "Example/RimWorldRefl" { Properties { _MainTex ("Texture", 2D) = "white" {} _Cube ("Cubemap", CUBE) = "" {} _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0 _Color ("Main Color", Color) = (1,0.5,0.5,1)
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float3 worldRefl;
float3 viewDir;
};
sampler2D _MainTex;
samplerCUBE _Cube;
float4 _Color;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * 1;
o.Albedo *= _Color.rgb;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = texCUBE (_Cube, IN.worldRefl).rgb * pow(rim,_RimPower);
}
ENDCG
}
Fallback "Diffuse"
}
(untested)
Oh, it works, but it's changing the color of the cubemap. I wanted to change the color of the diffuse. Thanks, anyway.
Yes ... we have to multiply the color RGB values to the Albedo value.
Your answer

Follow this Question
Related Questions
Main Color on terrain splatmap shader 1 Answer
Material doesn't have a color property '_Color' 4 Answers
Add Color to Projection Shader 1 Answer
Need help with using world position in shader 1 Answer
Strange artifacts on Vertex Color Shader 0 Answers