コード例 #1
0
        // ---------------- shadow map ----------------------------------------------------------------------------------------------------------------------
        public unsafe static void EncodeShadowMap(RendererBGFXSystem sys, bgfx.Encoder *encoder, ushort viewId, ref SimpleMeshBGFX mesh, ref float4x4 tx, int startIndex, int indexCount, byte flipCulling, float4 bias)
        {
            ulong state = (ulong)(bgfx.StateFlags.WriteZ | bgfx.StateFlags.DepthTestLess | bgfx.StateFlags.CullCcw);

            if (flipCulling != 0)
            {
                state = FlipCulling(state);
            }
            bgfx.encoder_set_state(encoder, state, 0);
            unsafe { fixed(float4x4 *p = &tx) bgfx.encoder_set_transform(encoder, p, 1); }
            bgfx.encoder_set_index_buffer(encoder, mesh.indexBufferHandle, (uint)startIndex, (uint)indexCount);
            bgfx.encoder_set_vertex_buffer(encoder, 0, mesh.vertexBufferHandle, (uint)mesh.vertexFirst, (uint)mesh.vertexCount, mesh.vertexDeclHandle);
            bgfx.encoder_set_uniform(encoder, sys.ShadowMapShader.m_uniformBias, &bias, 1);
            bgfx.encoder_submit(encoder, viewId, sys.ShadowMapShader.m_prog, 0, false);
        }
コード例 #2
0
        public static unsafe void EncodeSimple(RendererBGFXSystem sys, bgfx.Encoder *encoder, ushort viewId, ref SimpleMeshBGFX mesh, ref float4x4 tx, ref SimpleMaterialBGFX mat, int startIndex, int indexCount, byte flipCulling)
        {
            bgfx.set_state(mat.state, 0);

            fixed(float4x4 *p = &tx)
            bgfx.encoder_set_transform(encoder, p, 1);

            bgfx.encoder_set_index_buffer(encoder, mesh.indexBufferHandle, (uint)startIndex, (uint)indexCount);
            bgfx.encoder_set_vertex_buffer(encoder, 0, mesh.vertexBufferHandle, (uint)mesh.vertexFirst, (uint)mesh.vertexCount, mesh.vertexDeclHandle);

            // material uniforms setup
            fixed(float4 *p = &mat.constAlbedo_Opacity)
            bgfx.encoder_set_uniform(encoder, sys.SimpleShader.m_uniformColor0, p, 1);

            fixed(float4 *p = &mat.mainTextureScaleTranslate)
            bgfx.encoder_set_uniform(encoder, sys.SimpleShader.m_uniformTexMad, p, 1);

            bgfx.encoder_set_texture(encoder, 0, sys.SimpleShader.m_samplerTexColor0, mat.texAlbedo, UInt32.MaxValue);
            bgfx.encoder_submit(encoder, viewId, sys.SimpleShader.m_prog, 0, false);
        }
コード例 #3
0
        public unsafe static void EncodeLit(RendererBGFXSystem sys, bgfx.Encoder *encoder, ushort viewId, ref SimpleMeshBGFX mesh, ref float4x4 tx,
                                            ref LitMaterialBGFX mat, ref LightingBGFX lighting,
                                            ref float4x4 viewTx, int startIndex, int indexCount, byte flipCulling, ref LightingViewSpaceBGFX viewSpaceLightCache)
        {
            ulong state = mat.state;

            if (flipCulling != 0)
            {
                state = FlipCulling(state);
            }
            bgfx.encoder_set_state(encoder, state, 0);

            fixed(float4x4 *p = &tx)
            bgfx.encoder_set_transform(encoder, p, 1);

            float3x3 minvt = math.transpose(math.inverse(new float3x3(tx.c0.xyz, tx.c1.xyz, tx.c2.xyz)));

            //float3x3 minvt = new float3x3(tx.c0.xyz, tx.c1.xyz, tx.c2.xyz);
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformModelInverseTranspose, &minvt, 1);

            bgfx.encoder_set_index_buffer(encoder, mesh.indexBufferHandle, (uint)startIndex, (uint)indexCount);
            bgfx.encoder_set_vertex_buffer(encoder, 0, mesh.vertexBufferHandle, (uint)mesh.vertexFirst, (uint)mesh.vertexCount, mesh.vertexDeclHandle);

            // material uniforms setup
            fixed(float4 *p = &mat.constAlbedo_Opacity)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformAlbedoOpacity, p, 1);

            fixed(float4 *p = &mat.constMetal_Smoothness)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformMetalSmoothness, p, 1);

            fixed(float4 *p = &mat.constEmissive_normalMapZScale)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformEmissiveNormalZScale, p, 1);

            float4 debugVect = sys.OutputDebugSelect;

            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformOutputDebugSelect, &debugVect, 1);
            // textures
            bgfx.encoder_set_texture(encoder, 0, sys.m_litShader.m_samplerAlbedo, mat.texAlbedo, UInt32.MaxValue);
            bgfx.encoder_set_texture(encoder, 1, sys.m_litShader.m_samplerMetal, mat.texMetal, UInt32.MaxValue);
            bgfx.encoder_set_texture(encoder, 2, sys.m_litShader.m_samplerNormal, mat.texNormal, UInt32.MaxValue);
            bgfx.encoder_set_texture(encoder, 3, sys.m_litShader.m_samplerSmoothness, mat.texSmoothness, UInt32.MaxValue);
            bgfx.encoder_set_texture(encoder, 4, sys.m_litShader.m_samplerEmissive, mat.texEmissive, UInt32.MaxValue);
            bgfx.encoder_set_texture(encoder, 5, sys.m_litShader.m_samplerOpacity, mat.texOpacity, UInt32.MaxValue);

            fixed(float4 *p = &mat.mainTextureScaleTranslate)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformTexMad, p, 1);

            // ambient
            fixed(float4 *p = &lighting.ambient)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_uniformAmbient, p, 1);

            // transform lighting to view space, if needed: this only needs to re-compute if the viewId changed
            // also the lighting view space is per-thread, hence it is passed in
            lighting.TransformToViewSpace(ref viewTx, ref viewSpaceLightCache, viewId);

            // dir or point lights
            fixed(float *p = viewSpaceLightCache.podl_positionOrDirViewSpace)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_simplelightPosOrDir, p, (ushort)lighting.numPointOrDirLights);

            fixed(float *p = lighting.podl_colorIVR)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_simplelightColorIVR, p, (ushort)lighting.numPointOrDirLights);

            // mapped lights (always have to set those or there are undefined samplers)
            EncodeMappedLight(encoder, ref lighting.mappedLight0, ref sys.m_litShader.m_mappedLight0, 0, viewSpaceLightCache.mappedLight0_viewPosOrDir);
            EncodeMappedLight(encoder, ref lighting.mappedLight1, ref sys.m_litShader.m_mappedLight1, 1, viewSpaceLightCache.mappedLight1_viewPosOrDir);

            fixed(float4 *p = &lighting.mappedLight01sis)
            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_texShadow01sis, p, 1);

            float4 numlights = new float4(lighting.numPointOrDirLights, lighting.numMappedLights, 0.0f, 0.0f);

            bgfx.encoder_set_uniform(encoder, sys.m_litShader.m_numLights, &numlights, 1);

            // submit
            bgfx.encoder_submit(encoder, viewId, sys.m_litShader.m_prog, 0, false);
        }
コード例 #4
0
 // ---------------- simple, unlit, with mesh ----------------------------------------------------------------------------------------------------------------------
 public static unsafe void SubmitSimpleDirect(RendererBGFXSystem sys, ushort viewId, ref SimpleMeshBGFX mesh, ref float4x4 tx, ref SimpleMaterialBGFX mat, int startIndex, int indexCount, byte flipCulling)
 {
     bgfx.Encoder *encoder = bgfx.encoder_begin(false);
     EncodeSimple(sys, encoder, viewId, ref mesh, ref tx, ref mat, startIndex, indexCount, flipCulling);
     bgfx.encoder_end(encoder);
 }
コード例 #5
0
        // ---------------- simple, lit, with mesh ----------------------------------------------------------------------------------------------------------------------
        public unsafe static void SubmitLitDirect(RendererBGFXSystem sys, ushort viewId, ref SimpleMeshBGFX mesh, ref float4x4 tx,
                                                  ref LitMaterialBGFX mat, ref LightingBGFX lighting,
                                                  ref float4x4 viewTx, int startIndex, int indexCount, byte flipCulling)
        {
            bgfx.Encoder *        encoder = bgfx.encoder_begin(false);
            LightingViewSpaceBGFX vsLight = default;

            vsLight.cacheTag = -1;
            EncodeLit(sys, encoder, viewId, ref mesh, ref tx, ref mat, ref lighting, ref viewTx, startIndex, indexCount, flipCulling, ref vsLight);
            bgfx.encoder_end(encoder);
        }