Skip to content

Instantly share code, notes, and snippets.

@mejje
Created May 1, 2017 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mejje/f4955d6c01a8b01266be365585a8a683 to your computer and use it in GitHub Desktop.
Save mejje/f4955d6c01a8b01266be365585a8a683 to your computer and use it in GitHub Desktop.
SVG importer 1.3.1 shader fixes for Unity 5.6
From 81b6ef5d94662e522ac9304402ea9f3f98bd672e Mon Sep 17 00:00:00 2001
Date: Mon, 1 May 2017 17:56:36 +0200
Subject: [PATCH] SVG importer shader fixes
---
.../Shaders/Resources/Standard/UnitySVG.cginc | 72 ++++++++++++----------
1 file changed, 41 insertions(+), 31 deletions(-)
diff --git a/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc b/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
index 5ab3afd..885add7 100644
--- a/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
+++ b/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
@@ -32,14 +32,14 @@ struct VertexOutputForwardBase_SVG
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
half3 eyeVec : TEXCOORD1;
- half4 tangentToWorldAndParallax[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
+ half4 tangentToWorldAndPackedData[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax or worldPos]
half4 ambientOrLightmapUV : TEXCOORD5; // SH or Lightmap UV
- SHADOW_COORDS(6)
+ UNITY_SHADOW_COORDS(6)
UNITY_FOG_COORDS(7)
fixed4 color : COLOR;
// next ones would not fit into SM2.0 limits, but they are always for SM3.0+
- #if UNITY_REQUIRE_FRAG_WORLDPOS
+ #if UNITY_REQUIRE_FRAG_WORLDPOS && !UNITY_PACK_WORLDPOS_WITH_TANGENT
float3 posWorld : TEXCOORD8;
#endif
};
@@ -51,9 +51,15 @@ VertexOutputForwardBase_SVG vertForwardBase_SVG (VertexInput_SVG v)
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
#if UNITY_REQUIRE_FRAG_WORLDPOS
- o.posWorld = posWorld.xyz;
+ #if UNITY_PACK_WORLDPOS_WITH_TANGENT
+ o.tangentToWorldAndPackedData[0].w = posWorld.x;
+ o.tangentToWorldAndPackedData[1].w = posWorld.y;
+ o.tangentToWorldAndPackedData[2].w = posWorld.z;
+ #else
+ o.posWorld = posWorld.xyz;
+ #endif
#endif
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
+ o.pos = UnityObjectToClipPos(v.vertex);
o.tex = TexCoords_SVG(v);
o.eyeVec = NormalizePerVertexNormal(posWorld.xyz - _WorldSpaceCameraPos);
float3 normalWorld = UnityObjectToWorldNormal(v.normal);
@@ -61,16 +67,16 @@ VertexOutputForwardBase_SVG vertForwardBase_SVG (VertexInput_SVG v)
float4 tangentWorld = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
float3x3 tangentToWorld = CreateTangentToWorldPerVertex(normalWorld, tangentWorld.xyz, tangentWorld.w);
- o.tangentToWorldAndParallax[0].xyz = tangentToWorld[0];
- o.tangentToWorldAndParallax[1].xyz = tangentToWorld[1];
- o.tangentToWorldAndParallax[2].xyz = tangentToWorld[2];
+ o.tangentToWorldAndPackedData[0].xyz = tangentToWorld[0];
+ o.tangentToWorldAndPackedData[1].xyz = tangentToWorld[1];
+ o.tangentToWorldAndPackedData[2].xyz = tangentToWorld[2];
#else
- o.tangentToWorldAndParallax[0].xyz = 0;
- o.tangentToWorldAndParallax[1].xyz = 0;
- o.tangentToWorldAndParallax[2].xyz = normalWorld;
+ o.tangentToWorldAndPackedData[0].xyz = 0;
+ o.tangentToWorldAndPackedData[1].xyz = 0;
+ o.tangentToWorldAndPackedData[2].xyz = normalWorld;
#endif
//We need this for shadow receving
- TRANSFER_SHADOW(o);
+ UNITY_TRANSFER_SHADOW(o, v.uv1);
// Static lightmaps
#ifndef LIGHTMAP_OFF
@@ -102,9 +108,9 @@ VertexOutputForwardBase_SVG vertForwardBase_SVG (VertexInput_SVG v)
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
half3 viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
- o.tangentToWorldAndParallax[0].w = viewDirForParallax.x;
- o.tangentToWorldAndParallax[1].w = viewDirForParallax.y;
- o.tangentToWorldAndParallax[2].w = viewDirForParallax.z;
+ o.tangentToWorldAndPackedData[0].w = viewDirForParallax.x;
+ o.tangentToWorldAndPackedData[1].w = viewDirForParallax.y;
+ o.tangentToWorldAndPackedData[2].w = viewDirForParallax.z;
#endif
o.color = v.color;
@@ -117,7 +123,7 @@ half4 fragForwardBase_SVG (VertexOutputForwardBase_SVG i) : SV_Target
{
FRAGMENT_SETUP(s)
UnityLight mainLight = MainLight ();
- half atten = SHADOW_ATTENUATION(i);
+ UNITY_LIGHT_ATTENUATION(atten, i, s.posWorld);
half occlusion = Occlusion(i.tex.xy);
UnityGI gi = FragmentGI (
@@ -127,7 +133,6 @@ half4 fragForwardBase_SVG (VertexOutputForwardBase_SVG i) : SV_Target
c *= i.color;
- c.rgb += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, occlusion, gi);
c.rgb += Emission(i.tex.xy);
UNITY_APPLY_FOG(i.fogCoord, c.rgb);
@@ -141,9 +146,9 @@ struct VertexOutputDeferred_SVG
fixed4 color : COLOR;
float4 tex : TEXCOORD0;
half3 eyeVec : TEXCOORD1;
- half4 tangentToWorldAndParallax[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
+ half4 tangentToWorldAndPackedData[3]: TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax or worldPos]
half4 ambientOrLightmapUV : TEXCOORD5; // SH or Lightmap UVs
- #if UNITY_REQUIRE_FRAG_WORLDPOS
+ #if UNITY_REQUIRE_FRAG_WORLDPOS && !UNITY_PACK_WORLDPOS_WITH_TANGENT
float3 posWorld : TEXCOORD6;
#endif
};
@@ -155,9 +160,15 @@ VertexOutputDeferred_SVG vertDeferred_SVG (VertexInput_SVG v)
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
#if UNITY_REQUIRE_FRAG_WORLDPOS
- o.posWorld = posWorld;
+ #if UNITY_PACK_WORLDPOS_WITH_TANGENT
+ o.tangentToWorldAndPackedData[0].w = posWorld.x;
+ o.tangentToWorldAndPackedData[1].w = posWorld.y;
+ o.tangentToWorldAndPackedData[2].w = posWorld.z;
+ #else
+ o.posWorld = posWorld.xyz;
+ #endif
#endif
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
+ o.pos = UnityObjectToClipPos(v.vertex);
o.tex = TexCoords_SVG(v);
o.eyeVec = NormalizePerVertexNormal(posWorld.xyz - _WorldSpaceCameraPos);
float3 normalWorld = UnityObjectToWorldNormal(v.normal);
@@ -165,13 +176,13 @@ VertexOutputDeferred_SVG vertDeferred_SVG (VertexInput_SVG v)
float4 tangentWorld = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
float3x3 tangentToWorld = CreateTangentToWorldPerVertex(normalWorld, tangentWorld.xyz, tangentWorld.w);
- o.tangentToWorldAndParallax[0].xyz = tangentToWorld[0];
- o.tangentToWorldAndParallax[1].xyz = tangentToWorld[1];
- o.tangentToWorldAndParallax[2].xyz = tangentToWorld[2];
+ o.tangentToWorldAndPackedData[0].xyz = tangentToWorld[0];
+ o.tangentToWorldAndPackedData[1].xyz = tangentToWorld[1];
+ o.tangentToWorldAndPackedData[2].xyz = tangentToWorld[2];
#else
- o.tangentToWorldAndParallax[0].xyz = 0;
- o.tangentToWorldAndParallax[1].xyz = 0;
- o.tangentToWorldAndParallax[2].xyz = normalWorld;
+ o.tangentToWorldAndPackedData[0].xyz = 0;
+ o.tangentToWorldAndPackedData[1].xyz = 0;
+ o.tangentToWorldAndPackedData[2].xyz = normalWorld;
#endif
#ifndef LIGHTMAP_OFF
@@ -193,9 +204,9 @@ VertexOutputDeferred_SVG vertDeferred_SVG (VertexInput_SVG v)
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
half3 viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
- o.tangentToWorldAndParallax[0].w = viewDirForParallax.x;
- o.tangentToWorldAndParallax[1].w = viewDirForParallax.y;
- o.tangentToWorldAndParallax[2].w = viewDirForParallax.z;
+ o.tangentToWorldAndPackedData[0].w = viewDirForParallax.x;
+ o.tangentToWorldAndPackedData[1].w = viewDirForParallax.y;
+ o.tangentToWorldAndPackedData[2].w = viewDirForParallax.z;
#endif
o.color = v.color;
@@ -236,7 +247,6 @@ void fragDeferred_SVG (
half3 emissiveColor = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect).rgb;
emissiveColor *= i.color;
- emissiveColor += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, occlusion, gi);
#ifdef _EMISSION
emissiveColor += Emission (i.tex.xy);
--
2.8.1.windows.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment