Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add FPSSample v0.1.1 SRP Diff
  • Loading branch information
0lento committed Nov 24, 2018
1 parent c5821cb commit b84221b
Show file tree
Hide file tree
Showing 27 changed files with 327 additions and 135 deletions.
Expand Up @@ -227,6 +227,8 @@ VolumeComponent CreateNewComponent(Type type)
return effect;
}

// sample-game begin: fix against SaveAssets() calling GC and destroying assets not referenced
private ScriptableObject m_TempRefToAvoidGettingDestroyed;
internal void AddComponent(Type type)
{
m_SerializedObject.Update();
Expand All @@ -248,8 +250,11 @@ internal void AddComponent(Type type)
if (EditorUtility.IsPersistent(asset))
{
EditorUtility.SetDirty(asset);
m_TempRefToAvoidGettingDestroyed = component;
AssetDatabase.SaveAssets();
m_TempRefToAvoidGettingDestroyed = null;
}
// sample-game end

// Create & store the internal editor object for this effect
CreateEditor(component, componentProp, forceOpen: true);
Expand Down
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;

namespace UnityEditor.Experimental.Rendering.HDPipeline
{
Expand Down Expand Up @@ -102,6 +103,12 @@ class HDRPreprocessShaders : IPreprocessShaders

public HDRPreprocessShaders()
{
// Samplegame hack
m_CurrentHDRPAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
materialList = HDEditorUtils.GetBaseShaderPreprocessorList();

// EXISTING CODE; BROKEN WHEN BUILDING BATCHMOD
/*
// TODO: Grab correct configuration/quality asset.
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (hdPipeline != null)
Expand All @@ -110,6 +117,7 @@ public HDRPreprocessShaders()
materialList = HDEditorUtils.GetBaseShaderPreprocessorList();
}
*/
}

public int callbackOrder { get { return 0; } }
Expand Down
Expand Up @@ -462,5 +462,10 @@ static public void SetupMaterialKeywordsAndPass(Material _material)
CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);
}

protected override void FpsModePropertiesGUI()
{

}
}
} // namespace UnityEditor
Expand Up @@ -4,7 +4,7 @@
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
//should be base for al material in hdrp. It will add the collapsable mecanisme on them
abstract class ExpendableAreaMaterial : ShaderGUI
public abstract class ExpendableAreaMaterial : ShaderGUI
{
protected interface IExpendableArea
{
Expand Down
Expand Up @@ -760,6 +760,11 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
}
MaterialTesselationPropertiesGUI();
VertexAnimationPropertiesGUI();

EditorGUILayout.Space();
FpsModePropertiesGUI();
EditorGUILayout.Space();

}
if (EditorGUI.EndChangeCheck())
{
Expand Down
Expand Up @@ -9,7 +9,7 @@ namespace UnityEditor.Experimental.Rendering.HDPipeline
// Such a Material will share some properties between it various variant (shader graph variant or hand authored variant).
// This is the purpose of BaseLitGUI. It contain all properties that are common to all Material based on Lit template.
// For the default hand written Lit material see LitUI.cs that contain specific properties for our default implementation.
abstract class BaseLitGUI : BaseUnlitGUI
public abstract class BaseLitGUI : BaseUnlitGUI
{
protected static class StylesBaseLit
{
Expand Down Expand Up @@ -59,6 +59,11 @@ protected static class StylesBaseLit

public static GUIContent supportDecalsText = new GUIContent("Enable Decal", "Allow to specify if the material can receive decal or not");

// FPS Mode
public static GUIContent fpsModeText = new GUIContent("Enable FPS Mode");
public static GUIContent fpsModeFovText = new GUIContent("Fov");
public static string fpsMode = "FPS Mode";

public static GUIContent enableGeometricSpecularAAText = new GUIContent("Enable geometric specular AA", "This reduce specular aliasing on highly dense mesh (Particularly useful when they don't use normal map)");
public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Allow to control the strength of the specular AA reduction. Higher mean more blurry result and less aliasing");
public static GUIContent specularAAThresholdText = new GUIContent("Threshold", "Allow to limit the effect of specular AA reduction. 0 mean don't apply reduction, higher value mean allow higher reduction");
Expand Down Expand Up @@ -153,6 +158,12 @@ public enum HeightmapParametrization
protected MaterialProperty windShiverDirectionality = null;
protected const string kWindShiverDirectionality = "_ShiverDirectionality";

// Fps mode
protected MaterialProperty fpsModeEnable = null;
protected const string kFpsModeEnabled = "_EnableFpsMode";
protected MaterialProperty fpsModeFov = null;
protected const string kFpsModeFov = "_FpsModeFov";

// tessellation params
protected MaterialProperty tessellationMode = null;
protected const string kTessellationMode = "_TessellationMode";
Expand Down Expand Up @@ -219,6 +230,9 @@ protected override void FindBaseMaterialProperties(MaterialProperty[] props)
windShiverDrag = FindProperty(kWindShiverDrag, props, false);
windShiverDirectionality = FindProperty(kWindShiverDirectionality, props, false);

fpsModeEnable = FindProperty(kFpsModeEnabled, props);
fpsModeFov = FindProperty(kFpsModeFov, props);

// Decal
supportDecals = FindProperty(kSupportDecals, props, false);

Expand Down Expand Up @@ -369,6 +383,7 @@ public override void ShaderPropertiesGUI(Material material)
}
MaterialTesselationPropertiesGUI();
VertexAnimationPropertiesGUI();
FpsModePropertiesGUI();
MaterialPropertiesGUI(material);
DoEmissionArea(material);
using (var header = new HeaderScope(StylesBaseUnlit.advancedText, (uint)Expendable.Advance, this))
Expand Down Expand Up @@ -418,6 +433,22 @@ protected override void VertexAnimationPropertiesGUI()
}
}

protected override void FpsModePropertiesGUI()
{
GUILayout.Label(StylesBaseLit.fpsMode, EditorStyles.boldLabel);

EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(fpsModeEnable, StylesBaseLit.fpsModeText);
if (fpsModeEnable.floatValue > 0.0f)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(fpsModeFov, StylesBaseLit.fpsModeFovText);
EditorGUI.indentLevel--;
}

EditorGUI.indentLevel--;
}

// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
static public void SetupBaseLitKeywords(Material material)
{
Expand Down Expand Up @@ -488,6 +519,9 @@ static public void SetupBaseLitKeywords(Material material)
CoreUtils.SetKeyword(material, "_TESSELLATION_PHONG", tessMode == TessellationMode.Phong);
}

bool fpsModeEnabled = material.GetFloat(kFpsModeEnabled) > 0.0f;
CoreUtils.SetKeyword(material, "_FPS_MODE", fpsModeEnabled);

SetupMainTexForAlphaTestGI("_BaseColorMap", "_BaseColor", material);

// Use negation so we don't create keyword by default
Expand Down
Expand Up @@ -5,7 +5,7 @@

namespace UnityEditor.Experimental.Rendering.HDPipeline
{
class LitGUI : BaseLitGUI
public class LitGUI : BaseLitGUI
{
static Expendable state = Expendable.Base | Expendable.Input | Expendable.VertexAnimation | Expendable.Detail | Expendable.Emissive | Expendable.Transparency | Expendable.Tesselation;
protected override uint expendedState { get { return (uint)state; } set { state = (Expendable)value; } }
Expand Down
Expand Up @@ -271,6 +271,11 @@ public StackLitGUI()
});
}

protected override void FpsModePropertiesGUI()
{

}

protected override bool ShouldEmissionBeEnabled(Material material)
{
return (material.GetColor(k_EmissiveColor) != Color.black) || material.GetTexture(k_EmissiveColorMap);
Expand Down
Expand Up @@ -9,7 +9,7 @@ namespace UnityEditor.Experimental.Rendering.HDPipeline
// Such a Material will share some properties between it various variant (shader graph variant or hand authored variant).
// This is the purpose of BaseLitGUI. It contain all properties that are common to all Material based on Lit template.
// For the default hand written Lit material see LitUI.cs that contain specific properties for our default implementation.
abstract class BaseUnlitGUI : ExpendableAreaMaterial
public abstract class BaseUnlitGUI : ExpendableAreaMaterial
{
//Be sure to end before after last LayeredLitGUI.LayerExpendable
[Flags]
Expand Down Expand Up @@ -158,6 +158,7 @@ public enum BlendMode
protected abstract void MaterialPropertiesGUI(Material material);
protected virtual void MaterialPropertiesAdvanceGUI(Material material) {}
protected abstract void VertexAnimationPropertiesGUI();
protected abstract void FpsModePropertiesGUI();
// This function will say if emissive is used or not regarding enlighten/PVR
protected virtual bool ShouldEmissionBeEnabled(Material material) { return false; }

Expand Down Expand Up @@ -637,6 +638,11 @@ public virtual void ShaderPropertiesGUI(Material material)
BaseMaterialPropertiesGUI();
}
VertexAnimationPropertiesGUI();

EditorGUILayout.Space();
FpsModePropertiesGUI();
EditorGUILayout.Space();

MaterialPropertiesGUI(material);
DoEmissionArea(material);
using (var header = new HeaderScope(StylesBaseUnlit.advancedText, (uint)Expendable.Advance, this))
Expand Down
Expand Up @@ -70,6 +70,10 @@ protected override void VertexAnimationPropertiesGUI()
{
}

protected override void FpsModePropertiesGUI()
{
}

protected override bool ShouldEmissionBeEnabled(Material material)
{
return (material.GetColor(kEmissiveColor) != Color.black) || material.GetTexture(kEmissiveColorMap);
Expand Down
Expand Up @@ -154,6 +154,10 @@ void SHADE_OPAQUE_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 grou
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);

// sample-game-begin: fix against emitting value so high it will end up as INF when it passes through ROP .. and then later bacomes NaN party
specularLighting = min(specularLighting, 65000.0f);
// sample-game-end

if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
{
specularLightingUAV[pixelCoord] = float4(specularLighting, 1.0);
Expand Down
Expand Up @@ -37,6 +37,10 @@ public float[] cascadeShadowBorders
}
}

// sample-game begin: global tweak for shadow distance
public static float shadowDistanceMultiplier = 1.0f;
// sample-game end

[Tooltip("Maximum shadow distance for all light types.")]
public NoInterpMinFloatParameter maxShadowDistance = new NoInterpMinFloatParameter(500.0f, 0.0f);

Expand Down
Expand Up @@ -109,6 +109,8 @@ public void OnValidate()
}
}

// sample-game begin: dont call update when in standanlone
#if !UNITY_STANDALONE
public void LateUpdate()
{
if (m_Handle != null)
Expand All @@ -122,6 +124,8 @@ public void LateUpdate()
}
}
}
#endif
// sample-game end

public void OnDrawGizmosSelected()
{
Expand Down
Expand Up @@ -227,6 +227,9 @@ Shader "HDRenderPipeline/LayeredLit"

// Following are builtin properties

[ToggleUI] _EnableFpsMode("Enable Fps Mode", Float) = 0.0
_FpsModeFov("_FpsModeFov", Float) = 60.0

[ToggleUI] _EnableSpecularOcclusion("Enable specular occlusion", Float) = 0.0

[HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
Expand Down Expand Up @@ -414,6 +417,7 @@ Shader "HDRenderPipeline/LayeredLit"
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS

#pragma shader_feature _DISABLE_DECALS
#pragma shader_feature _FPS_MODE
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA

// Keyword for transparent
Expand All @@ -433,6 +437,12 @@ Shader "HDRenderPipeline/LayeredLit"
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer

// sample-game begin: hard link DIRLIGHTMAP_COMBINED to LIGHTMAP_ON to avoid a multicompile
#ifdef LIGHTMAP_ON
#define DIRLIGHTMAP_COMBINED
#endif
// sample-game end

//-------------------------------------------------------------------------------------
// Define
//-------------------------------------------------------------------------------------
Expand Down Expand Up @@ -536,14 +546,18 @@ Shader "HDRenderPipeline/LayeredLit"

HLSLPROGRAM

#pragma multi_compile _ DEBUG_DISPLAY
// sample-game begin: limit to what we use
//#pragma multi_compile _ DEBUG_DISPLAY
#pragma shader_feature DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ SHADOWS_SHADOWMASK
//#pragma multi_compile _ DIRLIGHTMAP_COMBINED
//#pragma multi_compile _ DYNAMICLIGHTMAP_ON
//#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile _ LIGHT_LAYERS
// sample-game end

#ifdef _ALPHATEST_ON
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer
Expand Down Expand Up @@ -702,22 +716,29 @@ Shader "HDRenderPipeline/LayeredLit"

HLSLPROGRAM

#pragma multi_compile _ DEBUG_DISPLAY
// sample-game begin: limit to what we use
//#pragma multi_compile _ DEBUG_DISPLAY
#pragma shader_feature DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ SHADOWS_SHADOWMASK
//#pragma multi_compile _ DIRLIGHTMAP_COMBINED
//#pragma multi_compile _ DYNAMICLIGHTMAP_ON
//#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT

// Supported shadow modes per light type
#pragma multi_compile PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
#pragma multi_compile DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH

// #include "../../Lighting/Forward.hlsl"
//#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
#pragma multi_compile USE_CLUSTERED_LIGHTLIST
// #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Lighting/Forward.hlsl"
//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS

#define LIGHTLOOP_TILE_PASS
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
// sample-game end

#define SHADERPASS SHADERPASS_FORWARD
// In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
Expand Down

0 comments on commit b84221b

Please sign in to comment.