示例#1
0
        public unsafe bool UpdateLitMaterialBGFX(RendererBGFXInstance *sys, ref LitMaterial mat, ref LitMaterialBGFX matBGFX, bool srgbColors)
        {
            bool stillLoading = false;

            if (InitTexture(ref matBGFX.texAlbedoOpacity, mat.texAlbedoOpacity, sys->m_whiteTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texNormal, mat.texNormal, sys->m_upTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texMetal, mat.texMetal, sys->m_whiteTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texEmissive, mat.texEmissive, sys->m_whiteTexture))
            {
                stillLoading = true;
            }

            InitShader(ref matBGFX.shaderProgram, mat.shader, sys->m_litShader.m_prog);

            matBGFX.constAlbedo_Opacity = srgbColors ?
                                          new float4(Color.LinearToSRGB(mat.constAlbedo), mat.constOpacity) :
                                          new float4(mat.constAlbedo, mat.constOpacity);
            matBGFX.constMetal_Smoothness_Billboarded = new float4(mat.constMetal, mat.constSmoothness, mat.billboarded ? 1 : 0, 0);
            matBGFX.constEmissive_normalMapZScale     = srgbColors ?
                                                        new float4(Color.LinearToSRGB(mat.constEmissive), mat.normalMapZScale) :
                                                        new float4(mat.constEmissive, mat.normalMapZScale);
            matBGFX.mainTextureScaleTranslate = new float4(mat.scale, mat.offset);
            matBGFX.smoothness   = new float4(0.0f);
            matBGFX.smoothness.x = (!mat.transparent && mat.smoothnessAlbedoAlpha) ? 1 : 0;
            matBGFX.smoothness.y = (!mat.transparent && !mat.smoothnessAlbedoAlpha) ? 1 : 0;
            matBGFX.smoothness.z = !mat.transparent ? 1 : 0;

            // if twoSided, need to update state
            matBGFX.state = (ulong)(bgfx.StateFlags.WriteRgb | bgfx.StateFlags.WriteA | bgfx.StateFlags.DepthTestLess);
            if (!mat.twoSided && !mat.billboarded)
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.CullCcw;
            }
            if (mat.transparent)
            {
                matBGFX.state |= RendererBGFXStatic.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha);
            }
            else
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.WriteZ;
            }
            return(!stillLoading);
        }
示例#2
0
        public bool UpdateLitMaterialBGFX(RendererBGFXSystem sys, ref LitMaterial mat, ref LitMaterialBGFX matBGFX)
        {
            bool stillLoading = false;

            if (InitTexture(ref matBGFX.texAlbedo, mat.texAlbedo, sys.WhiteTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texOpacity, mat.texOpacity, sys.WhiteTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texNormal, mat.texNormal, sys.UpTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texMetal, mat.texMetal, sys.BlackTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texEmissive, mat.texEmissive, sys.BlackTexture))
            {
                stillLoading = true;
            }
            if (InitTexture(ref matBGFX.texSmoothness, mat.texSmoothness, sys.GreyTexture))
            {
                stillLoading = true;
            }

            matBGFX.constAlbedo_Opacity           = new float4(mat.constAlbedo, mat.constOpacity);
            matBGFX.constMetal_Smoothness         = new float4(mat.constMetal, mat.constSmoothness, 0, 0);
            matBGFX.constEmissive_normalMapZScale = new float4(mat.constEmissive, mat.normalMapZScale);
            matBGFX.mainTextureScaleTranslate     = new float4(mat.scale, mat.offset);

            // if twoSided, need to update state
            matBGFX.state = (ulong)(bgfx.StateFlags.WriteRgb | bgfx.StateFlags.WriteA | bgfx.StateFlags.DepthTestLess);
            if (!mat.twoSided)
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.CullCcw;
            }
            if (mat.transparent)
            {
                matBGFX.state |= RendererBGFXSystem.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha);
            }
            else
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.WriteZ;
            }
            return(!stillLoading);
        }