Example #1
0
        public bool UpdateSimpleMaterialBGFX(RendererBGFXSystem sys, ref SimpleMaterial mat, ref SimpleMaterialBGFX matBGFX)
        {
            // if constants changed, need to update packed value
            matBGFX.constAlbedo_Opacity = new float4(mat.constAlbedo, mat.constOpacity);
            // if texture entity OR load state changed need to update texture handles
            // content of texture change should transparently update texture referenced by handle
            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 twoSided or hasalpha changed, need to update state
            matBGFX.state = (ulong)(bgfx.StateFlags.WriteRgb | bgfx.StateFlags.WriteA | bgfx.StateFlags.DepthTestLess);
            if (!mat.twoSided)
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.CullCw;
            }
            if (mat.transparent)
            {
                matBGFX.state |= RendererBGFXSystem.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha);
            }
            else
            {
                matBGFX.state |= (ulong)bgfx.StateFlags.WriteZ;
            }
            matBGFX.mainTextureScaleTranslate = new float4(mat.scale, mat.offset);
            return(!stillLoading);
        }
Example #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);
        }
Example #3
0
        public static unsafe void EncodeLinePreTransformed(RendererBGFXSystem sys, bgfx.Encoder *encoder, ushort viewId, SimpleVertex *vertices, int n)
        {
            bgfx.TransientIndexBuffer  tib;
            bgfx.TransientVertexBuffer tvb;
            int ni = (n / 4) * 6;

            fixed(bgfx.VertexLayout *declp = sys.SimpleVertexBufferDecl)
            {
                if (!bgfx.alloc_transient_buffers(&tvb, declp, (uint)n, &tib, (uint)ni))
                {
                    throw new InvalidOperationException("Out of transient bgfx memory!");
                }
            }

            UnsafeUtility.MemCpy((SimpleVertex *)tvb.data, vertices, sizeof(SimpleVertex) * n);
            ushort *indices = (ushort *)tib.data;

            for (int i = 0; i < n; i += 4)
            {
                indices[0] = (ushort)i; indices[1] = (ushort)(i + 1); indices[2] = (ushort)(i + 2);
                indices[3] = (ushort)(i + 2); indices[4] = (ushort)(i + 3); indices[5] = (ushort)i;
                indices   += 6;
            }
            bgfx.encoder_set_transient_index_buffer(encoder, &tib, 0, (uint)ni);
            bgfx.encoder_set_transient_vertex_buffer(encoder, 0, &tvb, 0, (uint)n, sys.SimpleVertexBufferDeclHandle);

            // material uniforms setup
            ulong state = (ulong)(bgfx.StateFlags.DepthTestLess | bgfx.StateFlags.WriteRgb) | RendererBGFXSystem.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha);

            bgfx.encoder_set_state(encoder, state, 0);
            bgfx.encoder_submit(encoder, viewId, sys.LineShader.m_prog, 0, false);
        }