Hello!
I have a problem regarding the shader for my planet. I want to have a “Specular mask” so the water will be shiny, but the surface won’t. I have a shader written, and got it to work partially. (Note; I don’t know much about writing shaders)
This is the shader right now:
Shader "PlanetShader" {
Properties
{
_Color("Main Color", Color) = (1,1,1,1)
_SpecColor("Specular Color", Color) = (0.5,0.5,0.5,1)
_Shininess("Shininess", Range (0.01, 1)) = 0.078125
_MainTex("Base(RGB) Spec(A)", 2D) = "white" {}
_BumpMap("Bumpmap", 2D) = "bump" {}
_SpecMap("Specular (R) Gloss (G)", 2D) = "gray" {}
_RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower("Rim Power", Range(0,8.0)) = 3.0
}
SubShader
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Planet //<Remember this!
half _Shininess;
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _SpecMap;
fixed _Gloss;
fixed4 _Color;
float4 _RimColor;
float _RimPower;
half4 LightingPlanet (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 48.0);
half rim = ((1 - (dot (normalize(viewDir), (s.Normal)))) + ((dot (normalize(lightDir), (s.Normal)))));
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
c.rgb = c.rgb * (pow (rim, _RimPower) * _RimColor.rgb);
return c;
}
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_SpecMap;
float3 viewDir;
float3 worldRefl; INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
fixed4 specTex = tex2D (_SpecMap, IN.uv_SpecMap);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = specTex.r;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess * specTex.g;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Diffuse"
}
Now this works great for the actual lighting on the planet, but not for the reflection. However, when I change “#pragma surface surf Planet” to " #pragma surface surf BlinnPhong" I get the reflection how I want it (On the water, not on surface).
My question is; How do I get both?
The right planetary shader
The wanted reflections (On the water, not the surface)