Quantcast
Channel: Answers by "keeperkai2"
Viewing all articles
Browse latest Browse all 16

Answer by keeperkai2

$
0
0
by adding: \#pragma target 3.0 \#pragma debug under the surface function declaration(#pragma surface surf ColoredSpecular) and removing your "MySurfaceOutput" struct declaration and replacing MySurfaceOutput with the unity built-in struct SurfaceOutput. The shader will work. So let's take a look at the compiled cg code: struct v2f_surf { float4 pos : SV_POSITION; float2 pack0 : TEXCOORD0; fixed4 TtoW0 : TEXCOORD1; fixed4 TtoW1 : TEXCOORD2; fixed4 TtoW2 : TEXCOORD3; fixed3 lightDir : TEXCOORD4; fixed3 vlight : TEXCOORD5; float3 viewDir : TEXCOORD6; LIGHTING_COORDS(7,8) }; this is the vertex output of the vertex shader, as you can see, the struct v2f contains 0-8, 9 in total interpolated values, the default shader model for unity is shader model 2.0, which only supports 8, so by declaring #pragma target 3.0, we will get 2 more interpolaters for us to use( if your graphics cards supports shader model 3.0). here is the code that works: Shader "Reflection/SpecularNormal" { Properties { _MainTexture("Diffuse Map", 2D) = "white"{} _NormalMap("Normal Map", 2D) = "bump"{} _ReflectionMap("Reflection Map", 2D) = "white"{} _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect } } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf ColoredSpecular #pragma target 3.0 #pragma debug inline half4 LightingColoredSpecular (SurfaceOutput s, half3 lightDirection, half3 viewDirection, half attenuation) { half3 halfVector = normalize (lightDirection + viewDirection); half diffuseLight = max (0, dot (s.Normal, lightDirection)); float specularBase = max (0, dot (s.Normal, halfVector)); float specularLight = pow (specularBase, 128.0 * 0.55f); //Magic numbers because the struct must be small half3 specColor = 0.15f * specularLight * s.Albedo; half4 c; c.rgb = (s.Albedo * _LightColor0.rgb * diffuseLight + _LightColor0.rgb * specColor) * (attenuation * 2); c.a = s.Alpha; return c; } struct Input { float2 uv_MainTexture; float3 worldRefl; INTERNAL_DATA }; sampler2D _MainTexture; sampler2D _NormalMap; sampler2D _ReflectionMap; samplerCUBE _Cube; fixed4 _ReflectColor; void surf (Input IN, inout SurfaceOutput o) { fixed4 tex = tex2D(_MainTexture, IN.uv_MainTexture); o.Albedo = tex.rgb; o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTexture)); fixed4 reflectionColor = tex2D(_ReflectionMap, IN.uv_MainTexture); fixed4 reflcol = texCUBE (_Cube, IN.worldRefl); reflcol *= tex.a; o.Emission = reflcol.rgb * reflectionColor.rgb; o.Alpha = reflcol.a * reflectionColor.a; } ENDCG } Fallback "Reflective/VertexLit" }

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>