예제 #1
0
        private void ComputeSliceAndMask(ShaderKeyword keyword, out uint slice, out uint mask)
        {
            int index = keyword.GetKeywordIndex();

            slice = (uint)(index / k_SizeInBits);
            mask  = (uint)(1 << (index % k_SizeInBits));
        }
예제 #2
0
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Rendering.ShaderKeyword o;
         System.String a1;
         checkType(l, 2, out a1);
         o = new UnityEngine.Rendering.ShaderKeyword(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
예제 #3
0
 static public int GetName(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Rendering.ShaderKeyword self = (UnityEngine.Rendering.ShaderKeyword)checkSelf(l);
         var ret = self.GetName();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
 public static ShaderKeywordType GetGlobalKeywordType(ShaderKeyword index)
 {
     if (index.IsValid())
     {
         return(GetGlobalShaderKeywordType(index.m_Index));
     }
     return(ShaderKeywordType.UserDefined);
 }
예제 #5
0
 public void Disable(ShaderKeyword keyword)
 {
     if (keyword.m_IsLocal || !keyword.IsValid())
     {
         DisableKeywordName(this, keyword.m_Name);
     }
     else
     {
         DisableGlobalKeyword(this, keyword.m_Index);
     }
 }
예제 #6
0
 public void Enable(ShaderKeyword keyword)
 {
     CheckKeywordCompatible(keyword);
     if (keyword.m_IsLocal || !keyword.IsValid())
     {
         EnableKeywordName(this, keyword.m_Name);
     }
     else
     {
         EnableGlobalKeyword(this, keyword.m_Index);
     }
 }
 static public int GetKeywordName(IntPtr l)
 {
     try {
         UnityEngine.Rendering.ShaderKeyword self = (UnityEngine.Rendering.ShaderKeyword)checkSelf(l);
         var ret = self.GetKeywordName();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #8
0
 private void CheckKeywordCompatible(ShaderKeyword keyword)
 {
     if (keyword.m_IsLocal)
     {
         if (m_Shader != IntPtr.Zero)
         {
             Assert.IsTrue(!keyword.m_IsCompute, "Trying to use a keyword that comes from a different shader.");
         }
         else
         {
             Assert.IsTrue(keyword.m_IsCompute, "Trying to use a keyword that comes from a different shader.");
         }
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Rendering.ShaderKeyword o;
         System.String a1;
         checkType(l, 2, out a1);
         o = new UnityEngine.Rendering.ShaderKeyword(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #10
0
        public void Disable(ShaderKeyword keyword)
        {
            if (!keyword.IsValid())
            {
                return;
            }

            uint slice, mask;

            ComputeSliceAndMask(keyword, out slice, out mask);
            fixed(uint *bits = m_Bits)
            {
                bits[slice] &= ~mask;
            }
        }
예제 #11
0
        public bool IsEnabled(ShaderKeyword keyword)
        {
            if (!keyword.IsValid())
            {
                return(false);
            }

            uint slice, mask;

            ComputeSliceAndMask(keyword, out slice, out mask);
            fixed(uint *bits = m_Bits)
            {
                return((bits[slice] & mask) != 0);
            }
        }
예제 #12
0
        public    ShaderKeyword[] GetShaderKeywords()
        {
            ShaderKeyword[] shaderKeywords = new ShaderKeyword[ShaderKeyword.k_MaxShaderKeywords];
            int             keywordCount   = 0;

            for (int keywordIndex = 0; keywordIndex < ShaderKeyword.k_MaxShaderKeywords; ++keywordIndex)
            {
                ShaderKeyword keyword = new ShaderKeyword(keywordIndex);
                if (IsEnabled(keyword))
                {
                    shaderKeywords[keywordCount] = keyword;
                    ++keywordCount;
                }
            }
            Array.Resize <ShaderKeyword>(ref shaderKeywords, keywordCount);
            return(shaderKeywords);
        }
예제 #13
0
 public static ShaderKeywordType GetKeywordType(ComputeShader shader, ShaderKeyword index)
 {
     return(ShaderKeyword.GetComputeShaderKeywordType(shader, index));
 }
예제 #14
0
 public ShaderKeyword(string keywordName)
 {
     this.m_KeywordIndex = ShaderKeyword.GetGlobalKeywordIndex(keywordName);
 }
예제 #15
0
 public LitShaderPreprocessor()
 {
     m_ForceForwardEmissive = new UnityEngine.Rendering.ShaderKeyword("_FORCE_FORWARD_EMISSIVE");
 }
 public static void SetShaderKeywordIndex(UnityEngine.Rendering.ShaderKeyword shaderKeyword, int keywordIndex)
 {
     KEYWORD_INDEX_FIELDINFO.SetValue(shaderKeyword, keywordIndex);
 }
 [FreeFunction("ShaderScripting::GetKeywordName")] extern public static string GetKeywordName(Shader shader, ShaderKeyword index);
 public static string GetGlobalKeywordName(ShaderKeyword index)
 {
     return(index.m_Name);
 }
예제 #19
0
 internal static ShaderKeywordType GetComputeShaderKeywordType(ComputeShader shader, ShaderKeyword index)
 {
     return(ShaderKeyword.GetComputeShaderKeywordType_Injected(shader, ref index));
 }
예제 #20
0
 public bool IsEnabled(ShaderKeyword keyword)
 {
     CheckKeywordCompatible(keyword);
     return(IsKeywordNameEnabled(this, keyword.m_Name));
 }
 public static bool IsKeywordLocal(ShaderKeyword keyword)
 {
     return(keyword.m_IsLocal);
 }
 [FreeFunction("ShaderScripting::GetKeywordType")] extern public static ShaderKeywordType GetKeywordType(Shader shader, ShaderKeyword index);
예제 #23
0
 public static string GetKeywordName(ComputeShader shader, ShaderKeyword index)
 {
     return(ShaderKeyword.GetComputeShaderKeywordName(shader, index));
 }
예제 #24
0
 public ShaderKeyword(Shader shader, string keywordName)
 {
     this.m_KeywordIndex = ShaderKeyword.GetKeywordIndex(shader, keywordName);
 }
 public static int GetShaderKeywordIndex(UnityEngine.Rendering.ShaderKeyword shaderKeyword)
 {
     return((int)KEYWORD_INDEX_FIELDINFO.GetValue(shaderKeyword));
 }
 [FreeFunction("ShaderScripting::IsKeywordLocal")]       extern public static bool IsKeywordLocal(ShaderKeyword index);
 public static ShaderKeywordType GetKeywordType(ComputeShader shader, ShaderKeyword index)
 {
     return(ShaderKeywordType.UserDefined);
 }
예제 #28
0
        bool LitShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData)
        {
            if (CommonShaderStripper(hdrpAsset, shader, snippet, inputData))
            {
                return(true);
            }

            bool isGBufferPass = snippet.passName == "GBuffer";
            //bool isForwardPass = snippet.passName == "Forward";
            bool isDepthOnlyPass          = snippet.passName == "DepthOnly";
            bool isTransparentForwardPass = snippet.passName == "TransparentDepthPostpass" || snippet.passName == "TransparentBackface" || snippet.passName == "TransparentDepthPrepass";

            // When using forward only, we never need GBuffer pass (only Forward)
            if (hdrpAsset.renderPipelineSettings.supportOnlyForward && isGBufferPass)
            {
                return(true);
            }

            if (inputData.shaderKeywordSet.IsEnabled(m_Transparent))
            {
                // If transparent, we never need GBuffer pass.
                if (isGBufferPass)
                {
                    return(true);
                }
            }
            else // Opaque
            {
                // If opaque, we never need transparent specific passes (even in forward only mode)
                if (isTransparentForwardPass)
                {
                    return(true);
                }

                // When we are in deferred (i.e !hdrpAsset.renderPipelineSettings.supportOnlyForward), we only support tile lighting
                if (!hdrpAsset.renderPipelineSettings.supportOnlyForward && inputData.shaderKeywordSet.IsEnabled(m_ClusterLighting))
                {
                    return(true);
                }

                if (isDepthOnlyPass)
                {
                    // When we are full forward, we don't have depth prepass without writeNormalBuffer
                    if (hdrpAsset.renderPipelineSettings.supportOnlyForward && !inputData.shaderKeywordSet.IsEnabled(m_WriteNormalBuffer))
                    {
                        return(true);
                    }
                }

                // TODO: add an option to say we are using only the deferred shader variant (for Lit)
                //if (0)
                {
                    // If opaque and not forward only, then we only need the forward debug pass.
                    //if (isForwardPass && !inputData.shaderKeywordSet.IsEnabled(m_DebugDisplay))
                    //    return true;
                }
            }

//forest-begin: G-Buffer motion vectors
            if (inputData.shaderCompilerPlatform != ShaderCompilerPlatform.PS4 && inputData.shaderCompilerPlatform != ShaderCompilerPlatform.XboxOneD3D11 && inputData.shaderCompilerPlatform != ShaderCompilerPlatform.XboxOneD3D12)
            {
                if (shader.name == "HDRenderPipeline/Lit" || shader.name == "HDRenderPipeline/LitTessellation")
                {
                    var gBufferMotionVectors   = new UnityEngine.Rendering.ShaderKeyword("GBUFFER_MOTION_VECTORS");
                    var isGBufferMotionVectors = inputData.shaderKeywordSet.IsEnabled(gBufferMotionVectors);

                    if (hdrpAsset.GetFrameSettings().enableGBufferMotionVectors)
                    {
                        if (isGBufferPass && !isGBufferMotionVectors)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (isGBufferMotionVectors)
                        {
                            return(true);
                        }
                    }
                }
            }
//forest-end:

            // TODO: Tests for later
            // We need to find a way to strip useless shader features for passes/shader stages that don't need them (example, vertex shaders won't ever need SSS Feature flag)
            // This causes several problems:
            // - Runtime code that "finds" shader variants based on feature flags might not find them anymore... thus fall backing to the "let's give a score to variant" code path that may find the wrong variant.
            // - Another issue is that if a feature is declared without a "_" fall-back, if we strip the other variants, none may be left to use! This needs to be changed on our side.
            //if (snippet.shaderType == ShaderType.Vertex && inputData.shaderKeywordSet.IsEnabled(m_FeatureSSS))
            //    return true;

            return(false);
        }
 public static string GetKeywordName(ComputeShader shader, ShaderKeyword index)
 {
     return(index.m_Name);
 }
예제 #30
0
 internal static string GetComputeShaderKeywordName(ComputeShader shader, ShaderKeyword index)
 {
     return(ShaderKeyword.GetComputeShaderKeywordName_Injected(shader, ref index));
 }