I'm trying this all the day but i have no knowledge with shader programming, i've tried the unify community example but i think it is obsolete, the console returns me a couple of warnings and the material become pink, i switched the codes that the console warned me but still no sucess, it still says that my graphics card can't run subshaders and i have a shader 4.0 graphics card..
do you want to work with lightprobes / lightmaps? This is driven by NdotV, of course you can remove the _BumpMap with o.Normal for faster execution, putting Alpha Rim power into _MainTex and remove _RimColor, That would be faster on mobile. Lightmap is not implemented, you can enable it with lightprobes though. Code (csharp): Shader "Shan/SurfaceRimLight" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _BumpMap ("Bump Map", 2D) = "bump"{} _RimColor("Rim Color(RGB) Power(A)", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert struct Input { float2 uv_MainTex; float2 uv_BumpMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _BumpMap; float4 _RimColor; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal)); o.Albedo = c.rgb; // to use with lightprobes. //float3 worldNormal = WorldNormalVector(IN,o.Normal); //o.Albedo = c.rgb*ShadeSH9(float4(worldNormal,1)); o.Emission = _RimColor.rgb * pow(rim, _RimColor.a); } ENDCG } FallBack "Diffuse" }
Thats kinda cool! how to optimise it further so it's just rimlight + lightprobes lights? ie removing the normal mapping? I imagine it would be fast on mobile.
These look great! I'll report back with some findings once I get in the office. One thing I noticed was POW - is that in the pixel or vertex level since it's a tad too expensive otherwise.
don't know really, surface shader is something unity made, gotta ask them. My first guess is that everything in surface shader is pixel/fragment shader.
How do I mask the rim with the _ MainTex's alpha? I got it working with specular, but I know very very very little about shader scripting, how would I go about making that rim effect be affected by _MainTex's alpha? Code (csharp): Shader "Bumped Specular with rim" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.03, 1)) = 0.078125 _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} _RimColor("Rim Color(RGB) Power(A)", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 400 CGPROGRAM #pragma surface surf BlinnPhong struct Input { float2 uv_MainTex; float2 uv_BumpMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _BumpMap; float4 _RimColor; fixed4 _Color; half _Shininess; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D(_MainTex, IN.uv_MainTex); o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal)); o.Albedo = c.rgb * _Color.rgb; o.Albedo += _RimColor.rgb * pow(rim, _RimColor.a); o.Gloss = c.a; o.Alpha = c.a * _Color.a; o.Specular = _Shininess; } ENDCG } FallBack "Diffuse" }
I can't use alpha twice? I did this and it seems to work! :-0 Code (csharp): Shader "Bumped Specular with rim" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.03, 1)) = 0.078125 _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} _RimColor("Rim Color(RGB) Power(A)", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 400 CGPROGRAM #pragma surface surf BlinnPhong struct Input { float2 uv_MainTex; float2 uv_BumpMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _BumpMap; float4 _RimColor; fixed4 _Color; half _Shininess; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D(_MainTex, IN.uv_MainTex); o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal)); o.Albedo = c.rgb * _Color.rgb; o.Albedo += _RimColor.rgb * pow(rim, _RimColor.a) * c.a; o.Gloss = c.a; o.Alpha = c.a * _Color.a; o.Specular = _Shininess; } ENDCG } FallBack "Diffuse" }
You can use alpha as many times as you want, you only have one alpha and you want to represent alpha, gloss and rim with it? That's why it "seems" to be working for you