Skip to content

Commit

Permalink
Yup, shader variants were the issue. I set it up to track the shader …
Browse files Browse the repository at this point in the history
…variants used in the editor, and started removing some of the unnecessary variations
  • Loading branch information
TheMasonX committed Jan 24, 2018
1 parent 740b4bd commit 9a6762f
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 47 deletions.
Binary file modified Assets/PCSS/Demo/Demo Assets/Palm Trees/Materials/Palm.mat
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Shader "Custom/NewSurfaceShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

sampler2D _MainTex;

struct Input {
float2 uv_MainTex;
};

half _Glossiness;
half _Metallic;
fixed4 _Color;

// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)

void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
float _WindFrequency;
float _WindAmplitude;

UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)

void vert(inout appdata v)
{
float3 pos = mul(v.vertex, unity_ObjectToWorld);
Expand Down
Binary file modified Assets/PCSS/Demo/PCSS Demo.unity
Binary file not shown.
40 changes: 18 additions & 22 deletions Assets/PCSS/Scripts/PCSSLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class PCSSLight : MonoBehaviour
public int PCF_SampleCount = 16;

[Space(20f)]
public bool RotateSamples = true;
public bool UseNoiseTexture = true;
// public bool RotateSamples = true;
// public bool UseNoiseTexture = true;
public Texture2D noiseTexture;

[Space(20f)]
Expand Down Expand Up @@ -95,13 +95,13 @@ public void Setup ()
_light.shadowCustomResolution = 0;

shader = Shader.Find(shaderName);
if (!Application.isEditor)
{
if (shader)
Debug.LogErrorFormat("Custom Shadow Shader Found: {0} | Supported {1}", shader.name, shader.isSupported);
else
Debug.LogError("Custom Shadow Shader Not Found!!!");
}
// if (!Application.isEditor)
// {
// if (shader)
// Debug.LogErrorFormat("Custom Shadow Shader Found: {0} | Supported {1}", shader.name, shader.isSupported);
// else
// Debug.LogError("Custom Shadow Shader Not Found!!!");
// }
shadowmapPropID = Shader.PropertyToID("_ShadowMap");

copyShadowBuffer = new CommandBuffer();
Expand Down Expand Up @@ -136,18 +136,14 @@ public void CreateShadowRenderTexture ()
[ContextMenu("Reset Shadows To Default")]
public void ResetShadowMode ()
{
// //Unity 2017 seems to have issues with the 'ResetShadowMode()' being called during 'OnDisable()' in builds, though it works fine in the editor
// if (!Application.isEditor)
// return;

builtinShader = Shader.Find(builtinShaderName);
if (!Application.isEditor)
{
if (builtinShader)
Debug.LogErrorFormat("Built-In Shadow Shader Found: {0} | Supported {1}", builtinShader.name, builtinShader.isSupported);
else
Debug.LogError("Shadow Shader Not Found!!!");
}
// if (!Application.isEditor)
// {
// if (builtinShader)
// Debug.LogErrorFormat("Built-In Shadow Shader Found: {0} | Supported {1}", builtinShader.name, builtinShader.isSupported);
// else
// Debug.LogError("Shadow Shader Not Found!!!");
// }

GraphicsSettings.SetCustomShader(BuiltinShaderType.ScreenSpaceShadows, builtinShader);
GraphicsSettings.SetShaderMode(BuiltinShaderType.ScreenSpaceShadows, BuiltinShaderMode.Disabled);
Expand Down Expand Up @@ -195,8 +191,8 @@ public void UpdateShaderValues ()
SetFlag("USE_BLOCKER_BIAS", Blocker_GradientBias > 0);
SetFlag("USE_PCF_BIAS", PCF_GradientBias > 0);

SetFlag("ROTATE_SAMPLES", RotateSamples);
SetFlag("USE_NOISE_TEX", UseNoiseTexture);
// SetFlag("ROTATE_SAMPLES", RotateSamples);
// SetFlag("USE_NOISE_TEX", UseNoiseTexture);

if (noiseTexture)
{
Expand Down
Binary file modified Assets/PCSS/Shaders/PCSS-ShaderVariants.shadervariants
Binary file not shown.
49 changes: 24 additions & 25 deletions Assets/PCSS/Shaders/PCSS.shader
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ float2 FindBlocker(float2 uv, float depth, float searchUV, float2 receiverPlaneD
{
float2 offset = PoissonOffsets[i] * searchUV;

#if defined(ROTATE_SAMPLES)
//#if defined(ROTATE_SAMPLES)
offset = Rotate(offset, rotationTrig);
#endif
//#endif

float shadowMapDepth = SampleShadowmapDepth(uv + offset);

Expand Down Expand Up @@ -488,9 +488,9 @@ float PCF_Filter(float2 uv, float depth, float filterRadiusUV, float2 receiverPl
{
float2 offset = PoissonOffsets[i] * filterRadiusUV;

#if defined(ROTATE_SAMPLES)
//#if defined(ROTATE_SAMPLES)
offset = Rotate(offset, rotationTrig);
#endif
//#endif

float biasedDepth = depth;

Expand Down Expand Up @@ -607,13 +607,12 @@ fixed4 frag_pcss (v2f i) : SV_Target
fixed4 cascadeWeights = GET_CASCADE_WEIGHTS(wpos, vpos.z);
float4 coord = GET_SHADOW_COORDINATES(wpos, cascadeWeights);

#if defined(USE_NOISE_TEX)
//#if defined(USE_NOISE_TEX)
float random = tex2D(_NoiseTexture, i.uv.xy * NoiseCoords.xy * _ScreenParams.xy).a;
random = mad(random, 2.0, -1.0);
//random = sign(random) * (1.0 - sqrt(1.0 - abs(random)));
#else
float random = ValueNoise(wpos.xyz);
#endif
//#else
// float random = ValueNoise(wpos.xyz);
//#endif

float2 receiverPlaneDepthBiasCascade0 = 0.0;
float2 receiverPlaneDepthBias = 0.0;
Expand Down Expand Up @@ -765,14 +764,14 @@ Subshader
#pragma multi_compile_shadowcollector
#pragma multi_compile POISSON_32 POISSON_64

#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
#pragma shader_feature USE_FALLOFF
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature USE_STATIC_BIAS
#pragma shader_feature USE_BLOCKER_BIAS
#pragma shader_feature USE_PCF_BIAS
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature ROTATE_SAMPLES
#pragma shader_feature USE_NOISE_TEX
#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
// #pragma shader_feature ROTATE_SAMPLES
// #pragma shader_feature USE_NOISE_TEX
#pragma target 3.0

inline float3 computeCameraSpacePosFromDepth(v2f i)
Expand All @@ -797,14 +796,14 @@ Subshader
#pragma multi_compile_shadowcollector
#pragma multi_compile POISSON_32 POISSON_64

#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
#pragma shader_feature USE_FALLOFF
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature USE_STATIC_BIAS
#pragma shader_feature USE_BLOCKER_BIAS
#pragma shader_feature USE_PCF_BIAS
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature ROTATE_SAMPLES
#pragma shader_feature USE_NOISE_TEX
#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
// #pragma shader_feature ROTATE_SAMPLES
// #pragma shader_feature USE_NOISE_TEX
#pragma target 3.0

inline float3 computeCameraSpacePosFromDepth(v2f i)
Expand Down Expand Up @@ -833,14 +832,14 @@ Subshader
#pragma multi_compile_shadowcollector
#pragma multi_compile POISSON_32 POISSON_64

#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
#pragma shader_feature USE_FALLOFF
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature USE_STATIC_BIAS
#pragma shader_feature USE_BLOCKER_BIAS
#pragma shader_feature USE_PCF_BIAS
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature ROTATE_SAMPLES
#pragma shader_feature USE_NOISE_TEX
#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
// #pragma shader_feature ROTATE_SAMPLES
// #pragma shader_feature USE_NOISE_TEX
#pragma target 3.0

inline float3 computeCameraSpacePosFromDepth(v2f i)
Expand All @@ -865,14 +864,14 @@ Subshader
#pragma multi_compile_shadowcollector
#pragma multi_compile POISSON_32 POISSON_64

#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
#pragma shader_feature USE_FALLOFF
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature USE_STATIC_BIAS
#pragma shader_feature USE_BLOCKER_BIAS
#pragma shader_feature USE_PCF_BIAS
#pragma shader_feature USE_CASCADE_BLENDING
#pragma shader_feature ROTATE_SAMPLES
#pragma shader_feature USE_NOISE_TEX
#pragma shader_feature ORTHOGRAPHIC_SUPPORTED
// #pragma shader_feature ROTATE_SAMPLES
// #pragma shader_feature USE_NOISE_TEX
#pragma target 3.0

inline float3 computeCameraSpacePosFromDepth(v2f i)
Expand Down
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.

0 comments on commit 9a6762f

Please sign in to comment.