Skip to content

Instantly share code, notes, and snippets.

@mejje
Created March 1, 2017 22:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mejje/ccb1b5769078a7fddecf0c1ecb0466e1 to your computer and use it in GitHub Desktop.
Save mejje/ccb1b5769078a7fddecf0c1ecb0466e1 to your computer and use it in GitHub Desktop.
SVG importer 1.3.1 shader fixes for Unity 5.5
From 481b318b11a4c572315f4ea47fd58690263e5330 Mon Sep 17 00:00:00 2001
Date: Wed, 1 Mar 2017 21:25:06 +0100
Subject: [PATCH] SVG importer shader fixes
---
.../Shaders/Resources/Standard/UnitySVG.cginc | 64 +++++++++++++---------
1 file changed, 38 insertions(+), 26 deletions(-)
diff --git a/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc b/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
index e2fd6b0..5ab3afd 100644
--- a/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
+++ b/Assets/SVG Importer/Plugins/Shaders/Resources/Standard/UnitySVG.cginc
@@ -39,7 +39,7 @@ struct VertexOutputForwardBase_SVG
fixed4 color : COLOR;
// next ones would not fit into SM2.0 limits, but they are always for SM3.0+
- #if UNITY_SPECCUBE_BOX_PROJECTION
+ #if UNITY_REQUIRE_FRAG_WORLDPOS
float3 posWorld : TEXCOORD8;
#endif
};
@@ -50,7 +50,7 @@ VertexOutputForwardBase_SVG vertForwardBase_SVG (VertexInput_SVG v)
UNITY_INITIALIZE_OUTPUT(VertexOutputForwardBase_SVG, o);
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
- #if UNITY_SPECCUBE_BOX_PROJECTION
+ #if UNITY_REQUIRE_FRAG_WORLDPOS
o.posWorld = posWorld.xyz;
#endif
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
@@ -116,18 +116,18 @@ VertexOutputForwardBase_SVG vertForwardBase_SVG (VertexInput_SVG v)
half4 fragForwardBase_SVG (VertexOutputForwardBase_SVG i) : SV_Target
{
FRAGMENT_SETUP(s)
- UnityLight mainLight = MainLight (s.normalWorld);
+ UnityLight mainLight = MainLight ();
half atten = SHADOW_ATTENUATION(i);
half occlusion = Occlusion(i.tex.xy);
UnityGI gi = FragmentGI (
- s.posWorld, occlusion, i.ambientOrLightmapUV, atten, s.oneMinusRoughness, s.normalWorld, s.eyeVec, mainLight);
+ s.posWorld, occlusion, i.ambientOrLightmapUV, atten, s.smoothness, s.normalWorld, s.eyeVec, mainLight);
- half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect);
+ half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect);
c *= i.color;
- c.rgb += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, occlusion, gi);
+ 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);
@@ -143,7 +143,7 @@ struct VertexOutputDeferred_SVG
half3 eyeVec : TEXCOORD1;
half4 tangentToWorldAndParallax[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
half4 ambientOrLightmapUV : TEXCOORD5; // SH or Lightmap UVs
- #if UNITY_SPECCUBE_BOX_PROJECTION
+ #if UNITY_REQUIRE_FRAG_WORLDPOS
float3 posWorld : TEXCOORD6;
#endif
};
@@ -154,7 +154,7 @@ VertexOutputDeferred_SVG vertDeferred_SVG (VertexInput_SVG v)
UNITY_INITIALIZE_OUTPUT(VertexOutputDeferred_SVG, o);
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
- #if UNITY_SPECCUBE_BOX_PROJECTION
+ #if UNITY_REQUIRE_FRAG_WORLDPOS
o.posWorld = posWorld;
#endif
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
@@ -204,16 +204,16 @@ VertexOutputDeferred_SVG vertDeferred_SVG (VertexInput_SVG v)
void fragDeferred_SVG (
VertexOutputDeferred_SVG i,
- out half4 outDiffuse : SV_Target0, // RT0: diffuse color (rgb), occlusion (a)
- out half4 outSpecSmoothness : SV_Target1, // RT1: spec color (rgb), smoothness (a)
- out half4 outNormal : SV_Target2, // RT2: normal (rgb), --unused, very low precision-- (a)
+ out half4 outGBuffer0 : SV_Target0,
+ out half4 outGBuffer1 : SV_Target1,
+ out half4 outGBuffer2 : SV_Target2,
out half4 outEmission : SV_Target3 // RT3: emission (rgb), --unused-- (a)
)
{
#if (SHADER_TARGET < 30)
- outDiffuse = 1;
- outSpecSmoothness = 1;
- outNormal = 0;
+ outGBuffer0 = 1;
+ outGBuffer1 = 1;
+ outGBuffer2 = 0;
outEmission = 0;
return;
#endif
@@ -221,30 +221,42 @@ void fragDeferred_SVG (
FRAGMENT_SETUP(s)
// no analytic lights in this pass
- UnityLight dummyLight = DummyLight (s.normalWorld);
+ UnityLight dummyLight = DummyLight ();
half atten = 1;
// only GI
half occlusion = Occlusion(i.tex.xy);
- UnityGI gi = FragmentGI (
- s.posWorld, occlusion, i.ambientOrLightmapUV, atten, s.oneMinusRoughness, s.normalWorld, s.eyeVec, dummyLight);
+#if UNITY_ENABLE_REFLECTION_BUFFERS
+ bool sampleReflectionsInDeferred = false;
+#else
+ bool sampleReflectionsInDeferred = true;
+#endif
+
+ UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, dummyLight, sampleReflectionsInDeferred);
- half3 color = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect).rgb;
- color *= i.color;
- color += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.oneMinusRoughness, s.normalWorld, -s.eyeVec, occlusion, gi);
+ 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
- color += Emission (i.tex.xy);
+ emissiveColor += Emission (i.tex.xy);
#endif
#ifndef UNITY_HDR_ON
- color.rgb = exp2(-color.rgb);
+ emissiveColor.rgb = exp2(-emissiveColor.rgb);
#endif
- outDiffuse = half4(s.diffColor * i.color.rgb, occlusion);
- outSpecSmoothness = half4(s.specColor * i.color.rgb, s.oneMinusRoughness);
- outNormal = half4(s.normalWorld*0.5+0.5,1);
- outEmission = half4(color, 1);
+ UnityStandardData data;
+ data.diffuseColor = s.diffColor;
+ data.occlusion = occlusion;
+ data.specularColor = s.specColor;
+ data.smoothness = s.smoothness;
+ data.normalWorld = s.normalWorld;
+
+ UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2);
+
+ // Emisive lighting buffer
+ outEmission = half4(emissiveColor, 1);
}
#endif
\ No newline at end of file
--
2.8.1.windows.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment