Hello! My name is Cristi and I have a big problem with a shader. This shader is from "ats Snow Suite". The error is: "incorrect number of arguments to numeric-type constructor" on line 65 and the Shader is: Click here: Spoiler Code (csharp): Shader "snowShader Bumped Diffuse" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 300 CGPROGRAM #pragma surface surf Lambert vertex:snow #pragma exclude_renderers flash //#pragma target 3.0 sampler2D _MainTex; sampler2D _SnowTex; sampler2D _BumpMap; fixed4 _Color; float _snowShininess; float _SnowAmount; float _SnowStartHeight; sampler2D _SnowTexture; struct Input { float2 uv_MainTex; float2 uv_BumpMap; fixed4 color : COLOR; float3 worldPos; fixed3 MyWorldNormal; }; void snow (inout appdata_full v, out Input o) { o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal)); } void surf (Input IN, inout SurfaceOutput o) { fixed4 col = tex2D(_MainTex, IN.uv_MainTex) * _Color; fixed4 snow = tex2D(_SnowTex, IN.uv_MainTex); o.Alpha = col.a; o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); // get snow texture // distribution might be stored in alpha half4 snowtex = tex2D( _SnowTexture, IN.uv_MainTex); // clamp(IN.MyWorldNormal.y + 0.6, 0, 1) = allows snow even on orthogonal surfaces // (1-col.b) = take the blue channel to get some kind of heightmap float snowAmount = (_SnowAmount * (clamp(IN.MyWorldNormal.y + 0.6, 0, 1)) * (1-col.b) *.8 + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25); // clamp snow to _SnowStartHeight snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1); // sharpen snow mask snowAmount = clamp(pow(snowAmount,6)*256, 0, 1); o.Alpha = 0.0; // mix o.Albedo = col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount; o.Gloss = half(snowAmount*(1-snowtex.rgb)); o.Specular = _snowShininess; // smooth normal o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50)); } ENDCG } FallBack "Diffuse" } Help me, please!
I actually have no Idea what's up here... Once I get home, I might try and check this on my laptop. (could do it now, but I forgot my TAFE ID... )
I'm guessing its line 66, o.Gloss = half(snowAmount*(1-snowtex.rgb)); test if this works, o.Gloss = half(snowAmount*(1-snowtex.r));
Thank you, mgear! FuzzyQuills, ok. But I have another 2 errors: 'snow': output parameter 'o' not completely initialized - at line 38 and this error 'vert': output parameter 'o' not completely initialized at line 40, in this shader: Spoiler Code (csharp): Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" { Properties { _Control ("Control (RGBA)", 2D) = "red" {} _Splat3 ("Layer 3 (A)", 2D) = "white" {} _Splat2 ("Layer 2 (B)", 2D) = "white" {} _Splat1 ("Layer 1 (G)", 2D) = "white" {} _Splat0 ("Layer 0 (R)", 2D) = "white" {} // used in fallback on old cards _MainTex ("BaseMap (RGB)", 2D) = "white" {} _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) } SubShader { Tags { "SplatCount" = "4" "Queue" = "Geometry-100" "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf BlinnPhong vertex:vert #pragma target 3.0 #include "UnityCG.cginc" struct Input { float3 worldPos; float2 uv_Control : TEXCOORD0; float2 uv_Splat0 : TEXCOORD1; float2 uv_Splat1 : TEXCOORD2; float2 uv_Splat2 : TEXCOORD3; float2 uv_Splat3 : TEXCOORD4; float3 color : COLOR; }; // Supply the shader with tangents for the terrain void vert (inout appdata_full v, out Input o) { // store worldNormal in vertexColor in order to safe registers // terrains usually are not rotated -> so we do not have to to calculate the worldNormal, which would be: // v.color.rgb = normalize(mul((float3x3)_Object2World, v.normal)); v.color.rgb = v.normal; // A general tangent estimation float3 T1 = float3(1, 0, 1); float3 Bi = cross(T1, v.normal); float3 newTangent = cross(v.normal, Bi); normalize(newTangent); v.tangent.xyz = newTangent.xyz; if (dot(cross(v.normal,newTangent),Bi) < 0) v.tangent.w = -1.0f; else v.tangent.w = 1.0f; } sampler2D _Control; sampler2D _BumpMap0, _BumpMap1, _BumpMap2, _BumpMap3, _SnowTexture; sampler2D _Splat0,_Splat1,_Splat2,_Splat3; float _snowPowerTex0, _snowPowerTex1, _snowPowerTex2, _snowPowerTex3; //float _Spec0, _Spec1, _Spec2, _Spec3, _Tile0, _Tile1, _Tile2, _Tile3, float _snowShininess, _SnowTile, _TerrainX, _TerrainZ; float4 _v4CameraPos; float _SnowAmount; float _SnowStartHeight; void surf (Input IN, inout SurfaceOutput o) { half4 splat_control = tex2D (_Control, IN.uv_Control); half3 col; float snowPower; // 4 splats, normals, and specular settings col = splat_control.r * tex2D(_Splat0, IN.uv_Splat0).rgb; o.Normal = splat_control.r * UnpackNormal(tex2D(_BumpMap0, IN.uv_Splat0)); snowPower = splat_control.r * _snowPowerTex0; //o.Gloss = _Spec0 * splat_control.r; //o.Specular = _Spec0 * splat_control.r; //// col += splat_control.g * tex2D(_Splat1, IN.uv_Splat1).rgb; o.Normal += splat_control.g * UnpackNormal(tex2D(_BumpMap1, IN.uv_Splat1)); snowPower += splat_control.g * _snowPowerTex1; //o.Gloss += _Spec1 * splat_control.g; //o.Specular += _Spec1 * splat_control.g; //// col += splat_control.b * tex2D(_Splat2, IN.uv_Splat2).rgb; o.Normal += splat_control.b * UnpackNormal(tex2D(_BumpMap2, IN.uv_Splat2)); snowPower += splat_control.b * _snowPowerTex2; //o.Gloss += _Spec2 * splat_control.b; //o.Specular +=_Spec2 * splat_control.b; //// col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb; o.Normal += splat_control.a * UnpackNormal(tex2D(_BumpMap3, IN.uv_Splat3)); snowPower += splat_control.a * _snowPowerTex3; //o.Gloss += _Spec3 * splat_control.a; //o.Specular += _Spec3 * splat_control.a; /////////////////// // get snow texture half3 snow = tex2D( _SnowTexture, float2(IN.uv_Control.x * (_TerrainX/_SnowTile), IN.uv_Control.y * (_TerrainZ/_SnowTile)) ).rgb; // get snow distribution texture half3 snowdistribution = tex2D( _SnowTexture, IN.uv_Control).a; // (1-col.b) = take the blue channel to get some kind of heightmap // worldNormal is stored in IN.color //float snowAmount = (_SnowAmount * IN.color.y * (1-col.b) + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25) * snowPower; //float snowAmount = (_SnowAmount * IN.color.y * (1-col.b) * snowPower + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25); float snowAmount = (_SnowAmount * IN.color.y * (1-col.b) + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25)*snowPower; // instead of col.b we can go with Luminance(col.rgb) // but this will lead to bright textures on the terrain getting less snow and is more expensive //float snowAmount = _SnowAmount * IN.color.y * (1- Luminance(col.rgb)) + clamp(o.Normal.y, 0, 1) * _SnowAmount *.5; // clamp snow to _SnowStartHeight snowAmount *= clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1); // mix in snowdistributionmap (lerp) and sharpen snow mask (pow), then clamp snowAmount = clamp(pow(snowAmount*(lerp(snowdistribution, 1, snowAmount)),6)*256, 0, 1); o.Albedo = col.rgb * (1-snowAmount) + snow.rgb*snowAmount; // smooth normal o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50)); o.Gloss = snowAmount*(1-snow); o.Specular = _snowShininess; o.Alpha = 0.0; } ENDCG } // Fallback to Diffuse Fallback "Diffuse" }
Try this (not sure) : It seems that the o parameter is useless, because you don't use it in the function, you directly modify v (inout).
@Cristi97Gaming: Looks like you're using DX11. Try doing what Cyrien said! DX11 is very sensitive about syntax, so silly syntax differences, (or things that should work... ) often stuff up DX11. If all else fails, try D3D9 renderer and see what happens.
Try adding UNITY_INITIALIZE_OUTPUT(Input, o); to the beginning of your vertex program. Like so --- Code (csharp): void vert (inout appdata_full v, out Input o) { UNITY_INITIALIZE_OUTPUT(Input, o); // ... }
Use it when compiling HLSL. It initialises the output to zero so the compiler doesn't complain about uninitialised values. For Dx9, that will come up as a warning, but Dx11 will throw an error.