- Home /
Need a bit of help with shader. (Diffuse, Specular, Normal, CubeMap-Reflection, 2x Additive)
Right off the bat I know absolutely nothing about shaders, but I've managed to cobble together this legacy shader that almost does what I'm looking for. Maybe one of you shader wizzards out there would be kind enough to lend a hand. Thanks in advance.
What I'm trying to make is a legacy shader that has: Diffuse, Specular, Normal, CubeMap-Reflection and 2x Self-Ilum or Additive. All of which can be colored separately and have the strength values modified.
This Frankenstein attempt almost does the job except the Normal map is only visible in the CubeMap-Reflection unless I crank up the Normal map strength. But that makes the bump effect way too aggressive in the Reflecting parts.
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Legacy Shaders/Reflective/Bumped Specular AdditiveX2" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_TintColor ("Tint Color", Color) = (1,1,1,1)
_TintColor2 ("Tint Color2", Color) = (0,0.5,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.255
_SpecPower ("Specular Power", Range (0.01, 20)) = 10
_BumpPower ("Bump Power", Range (4, 0.1)) = 1
_MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Illum ("Illumin (RGB)", 2D) = "black" {}
_Illum2 ("Illumin2 (RGB)", 2D) = "black" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
#pragma surface surf BlinnPhong
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Illum;
sampler2D _Illum2;
samplerCUBE _Cube;
float4 _Color;
fixed4 _TintColor;
fixed4 _TintColor2;
float4 _ReflectColor;
half _Shininess;
fixed _SpecPower;
fixed _BumpPower;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 worldRefl;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 illum = tex2D(_Illum, IN.uv_MainTex);
fixed4 illum2 = tex2D(_Illum2, IN.uv_MainTex);
fixed4 c = tex * _Color;
o.Albedo = c.rgb;
o.Gloss = tex.a * _SpecPower;
o.Specular = _Shininess;
fixed3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
normal.z = normal.z * _BumpPower;
o.Normal = normalize(normal);
float3 worldRefl = WorldReflectionVector (IN, o.Normal);
fixed4 reflcol = texCUBE (_Cube, worldRefl);
reflcol *= tex.a * _SpecPower;
o.Emission = reflcol.rgb * _ReflectColor.rgb + (((2.0f * (illum.rgb * _TintColor.a)) * _TintColor) + (1.93f * (illum2.rgb * _TintColor2.a) * _TintColor2));
o.Alpha = reflcol.a * _ReflectColor.a;
}
ENDCG
}
FallBack "Legacy Shaders/Reflective/Bumped Specular"
}
Anyone? It's only the last bit I need help with. Everything up to line 60 is correct. I just don't know how I'm supposed to add things up at the end there.
in this case, i feel your shader is doing vertex based lighting ins$$anonymous$$d of pixel-based lighting. I think BlinnPhong is the problem (it's the lighting function). It may be better if you start your modifying from a shader with standard lighting model. (Right Click: Create/Shader/Standard Surface shader). i don't have to research so i am not sure
Answer by Daemonhahn · Apr 12, 2018 at 09:28 AM
I dont think you need to normalize your normals. That is converting them to 0-1 space. Try removing the line that says:
o.Normal = normalize(normal);
instead write:
o.Normal = normal;
And see if that helps?