Example #1
0
        const string kSpecularOcclusionMode     = "_SpecularOcclusionMode"; // match AdvancedOptionsUIBlock.kSpecularOcclusionMode : TODO move both to HDStringConstants.

        // 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 SetupMaterialKeywordsAndPass(Material material)
        {
            material.SetupBaseUnlitKeywords();
            material.SetupBaseUnlitPass();

            AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(kAxF_BRDFType);

            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);

            // Keywords for opt-out of decals and SSR:
            bool decalsEnabled = material.HasProperty(kEnableDecals) && material.GetFloat(kEnableDecals) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_DECALS", decalsEnabled == false);
            bool ssrEnabled = material.HasProperty(kEnableSSR) && material.GetFloat(kEnableSSR) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_SSR", ssrEnabled == false);
            CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.HasProperty(kEnableGeometricSpecularAA) && material.GetFloat(kEnableGeometricSpecularAA) > 0.0f);
            CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", material.HasProperty(kSpecularOcclusionMode) && material.GetFloat(kSpecularOcclusionMode) == 0.0f);

            BaseLitGUI.SetupStencil(material, receivesSSR: ssrEnabled, useSplitLighting: false);

            if (material.HasProperty(kAddPrecomputedVelocity))
            {
                CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
            }
        }
Example #2
0
        // 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 SetupMaterialKeywordsAndPass(Material material)
        {
            material.SetupBaseUnlitKeywords();
            material.SetupBaseUnlitPass();

            AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(kAxF_BRDFType);

            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);


            // Mapping Modes:
            AxFMappingMode mappingMode = (AxFMappingMode)material.GetFloat(kMappingMode);

            // Make sure the mask is synched:
            material.SetVector(kMappingMask, AxFMappingModeToMask(mappingMode));

            bool mappingIsPlanar = (mappingMode >= AxFMappingMode.PlanarXY) && (mappingMode < AxFMappingMode.Triplanar);
            bool planarIsLocal   = (material.GetFloat(kPlanarSpace) > 0.0f);

            CoreUtils.SetKeyword(material, "_MAPPING_PLANAR", mappingIsPlanar);
            CoreUtils.SetKeyword(material, "_MAPPING_TRIPLANAR", mappingMode == AxFMappingMode.Triplanar);

            if (mappingIsPlanar || mappingMode == AxFMappingMode.Triplanar)
            {
                CoreUtils.SetKeyword(material, "_PLANAR_LOCAL", planarIsLocal);
            }

            // Note: for ShaderPass defines for vertmesh/varyingmesh setup, we still use the same
            // defines _REQUIRE_UV2 and _REQUIRE_UV3, and thus if eg _REQUIRE_UV3 is defined, _REQUIRE_UV2 will
            // be assumed to be needed. But here in the AxFData sampling code, we use these to indicate precisely
            // the single set used (if not using planar/triplanar) only and thus add _REQUIRE_UV1.
            // Extra UVs might be transfered but we only need and support a single set at a time for the whole material.
            CoreUtils.SetKeyword(material, "_REQUIRE_UV1", mappingMode == AxFMappingMode.UV1);
            CoreUtils.SetKeyword(material, "_REQUIRE_UV2", mappingMode == AxFMappingMode.UV2);
            CoreUtils.SetKeyword(material, "_REQUIRE_UV3", mappingMode == AxFMappingMode.UV3);

            // Keywords for opt-out of decals and SSR:
            bool decalsEnabled = material.HasProperty(kEnableDecals) && material.GetFloat(kEnableDecals) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_DECALS", decalsEnabled == false);
            bool ssrEnabled = material.HasProperty(kEnableSSR) && material.GetFloat(kEnableSSR) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_SSR", ssrEnabled == false);
            CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.HasProperty(kEnableGeometricSpecularAA) && material.GetFloat(kEnableGeometricSpecularAA) > 0.0f);
            CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", material.HasProperty(kSpecularOcclusionMode) && material.GetFloat(kSpecularOcclusionMode) == 0.0f);

            BaseLitGUI.SetupStencil(material, receivesSSR: ssrEnabled, useSplitLighting: false);

            if (material.HasProperty(kAddPrecomputedVelocity))
            {
                CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
            }
        }
        // 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 SetupMaterialKeywordsAndPass(Material _material)
        {
            SetupBaseUnlitKeywords(_material);
            SetupBaseUnlitMaterialPass(_material);

            AxfBrdfType BRDFType = (AxfBrdfType)_material.GetFloat(m_AxF_BRDFTypeText);

            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);
        }
Example #4
0
        void DrawAxfSurfaceOptionsGUI()
        {
            materialEditor.ShaderProperty(m_MaterialTilingU, "Material Tiling U");
            materialEditor.ShaderProperty(m_MaterialTilingV, "Material Tiling V");

            AxfBrdfType AxF_BRDFType = (AxfBrdfType)m_AxF_BRDFType.floatValue;

            AxF_BRDFType = (AxfBrdfType)EditorGUILayout.Popup("BRDF Type", (int)AxF_BRDFType, AxfBrdfTypeNames);
            m_AxF_BRDFType.floatValue = (float)AxF_BRDFType;

            switch (AxF_BRDFType)
            {
            case AxfBrdfType.SVBRDF:
            {
                EditorGUILayout.Space();
                ++EditorGUI.indentLevel;

                // Read as compact flags
                uint flags        = (uint)m_Flags.floatValue;
                uint BRDFType     = (uint)m_SVBRDF_BRDFType.floatValue;
                uint BRDFVariants = (uint)m_SVBRDF_BRDFVariants.floatValue;

                SvbrdfDiffuseType          diffuseType    = (SvbrdfDiffuseType)(BRDFType & 0x1);
                SvbrdfSpecularType         specularType   = (SvbrdfSpecularType)((BRDFType >> 1) & 0x7);
                SvbrdfFresnelVariant       fresnelVariant = (SvbrdfFresnelVariant)(BRDFVariants & 0x3);
                SvbrdfSpecularVariantWard  wardVariant    = (SvbrdfSpecularVariantWard)((BRDFVariants >> 2) & 0x3);
                SvbrdfSpecularVariantBlinn blinnVariant   = (SvbrdfSpecularVariantBlinn)((BRDFVariants >> 4) & 0x3);

                // Expand as user-friendly UI
//                     EditorGUILayout.LabelField( "Flags", EditorStyles.boldLabel );
                EditorGUILayout.LabelField("BRDF Variants", EditorStyles.boldLabel);

                diffuseType  = (SvbrdfDiffuseType)EditorGUILayout.Popup("Diffuse Type", (int)diffuseType, SvbrdfDiffuseTypeNames);
                specularType = (SvbrdfSpecularType)EditorGUILayout.Popup("Specular Type", (int)specularType, SvbrdfSpecularTypeNames);

                if (specularType == SvbrdfSpecularType.WARD)
                {
                    fresnelVariant = (SvbrdfFresnelVariant)EditorGUILayout.Popup("Fresnel Variant", (int)fresnelVariant, SvbrdfFresnelVariantNames);
                    wardVariant    = (SvbrdfSpecularVariantWard)EditorGUILayout.Popup("Ward Variant", (int)wardVariant, SvbrdfSpecularVariantWardNames);
                }
                else if (specularType == SvbrdfSpecularType.BLINN_PHONG)
                {
                    blinnVariant = (SvbrdfSpecularVariantBlinn)EditorGUILayout.Popup("Blinn Variant", (int)blinnVariant, SvbrdfSpecularVariantBlinnNames);
                }

                // Regular maps
                materialEditor.TexturePropertySingleLine(Styles.diffuseColorMapText, m_DiffuseColorMap);
                materialEditor.TexturePropertySingleLine(Styles.specularColorMapText, m_SpecularColorMap);
                materialEditor.TexturePropertySingleLine(Styles.specularLobeMapText, m_SpecularLobeMap);
                m_SpecularLobeMapScale.floatValue = EditorGUILayout.FloatField(Styles.specularLobeMapScaleText, m_SpecularLobeMapScale.floatValue);
                materialEditor.TexturePropertySingleLine(Styles.fresnelMapText, m_FresnelMap);
                materialEditor.TexturePropertySingleLine(Styles.normalMapText, m_NormalMap);

                // Alpha
                materialEditor.TexturePropertySingleLine(Styles.alphaMapText, m_AlphaMap);

                // Displacement
                bool useDisplacementMap = EditorGUILayout.Toggle("Enable Displacement Map", (flags & 8) != 0);
                if (useDisplacementMap)
                {
                    ++EditorGUI.indentLevel;
                    materialEditor.TexturePropertySingleLine(Styles.heightMapText, m_HeightMap);
                    materialEditor.ShaderProperty(m_SVBRDF_HeightMapMaxMM, "Max Displacement (mm)");
                    --EditorGUI.indentLevel;
                }

                // Anisotropy
                bool isAnisotropic = EditorGUILayout.Toggle("Is Anisotropic", (flags & 1) != 0);
                if (isAnisotropic)
                {
                    ++EditorGUI.indentLevel;
                    materialEditor.TexturePropertySingleLine(Styles.anisoRotationMapText, m_AnisoRotationMap);
                    --EditorGUI.indentLevel;
                }

                // Clearcoat
                bool hasClearcoat            = EditorGUILayout.Toggle("Enable Clearcoat", (flags & 2) != 0);
                bool clearcoatUsesRefraction = (flags & 4) != 0;
                if (hasClearcoat)
                {
                    ++EditorGUI.indentLevel;
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatColorMapText, m_ClearcoatColorMap);
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap);
                    clearcoatUsesRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatUsesRefraction);
                    if (clearcoatUsesRefraction)
                    {
                        ++EditorGUI.indentLevel;
                        materialEditor.TexturePropertySingleLine(Styles.clearcoatIORMapText, m_ClearcoatIORMap);
                        --EditorGUI.indentLevel;
                    }
                    --EditorGUI.indentLevel;
                }

                // Write back as compact flags
                flags  = 0;
                flags |= isAnisotropic ? 1U : 0U;
                flags |= hasClearcoat ? 2U : 0U;
                flags |= clearcoatUsesRefraction ? 4U : 0U;
                flags |= useDisplacementMap ? 8U : 0U;

                BRDFType  = 0;
                BRDFType |= (uint)diffuseType;
                BRDFType |= ((uint)specularType) << 1;

                BRDFVariants  = 0;
                BRDFVariants |= (uint)fresnelVariant;
                BRDFVariants |= ((uint)wardVariant) << 2;
                BRDFVariants |= ((uint)blinnVariant) << 4;

//                    cmd.SetGlobalFloat( HDShaderIDs._TexturingModeFlags, *(float*) &texturingModeFlags );
                m_Flags.floatValue               = (float)flags;
                m_SVBRDF_BRDFType.floatValue     = (float)BRDFType;
                m_SVBRDF_BRDFVariants.floatValue = (float)BRDFVariants;

                --EditorGUI.indentLevel;
                break;
            }

            case AxfBrdfType.CAR_PAINT:
            {
                EditorGUILayout.Space();
                ++EditorGUI.indentLevel;

                // Read as compact flags
                uint flags = (uint)m_Flags.floatValue;

                bool isAnisotropic      = false;
                bool useDisplacementMap = false;

                // Expand as user-friendly UI

                // Regular maps
                materialEditor.TexturePropertySingleLine(Styles.BRDFColorMapText, m_CarPaint2_BRDFColorMap);
                m_CarPaint2_BRDFColorMapScale.floatValue = EditorGUILayout.FloatField(Styles.BRDFColorMapScaleText, m_CarPaint2_BRDFColorMapScale.floatValue);

                bool brdfColorUseDiagonalClamp = EditorGUILayout.Toggle("BRDF Color Table Diagonal Clamping", (flags & 16) != 0);
                if (brdfColorUseDiagonalClamp)
                {
                    ++EditorGUI.indentLevel;
                    m_CarPaint2_BRDFColorMapUVScale.vectorValue = EditorGUILayout.Vector2Field(Styles.BRDFColorMapUVScaleText, m_CarPaint2_BRDFColorMapUVScale.vectorValue);
                    --EditorGUI.indentLevel;
                }


                materialEditor.TexturePropertySingleLine(Styles.BTFFlakesMapText, m_CarPaint2_BTFFlakeMap);
                //EditorGUILayout.LabelField( "Texture Dimension = " + m_CarPaint_BTFFlakesMap_sRGB.textureDimension );
                //EditorGUILayout.LabelField( "Texture Format = " + m_CarPaint_BTFFlakesMap_sRGB.textureValue. );
                m_CarPaint2_BTFFlakeMapScale.floatValue = EditorGUILayout.FloatField(Styles.BTFFlakesMapScaleText, m_CarPaint2_BTFFlakeMapScale.floatValue);
                m_CarPaint2_FlakeTiling.floatValue      = EditorGUILayout.FloatField(Styles.FlakesTilingText, m_CarPaint2_FlakeTiling.floatValue);

                materialEditor.TexturePropertySingleLine(Styles.thetaFI_sliceLUTMapText, m_CarPaint2_FlakeThetaFISliceLUTMap);

                // m_CarPaint_maxThetaI = FindProperty( m_CarPaint_maxThetaIText, props );
                // m_CarPaint_numThetaF = FindProperty( m_CarPaint_numThetaFText, props );
                // m_CarPaint_numThetaI = FindProperty( m_CarPaint_numThetaIText, props );


                // Clearcoat
                bool hasClearcoat            = EditorGUILayout.Toggle("Enable Clearcoat", (flags & 2) != 0);
                bool clearcoatUsesRefraction = (flags & 4) != 0;
                if (hasClearcoat)
                {
                    ++EditorGUI.indentLevel;
//                        materialEditor.TexturePropertySingleLine( Styles.clearcoatColorMapText, m_ClearcoatColorMap );
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap);
//                        if ( clearcoatUsesRefraction ) {
                    {
                        ++EditorGUI.indentLevel;
//                            materialEditor.TexturePropertySingleLine( Styles.clearcoatIORMapText, m_ClearcoatIORMap );
                        m_CarPaint2_ClearcoatIOR.floatValue = EditorGUILayout.FloatField(Styles.CarPaintIORText, m_CarPaint2_ClearcoatIOR.floatValue);
                        --EditorGUI.indentLevel;
                    }
                    --EditorGUI.indentLevel;
                    clearcoatUsesRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatUsesRefraction);
                }

                // Write back as compact flags
                flags  = 0;
                flags |= isAnisotropic ? 1U : 0U;
                flags |= hasClearcoat ? 2U : 0U;
                flags |= clearcoatUsesRefraction ? 4U : 0U;
                flags |= useDisplacementMap ? 8U : 0U;
                flags |= brdfColorUseDiagonalClamp ? 16U : 0U;

//                    cmd.SetGlobalFloat( HDShaderIDs._TexturingModeFlags, *(float*) &texturingModeFlags );
                m_Flags.floatValue = (float)flags;

                --EditorGUI.indentLevel;
                break;
            }
            }
        }
Example #5
0
        // 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 SetupMaterialKeywordsAndPass(Material material)
        {
            SetupBaseUnlitKeywords(material);
            SetupBaseUnlitMaterialPass(material);

            AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(m_AxF_BRDFTypeText);

            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);

            // Keywords for opt-out of decals and SSR:
            bool decalsEnabled = material.HasProperty(kEnableDecals) && material.GetFloat(kEnableDecals) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_DECALS", decalsEnabled == false);
            bool ssrEnabled = material.HasProperty(kEnableSSR) && material.GetFloat(kEnableSSR) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_SSR", ssrEnabled == false);

            // Set the reference values for the stencil test

            // Stencil usage rules:
            // DoesntReceiveSSR and DecalsForwardOutputNormalBuffer need to be tagged during depth prepass
            // LightingMask need to be tagged during either GBuffer or Forward pass
            // ObjectVelocity need to be tagged in velocity pass.
            // As velocity pass can be use as a replacement of depth prepass it also need to have DoesntReceiveSSR and DecalsForwardOutputNormalBuffer
            // Object velocity is always render after a full depth buffer (if there is no depth prepass for GBuffer all object motion vectors are render after GBuffer)
            // so we have a guarantee than when we write object velocity no other object will be draw on top (and so would have require to overwrite velocity).
            // Final combination is:
            // Prepass: DoesntReceiveSSR,  DecalsForwardOutputNormalBuffer
            // Motion vectors: DoesntReceiveSSR,  DecalsForwardOutputNormalBuffer, ObjectVelocity
            // GBuffer: LightingMask, DecalsForwardOutputNormalBuffer, ObjectVelocity
            // Forward: LightingMask

            int stencilRef            = (int)StencilLightingUsage.RegularLighting;
            int stencilWriteMask      = (int)HDRenderPipeline.StencilBitMask.LightingMask;
            int stencilRefDepth       = 0;
            int stencilWriteMaskDepth = 0;
            int stencilRefMV          = (int)HDRenderPipeline.StencilBitMask.ObjectVelocity;
            int stencilWriteMaskMV    = (int)HDRenderPipeline.StencilBitMask.ObjectVelocity;

            if (!ssrEnabled)
            {
                stencilRefDepth |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR;
                stencilRefMV    |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR;
            }

            if (decalsEnabled)
            {
                stencilRefDepth |= (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer;
                stencilRefMV    |= (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer;
            }

            stencilWriteMaskDepth |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR | (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer;
            stencilWriteMaskMV    |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR | (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer;

            // As we tag both during velocity pass and Gbuffer pass we need a separate state and we need to use the write mask
            material.SetInt(kStencilRef, stencilRef);
            material.SetInt(kStencilWriteMask, stencilWriteMask);
            material.SetInt(kStencilRefDepth, stencilRefDepth);
            material.SetInt(kStencilWriteMaskDepth, stencilWriteMaskDepth);
            material.SetInt(kStencilRefMV, stencilRefMV);
            material.SetInt(kStencilWriteMaskMV, stencilWriteMaskMV);
        }
Example #6
0
        // 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 SetupMaterialKeywordsAndPass(Material _material)
        {
            SetupBaseUnlitKeywords(_material);
            SetupBaseUnlitMaterialPass(_material);

            AxfBrdfType BRDFType = (AxfBrdfType)_material.GetFloat(m_AxF_BRDFTypeText);

            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            CoreUtils.SetKeyword(_material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);

            // Keywords for opt-out of decals and SSR:
            bool decalsEnabled = _material.HasProperty(kEnableDecals) && _material.GetFloat(kEnableDecals) > 0.0f;

            CoreUtils.SetKeyword(_material, "_DISABLE_DECALS", decalsEnabled == false);
            bool ssrEnabled = _material.HasProperty(kEnableSSR) && _material.GetFloat(kEnableSSR) > 0.0f;

            CoreUtils.SetKeyword(_material, "_DISABLE_SSR", ssrEnabled == false);

            //
            // Set the reference values for the stencil test - required for SSS, decals, motion vectors
            // and TODOTODO disabling wasteful SSR tracing in compute shader
            //

            // We tag during velocity pass, forwardonly pass, and depth forwardonly prepass
            // so we need a separate state and we need to use the write mask:
            int stencilRef       = (int)StencilLightingUsage.RegularLighting;
            int stencilWriteMask = (int)HDRenderPipeline.StencilBitMask.LightingMask;
            //if (sssEnabled)
            //{
            //    stencilRef = (int)StencilLightingUsage.SplitLighting;
            //}

            // For depth only pass, we also tag: when the renderpipeline itself is set in deferred mode,
            // this is needed for decal to normal buffer compositing to still happen for forward only _materials (like stacklit).
            // When the renderpipeline is in full forward, it automatically do compositing for all pixels
            // tagged with the decal bit as they all need compositing since it knows every opaque was rendered in forward.
            int stencilDepthPrepassRef       = decalsEnabled ? (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer : 0;
            int stencilDepthPrepassWriteMask = decalsEnabled ? (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer : 0;

            // TODOTODO enable this and test, when RenderPipeline is modified to copy the stencil to UAV not
            // only on feature variants, but if we render any depth forward only prepasses and have SSR,
            // as in this case, it might be worth it to save SSR tracing for full forward materials that escape
            // it.
            // (If the pipeline is itself in fullforward, then depth only prepasses (eg in Lit) should also tag,
            // like we plan to do here:)
            //if (!ssrEnabled)
            //{
            //    stencilDepthPrepassRef |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR;
            //    stencilDepthPrepassWriteMask |= (int)HDRenderPipeline.StencilBitMask.DoesntReceiveSSR;
            //}

            // We tag during velocity pass, forwardonly pass, so we need a separate state and we need to use the write mask
            _material.SetInt(kStencilRef, stencilRef);
            _material.SetInt(kStencilWriteMask, stencilWriteMask);
            _material.SetInt(kStencilRefMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
            _material.SetInt(kStencilWriteMaskMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);

            _material.SetInt(kStencilDepthPrepassRef, stencilDepthPrepassRef);
            _material.SetInt(kStencilDepthPrepassWriteMask, stencilDepthPrepassWriteMask);
        }
Example #7
0
        void DrawAxfSurfaceOptionsGUI()
        {
            AxfBrdfType AxF_BRDFType = (AxfBrdfType)m_AxF_BRDFType.floatValue;

            AxF_BRDFType = (AxfBrdfType)EditorGUILayout.Popup("BRDF Type", (int)AxF_BRDFType, AxfBrdfTypeNames);
            m_AxF_BRDFType.floatValue = (float)AxF_BRDFType;

            // Extract flag:
            uint flags = (uint)m_Flags.floatValue;

            ExtractFlags(flags,
                         out bool anisotropy, out bool clearcoat, out bool clearcoatRefraction, out bool useHeightMap, out bool brdfColorDiagonalClamp,
                         out bool honorMinRoughness);

            switch (AxF_BRDFType)
            {
            case AxfBrdfType.SVBRDF:
            {
                EditorGUILayout.Space();
                ++EditorGUI.indentLevel;

                // Read as compact flags
                //uint    flags = (uint)m_Flags.floatValue;
                uint BRDFType     = (uint)m_SVBRDF_BRDFType.floatValue;
                uint BRDFVariants = (uint)m_SVBRDF_BRDFVariants.floatValue;

                SvbrdfDiffuseType          diffuseType    = (SvbrdfDiffuseType)(BRDFType & 0x1);
                SvbrdfSpecularType         specularType   = (SvbrdfSpecularType)((BRDFType >> 1) & 0x7);
                SvbrdfFresnelVariant       fresnelVariant = (SvbrdfFresnelVariant)(BRDFVariants & 0x3);
                SvbrdfSpecularVariantWard  wardVariant    = (SvbrdfSpecularVariantWard)((BRDFVariants >> 2) & 0x3);
                SvbrdfSpecularVariantBlinn blinnVariant   = (SvbrdfSpecularVariantBlinn)((BRDFVariants >> 4) & 0x3);

                // Expand as user-friendly UI
                EditorGUILayout.LabelField("BRDF Variants", EditorStyles.boldLabel);

                diffuseType  = (SvbrdfDiffuseType)EditorGUILayout.Popup("Diffuse Type", (int)diffuseType, SvbrdfDiffuseTypeNames);
                specularType = (SvbrdfSpecularType)EditorGUILayout.Popup("Specular Type", (int)specularType, SvbrdfSpecularTypeNames);

                if (specularType == SvbrdfSpecularType.WARD)
                {
                    fresnelVariant = (SvbrdfFresnelVariant)EditorGUILayout.Popup("Fresnel Variant", (int)fresnelVariant, SvbrdfFresnelVariantNames);
                    wardVariant    = (SvbrdfSpecularVariantWard)EditorGUILayout.Popup("Ward Variant", (int)wardVariant, SvbrdfSpecularVariantWardNames);
                }
                else if (specularType == SvbrdfSpecularType.BLINN_PHONG)
                {
                    blinnVariant = (SvbrdfSpecularVariantBlinn)EditorGUILayout.Popup("Blinn Variant", (int)blinnVariant, SvbrdfSpecularVariantBlinnNames);
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Parameters and Maps", EditorStyles.boldLabel);

                // Regular maps
                DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);

                materialEditor.TexturePropertySingleLine(Styles.diffuseColorMapText, m_DiffuseColorMap, m_DiffuseColorMapST);
                materialEditor.TexturePropertySingleLine(Styles.specularColorMapText, m_SpecularColorMap, m_SpecularColorMapST);
                materialEditor.TexturePropertySingleLine(Styles.specularLobeMapText, m_SpecularLobeMap, m_SpecularLobeMapST);
                m_SpecularLobeMapScale.floatValue = EditorGUILayout.FloatField(Styles.specularLobeMapScaleText, m_SpecularLobeMapScale.floatValue);

                EditorGUILayout.Space();
                DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);

                materialEditor.TexturePropertySingleLine(Styles.fresnelMapText, m_FresnelMap, m_FresnelMapST);
                materialEditor.TexturePropertySingleLine(Styles.normalMapText, m_NormalMap, m_NormalMapST);

                // Alpha
                materialEditor.TexturePropertySingleLine(Styles.alphaMapText, m_AlphaMap, m_AlphaMapST);

                // Displacement
                //TODO: unsupported for now
                //useHeightMap = EditorGUILayout.Toggle("Enable Displacement Map", useHeightMap);
                useHeightMap = false;
                if (useHeightMap)
                {
                    ++EditorGUI.indentLevel;
                    DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);
                    materialEditor.TexturePropertySingleLine(Styles.heightMapText, m_HeightMap, m_HeightMapST);
                    materialEditor.ShaderProperty(m_SVBRDF_HeightMapMaxMM, "Max Displacement (mm)");
                    --EditorGUI.indentLevel;
                }

                // Anisotropy
                anisotropy = EditorGUILayout.Toggle("Is Anisotropic", anisotropy);
                if (anisotropy)
                {
                    ++EditorGUI.indentLevel;
                    DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);
                    materialEditor.TexturePropertySingleLine(Styles.anisoRotationMapText, m_AnisoRotationMap, m_AnisoRotationMapST);
                    --EditorGUI.indentLevel;
                }

                // Clearcoat
                clearcoat = EditorGUILayout.Toggle("Enable Clearcoat", clearcoat);
                if (clearcoat)
                {
                    ++EditorGUI.indentLevel;
                    DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatColorMapText, m_ClearcoatColorMap, m_ClearcoatColorMapST);
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap, m_ClearcoatNormalMapST);
                    clearcoatRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatRefraction);
                    // The IOR map is always required for the coat F0, while in the CAR_PAINT model, the IOR
                    // is given by a scalar value.
                    DrawRightJustifiedHeader(Styles.mapsTilingOffsetText.text);
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatIORMapText, m_ClearcoatIORMap, m_ClearcoatIORMapST);
                    --EditorGUI.indentLevel;
                }

                BRDFType  = 0;
                BRDFType |= (uint)diffuseType;
                BRDFType |= ((uint)specularType) << 1;

                BRDFVariants  = 0;
                BRDFVariants |= (uint)fresnelVariant;
                BRDFVariants |= ((uint)wardVariant) << 2;
                BRDFVariants |= ((uint)blinnVariant) << 4;

                m_SVBRDF_BRDFType.floatValue     = (float)BRDFType;
                m_SVBRDF_BRDFVariants.floatValue = (float)BRDFVariants;
                --EditorGUI.indentLevel;
                break;
            }

            case AxfBrdfType.CAR_PAINT:
            {
                EditorGUILayout.Space();
                ++EditorGUI.indentLevel;

                // Expand as user-friendly UI

                // Regular maps
                materialEditor.TexturePropertySingleLine(Styles.BRDFColorMapText, m_CarPaint2_BRDFColorMap);
                m_CarPaint2_BRDFColorMapScale.floatValue = EditorGUILayout.FloatField(Styles.BRDFColorMapScaleText, m_CarPaint2_BRDFColorMapScale.floatValue);

                brdfColorDiagonalClamp = EditorGUILayout.Toggle("BRDF Color Table Diagonal Clamping", brdfColorDiagonalClamp);
                if (brdfColorDiagonalClamp)
                {
                    ++EditorGUI.indentLevel;
                    m_CarPaint2_BRDFColorMapUVScale.vectorValue = EditorGUILayout.Vector2Field(Styles.BRDFColorMapUVScaleText, m_CarPaint2_BRDFColorMapUVScale.vectorValue);
                    --EditorGUI.indentLevel;
                }

                DrawRightJustifiedHeader(Styles.BTFFlakesTilingText.text);
                materialEditor.TexturePropertySingleLine(Styles.BTFFlakesMapText, m_CarPaint2_BTFFlakeMap, m_CarPaint2_BTFFlakeMapST);
                //materialEditor.TexturePropertySingleLine(Styles.BTFFlakesMapText, m_CarPaint2_BTFFlakeMap);
                //m_CarPaint2_BTFFlakeMapST.vectorValue = EditorGUILayout.Vector4Field(Styles.BTFFlakesTilingText, m_CarPaint2_BTFFlakeMapST.vectorValue);

                //EditorGUILayout.LabelField( "Texture Dimension = " + m_CarPaint_BTFFlakesMap_sRGB.textureDimension );
                //EditorGUILayout.LabelField( "Texture Format = " + m_CarPaint_BTFFlakesMap_sRGB.textureValue. );
                m_CarPaint2_BTFFlakeMapScale.floatValue = EditorGUILayout.FloatField(Styles.BTFFlakesMapScaleText, m_CarPaint2_BTFFlakeMapScale.floatValue);

                materialEditor.TexturePropertySingleLine(Styles.thetaFI_sliceLUTMapText, m_CarPaint2_FlakeThetaFISliceLUTMap);

                materialEditor.ShaderProperty(m_CarPaint2_FixedColorThetaHForIndirectLight, Styles.CarPaintFixedColorThetaHForIndirectLightText);
                materialEditor.ShaderProperty(m_CarPaint2_FixedFlakesThetaHForIndirectLight, Styles.CarPaintFixedFlakesThetaHForIndirectLightText);

                //m_CarPaint2_FlakeMaxThetaI = FindProperty(m_CarPaint2_FlakeMaxThetaIText);
                //m_CarPaint2_FlakeNumThetaF = FindProperty(m_CarPaint2_FlakeNumThetaFText);
                //m_CarPaint2_FlakeNumThetaI = FindProperty(m_CarPaint2_FlakeNumThetaIText);

                m_CarPaint2_CTDiffuse.floatValue  = EditorGUILayout.FloatField(Styles.CarPaintCTDiffuseText, m_CarPaint2_CTDiffuse.floatValue);
                m_CarPaint2_LobeCount.floatValue  = Mathf.Floor(Mathf.Clamp(EditorGUILayout.FloatField(Styles.CarPaintLobeCountText, m_CarPaint2_LobeCount.floatValue), 0f, 3f));
                m_CarPaint2_CTF0s.vectorValue     = EditorGUILayout.Vector3Field(Styles.CarPaintCTF0sText, m_CarPaint2_CTF0s.vectorValue);
                m_CarPaint2_CTCoeffs.vectorValue  = EditorGUILayout.Vector3Field(Styles.CarPaintCTCoeffsText, m_CarPaint2_CTCoeffs.vectorValue);
                m_CarPaint2_CTSpreads.vectorValue = EditorGUILayout.Vector3Field(Styles.CarPaintCTSpreadsText, m_CarPaint2_CTSpreads.vectorValue);

                if (useHeightMap)
                {
                    materialEditor.ShaderProperty(m_SVBRDF_HeightMapMaxMM, "Max Displacement (mm)");
                }

                // Clearcoat
                clearcoat = EditorGUILayout.Toggle("Enable Clearcoat", clearcoat);
                if (clearcoat)
                {
                    ++EditorGUI.indentLevel;
                    //materialEditor.TexturePropertySingleLine( Styles.clearcoatColorMapText, m_ClearcoatColorMap );

                    DrawRightJustifiedHeader(Styles.clearcoatNormalMapTilingText.text);
                    materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap, m_ClearcoatNormalMapST);
                    //materialEditor.TexturePropertySingleLine(Styles.clearcoatNormalMapText, m_ClearcoatNormalMap);
                    //m_ClearcoatNormalMapST.vectorValue = EditorGUILayout.Vector4Field(Styles.clearcoatNormalMapTilingText, m_ClearcoatNormalMapST.vectorValue);

                    //materialEditor.TexturePropertySingleLine( Styles.clearcoatIORMapText, m_ClearcoatIORMap );
                    m_CarPaint2_ClearcoatIOR.floatValue = EditorGUILayout.FloatField(Styles.CarPaintIORText, m_CarPaint2_ClearcoatIOR.floatValue);
                    --EditorGUI.indentLevel;
                    clearcoatRefraction = EditorGUILayout.Toggle("Enable Refraction", clearcoatRefraction);
                }

                --EditorGUI.indentLevel;
                break;
            }
            }

            // Finally write back flags:
            flags = GenFlags(anisotropy, clearcoat, clearcoatRefraction, useHeightMap, brdfColorDiagonalClamp,
                             honorMinRoughness);
            m_Flags.floatValue = (float)flags;
        }//DrawAxfSurfaceOptionsGUI
Example #8
0
        // 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 SetupAxFKeywordsAndPass(Material material)
        {
            material.SetupBaseUnlitKeywords();
            material.SetupBaseUnlitPass();

            AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(kAxF_BRDFType);

            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
            CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
            //unsupported for now: CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);


            // Mapping Modes:
            AxFMappingMode mappingMode = (AxFMappingMode)material.GetFloat(kMappingMode);

            // Make sure the mask is synched:
            material.SetVector(kMappingMask, AxFMappingModeToMask(mappingMode));

            bool mappingIsPlanar = (mappingMode >= AxFMappingMode.PlanarXY) && (mappingMode < AxFMappingMode.Triplanar);
            bool planarIsLocal   = (material.GetFloat(kPlanarSpace) > 0.0f);

            CoreUtils.SetKeyword(material, "_MAPPING_PLANAR", mappingIsPlanar);
            CoreUtils.SetKeyword(material, "_MAPPING_TRIPLANAR", mappingMode == AxFMappingMode.Triplanar);

            if (mappingIsPlanar || mappingMode == AxFMappingMode.Triplanar)
            {
                CoreUtils.SetKeyword(material, "_PLANAR_LOCAL", planarIsLocal);
            }

            // Note: for ShaderPass defines for vertmesh/varyingmesh setup, we still use the same
            // defines _REQUIRE_UV2 and _REQUIRE_UV3, and thus if eg _REQUIRE_UV3 is defined, _REQUIRE_UV2 will
            // be assumed to be needed. But here in the AxFData sampling code, we use these to indicate precisely
            // the single set used (if not using planar/triplanar) only and thus add _REQUIRE_UV1.
            // Extra UVs might be transfered but we only need and support a single set at a time for the whole material.
            CoreUtils.SetKeyword(material, "_REQUIRE_UV1", mappingMode == AxFMappingMode.UV1);
            CoreUtils.SetKeyword(material, "_REQUIRE_UV2", mappingMode == AxFMappingMode.UV2);
            CoreUtils.SetKeyword(material, "_REQUIRE_UV3", mappingMode == AxFMappingMode.UV3);

            // Keywords for opt-out of decals and SSR:
            bool decalsEnabled = material.HasProperty(kEnableDecals) && material.GetFloat(kEnableDecals) > 0.0f;

            CoreUtils.SetKeyword(material, "_DISABLE_DECALS", !decalsEnabled);

            bool ssrEnabled = false;

            if (material.GetSurfaceType() == SurfaceType.Transparent)
            {
                ssrEnabled = material.HasProperty(kReceivesSSRTransparent) ? material.GetFloat(kReceivesSSRTransparent) != 0 : false;
            }
            else
            {
                ssrEnabled = material.HasProperty(kReceivesSSR) ? material.GetFloat(kReceivesSSR) != 0 : false;
            }
            CoreUtils.SetKeyword(material, "_DISABLE_SSR", material.HasProperty(kReceivesSSR) && material.GetFloat(kReceivesSSR) == 0.0f);
            CoreUtils.SetKeyword(material, "_DISABLE_SSR_TRANSPARENT", material.HasProperty(kReceivesSSRTransparent) && material.GetFloat(kReceivesSSRTransparent) == 0.0);
            CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.HasProperty(kEnableGeometricSpecularAA) && material.GetFloat(kEnableGeometricSpecularAA) > 0.0f);
            CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", material.HasProperty(kSpecularOcclusionMode) && material.GetFloat(kSpecularOcclusionMode) == 0.0f);

            BaseLitGUI.SetupStencil(material, receivesSSR: ssrEnabled, useSplitLighting: false);

            if (material.HasProperty(kAddPrecomputedVelocity))
            {
                CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
            }
            //
            // Patch for raytracing for now: mirror int props as float explicitly
            //
            uint flags = (uint)material.GetFloat(kFlags);

            flags |= (uint)AxF.FeatureFlags.AxfDebugTest; // force bit 23 = 1
            material.SetFloat(kFlagsB, flags);

            uint SVBRDFType     = (uint)material.GetFloat(kSVBRDF_BRDFType);
            uint SVBRDFVariants = (uint)material.GetFloat(kSVBRDF_BRDFVariants);

            SvbrdfDiffuseType          diffuseType    = (SvbrdfDiffuseType)(SVBRDFType & 0x1);
            SvbrdfSpecularType         specularType   = (SvbrdfSpecularType)((SVBRDFType >> 1) & 0x7);
            SvbrdfFresnelVariant       fresnelVariant = (SvbrdfFresnelVariant)(SVBRDFVariants & 0x3);
            SvbrdfSpecularVariantWard  wardVariant    = (SvbrdfSpecularVariantWard)((SVBRDFVariants >> 2) & 0x3);
            SvbrdfSpecularVariantBlinn blinnVariant   = (SvbrdfSpecularVariantBlinn)((SVBRDFVariants >> 4) & 0x3);

            material.SetFloat(kSVBRDF_BRDFType_DiffuseType, (float)diffuseType);
            material.SetFloat(kSVBRDF_BRDFType_SpecularType, (float)specularType);
            material.SetFloat(kSVBRDF_BRDFVariants_FresnelType, (float)fresnelVariant);
            material.SetFloat(kSVBRDF_BRDFVariants_WardType, (float)wardVariant);
            material.SetFloat(kSVBRDF_BRDFVariants_BlinnType, (float)blinnVariant);

            material.SetFloat(kCarPaint2_FlakeMaxThetaI + kIntPropAsFloatSuffix, material.GetFloat(kCarPaint2_FlakeMaxThetaI));
            material.SetFloat(kCarPaint2_FlakeNumThetaF + kIntPropAsFloatSuffix, material.GetFloat(kCarPaint2_FlakeNumThetaF));
            material.SetFloat(kCarPaint2_FlakeNumThetaI + kIntPropAsFloatSuffix, material.GetFloat(kCarPaint2_FlakeNumThetaI));
        }