This question was
closed Feb 22, 2019 at 09:56 AM by
lawlzilla.
Question by
lawlzilla · Feb 21, 2019 at 01:03 PM ·
shadershadersshader programming
Shader error when updating shader.
Whenever I try to update the script this(undeclared identifier 'v' at line 70 (on d3d11)) error pops up and breaks the shader turning everything pink.
The code:
Shader "Custom/celShader"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_RampTex("Ramp", 2D) = "white" {}
_Color("Color", Color) = (1, 1, 1, 1)
_OutlineExtrusion("Outline Extrusion", float) = 0
_OutlineColor("Outline Color", Color) = (0, 0, 0, 1)
}
SubShader
{
Pass
{
Tags
{
"LightMode" = "ForwardBase"
}
Stencil
{
Ref 4
Comp always
Pass replace
ZFail keep
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _RampTex;
float4 _Color;
float4 _LightColor0;
struct vertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float3 texCoord : TEXCOORD0;
};
struct vertexOutput
{
float4 pos : SV_POSITION;
float3 normal : NORMAL;
float3 texCoord : TEXCOORD0;
LIGHTING_COORDS(1,2)
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = UnityObjectToClipPos(input.vertex);
float4 normal4 = float4(input.normal, 0.0);
output.normal = normalize(mul(normal4, unity_WorldToObject).xyz);
output.texCoord = input.texCoord;
TRANSFER_VERTEX_TO_FRAGMENT(output);
return output;
}
float4 frag(vertexOutput input) : COLOR
{
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
float ramp = clamp(dot(input.normal, lightDir), 0, 1.0);
float3 lighting = tex2D(_RampTex, float2(ramp, 0.5)).rgb;
float4 albedo = tex2D(_MainTex, input.texCoord.xy);
float attenuation = LIGHT_ATTENUATION(input);
float3 rgb = albedo.rgb * _LightColor0.rgb * lighting * _Color.rgb * attenuation;
return float4(rgb, 1.0);
}
ENDCG
}
Pass
{
Tags
{
"LightMode" = "ShadowCaster"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
v2f vert(appdata_base v)
{
v2f o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag(v2f i) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
Pass
{
Cull OFF
ZWrite OFF
ZTest ON
Stencil
{
Ref 4
Comp notequal
Fail keep
Pass replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform float4 _OutlineColor;
uniform float _OutlineSize;
uniform float _OutlineExtrusion;
sampler2D _MainTex;
struct vertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float3 texCoord : TEXCOORD0;
float4 color : TEXCOORD1;
};
struct vertexOutput
{
float4 pos : SV_POSITION;
float4 color : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
float4 newPos = input.vertex;
float3 normal = normalize(input.normal);
newPos += float4(normal, 0.0) * _OutlineExtrusion;
output.pos = UnityObjectToClipPos(newPos);
output.color = tex2Dlod(_MainTex, float4(input.texCoord.xy, 0, 0));
output.color *= _OutlineColor;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return input.color;
}
ENDCG
}
}
}
Comment
Follow this Question
Related Questions
i wanna draw inside like outside. shader.... 1 Answer
Getting Color Generated from Shader to Script to Shader 0 Answers
How do i get a shader to affect every object with the same material? 0 Answers
Very basic shader problem 0 Answers
Render oject A when behind object B, but not if behind object B and object C 1 Answer