- Home /
Unity 4.5 broke shader in DX11 mode
Unity 4.5 broke the below shader while in DX11 mode, causing the following errors:
'vert': function return value missing semantics at line 112
'frag': input parameter 'i' missing semantics at line 122
How can I go about fixing the shader?
Shader "TestShaders/TransparentWithShadow" {
Properties
{
// Usual stuffs
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
// Bump stuffs
//_Parallax ("Height", Range (0.005, 0.08)) = 0.02
//_BumpMap ("Normalmap", 2D) = "bump" {}
//_ParallaxMap ("Heightmap (A)", 2D) = "black" {}
// Shadow Stuff
_ShadowIntensity ("Shadow Intensity", Range (0, 1)) = 0.6
}
SubShader
{
Tags {
"Queue"="AlphaTest"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 300
Offset -3,-2
// Main Surface Pass (Handles Spot/Point lights)
CGPROGRAM
#pragma surface surf BlinnPhong alpha vertex:vert fullforwardshadows approxview
#pragma exclude_renderers d3d11 xbox360
half _Shininess;
sampler2D _MainTex;
float4 _Color;
//sampler2D _BumpMap;
//sampler2D _ParallaxMap;
//float _Parallax;
struct v2f {
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
};
struct Input {
float2 uv_MainTex;
//float2 uv_BumpMap;
//float3 viewDir;
};
v2f vert (inout appdata_full v) {
v2f o;
return o;
}
void surf (Input IN, inout SurfaceOutput o) {
// Comment the next 4 following lines to get a standard bumped rendering
// [Without Parallax usage, which can cause strange result on the back side of the plane]
// /*half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w;
// float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
// IN.uv_MainTex += offset;
// IN.uv_BumpMap += offset;*/
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
// clip(o.Alpha - _Cutoff);
o.Specular = _Shininess;
//o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
// Shadow Pass : Adding the shadows (from Directional Light)
// by blending the light attenuation
Pass {
Blend SrcAlpha OneMinusSrcAlpha
Name "ShadowPass"
Tags {"LightMode" = "ForwardBase"}
// ZWrite On ZTest LEqual Cull Off
CGPROGRAM
#pragma exclude_renderers d3d11 xbox360
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
float2 uv_MainTex : TEXCOORD1;
float4 pos : SV_POSITION;
LIGHTING_COORDS(3,4)
float3 lightDir;
};
float4 _MainTex_ST;
sampler2D _MainTex;
float4 _Color;
float _ShadowIntensity;
v2f vert (appdata_full v)
{
v2f o;
o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.lightDir = ObjSpaceLightDir( v.vertex );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 frag (v2f i) : COLOR
{
float atten = LIGHT_ATTENUATION(i);
half4 c;
c.rgb = 0;
c.a = (1-atten) * _ShadowIntensity * (tex2D(_MainTex, i.uv_MainTex).a);
return c;
}
ENDCG
}
}
FallBack "Transparent/Specular"
}
Answer by Scripter05 · Jul 19, 2014 at 07:14 PM
Add : TEXCOORD2 to v2f structure(lightDir)
struct v2f {
float2 uv_MainTex : TEXCOORD1;
float4 pos : SV_POSITION;
LIGHTING_COORDS(3,4)
float3 lightDir : TEXCOORD2;
Also remove or comment out this lines: #pragma exclude_renderers d3d11 xbox360
This will fix problems with dx11 renderer.
Answer by Aldrick · Sep 30, 2015 at 03:54 AM
it seems unity 5.0+ with dx11 compulsorily requests every struct member returned by vertex function must have a semantic.So you can just assign an unused semantic to it.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
DirectX11 & Unity problem 1 Answer
How to apply a shader to all materials inside a gameobject 1 Answer
Particle System not rendering at times 0 Answers
A node in a childnode? 1 Answer