private void AddCascadeMappedLight(ref LightingBGFX r, ref ShadowmappedLight sml, ref Light l, ref float4x4 tx, ref LightMatrices txCache,
                                           ref CascadeShadowmappedLight csm, ref CascadeShadowmappedLightCache csmData, RendererBGFXInstance *sys, bool srgbColors)
        {
            if (r.numCsmLights >= LightingBGFX.maxCsmLights)
            {
                throw new InvalidOperationException("Too many cascade mapped lights");
            }
            bgfx.TextureHandle texShadowMap = sys->m_noShadow;
            int shadowMapSize = 1;

            if (sml.shadowMap != Entity.Null && EntityManager.HasComponent <TextureBGFX>(sml.shadowMap))
            {
                var imShadowMap = EntityManager.GetComponentData <Image2D>(sml.shadowMap);
                Assert.IsTrue(imShadowMap.imagePixelWidth == imShadowMap.imagePixelHeight);
                shadowMapSize = imShadowMap.imagePixelHeight;
                texShadowMap  = EntityManager.GetComponentData <TextureBGFX>(sml.shadowMap).handle;
            }
            float4 worldPosOrDir = new float4(math.normalize(-tx.c2.xyz), 0.0f);
            float4 mask          = new float4(0);
            float3 c             = srgbColors?Color.LinearToSRGB(l.color):l.color;

            r.SetMappedLight(LightingBGFX.maxMappedLights + r.numCsmLights, txCache.mvp, c * l.intensity, worldPosOrDir, l.clipZFar, mask, texShadowMap, shadowMapSize);
            unsafe {
                r.csmOffsetScale[0]  = csmData.c0.offset.x; r.csmOffsetScale[1] = csmData.c0.offset.y; r.csmOffsetScale[2] = 0; r.csmOffsetScale[3] = csmData.c0.scale;
                r.csmOffsetScale[4]  = csmData.c1.offset.x; r.csmOffsetScale[5] = csmData.c1.offset.y; r.csmOffsetScale[6] = 0; r.csmOffsetScale[7] = csmData.c1.scale;
                r.csmOffsetScale[8]  = csmData.c2.offset.x; r.csmOffsetScale[9] = csmData.c2.offset.y; r.csmOffsetScale[10] = 0; r.csmOffsetScale[11] = csmData.c2.scale;
                r.csmOffsetScale[12] = csmData.c3.offset.x; r.csmOffsetScale[13] = csmData.c3.offset.y; r.csmOffsetScale[14] = 0; r.csmOffsetScale[15] = csmData.c3.scale;
            }
            // r.csmLightsis set in SetMappedLight
            r.numCsmLights++;
        }
        private void AddMappedLight(ref LightingBGFX r, ref ShadowmappedLight sml, ref Light l, ref float4x4 tx, ref LightMatrices txCache, RendererBGFXInstance *sys, bool isSpot, float4 spotmask, bool srgbColors)
        {
            if (r.numMappedLights >= LightingBGFX.maxMappedLights)
            {
                throw new InvalidOperationException("Too many mapped lights");
            }
            bgfx.TextureHandle texShadowMap = sys->m_noShadow;
            int shadowMapSize = 1;

            if (sml.shadowMap != Entity.Null && EntityManager.HasComponent <TextureBGFX>(sml.shadowMap))
            {
                var imShadowMap = EntityManager.GetComponentData <Image2D>(sml.shadowMap);
                Assert.IsTrue(imShadowMap.imagePixelWidth == imShadowMap.imagePixelHeight);
                shadowMapSize = imShadowMap.imagePixelHeight;
                texShadowMap  = EntityManager.GetComponentData <TextureBGFX>(sml.shadowMap).handle;
            }
            float4 mask          = isSpot ? spotmask : new float4(0.0f, 0.0f, 0.0f, 1.0f);
            float4 worldPosOrDir = isSpot? new float4(tx.c3.xyz, 1.0f) : new float4(-tx.c2.xyz, 0.0f);
            float3 c             = srgbColors?Color.LinearToSRGB(l.color):l.color;

            r.SetMappedLight(r.numMappedLights, txCache.mvp, c * l.intensity, worldPosOrDir, l.clipZFar, mask, texShadowMap, shadowMapSize);
            r.numMappedLights++;
        }
Beispiel #3
0
 private void AddMappedLight(ref LightingBGFX r, ref ShadowmappedLight sml, ref Light l, ref float4x4 tx, ref LightMatrices txCache, RendererBGFXSystem sys, bool isSpot)
 {
     if (r.numMappedLights >= LightingBGFX.maxMappedLights)
         throw new InvalidOperationException("Too many mapped lights"); }