private void UpdateLight(RenderView view)
        {
            uint offset  = 0;
            uint offset1 = 0;

            num_lights = 0;
            foreach (var light in view.lights)
            {
                if (light.LightType != LightType.Point)
                {
                    continue;
                }

                vec4 pos = new vec4(light.Node.WorldPosition, light.Range);
                light_pos_ranges.SetData(ref pos, offset);
                int color = light.EffectiveColor.ToRgba();
                light_colors.SetData(ref color, offset1);
                offset  += 16;
                offset1 += 4;
                num_lights++;
            }

            light_pos_ranges.Flush();
            light_colors.Flush();
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            RenderView view = View;

            UpdateLight(view);

            tile_count_x = ((uint)view.Width - 1) / TILE_WIDTH + 1;
            tile_count_y = ((uint)view.Height - 1) / TILE_HEIGHT + 1;

            Camera camera = view.Camera;

            clusterUniforms.view = camera.View;

            mat4 clip = new mat4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f);

            //clusterUniforms.projection_clip = clip*camera.Projection;
            clusterUniforms.projection_clip = camera.VkProjection;
            clusterUniforms.inv_view_proj   = glm.inverse(camera.VkProjection * camera.View);
            clusterUniforms.tile_size[0]    = (float)(TILE_WIDTH);
            clusterUniforms.tile_size[1]    = (float)(TILE_HEIGHT);
            clusterUniforms.grid_dim[0]     = tile_count_x;
            clusterUniforms.grid_dim[1]     = tile_count_y;

            clusterUniforms.cam_pos     = camera.Node.WorldPosition;
            clusterUniforms.cam_near    = camera.NearClip;
            clusterUniforms.cam_forward = camera.Node.WorldDirection;
            clusterUniforms.cam_far     = camera.FarClip;


            clusterUniforms.resolution[0] = (float)(view.Width);
            clusterUniforms.resolution[1] = (float)(view.Height);
            clusterUniforms.num_lights    = num_lights;

            uboCluster.SetData(ref clusterUniforms);
            uboCluster.Flush();
        }