protected void DrawOcclusionBox(ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            colorShader.UseShader();
            AAnimator.BindIdentity(1);

            GL.DepthMask(false);
            GL.Disable(EnableCap.CullFace);
            foreach (var sh in sm)
            {
                foreach (var mat in sh.Value)
                {
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible)
                        {
                            continue;
                        }

                        sp.world = sub.WorldTransform;
                        colorShader.SetUniqueParameter(sp, false);

                        GL.BeginQuery(QueryTarget.SamplesPassed, sub.OcclusionQuery);
                        //Drawer.DrawSubMesh(sub.SubMesh.boundsMesh.subMeshes[0]);
                        GL.EndQuery(QueryTarget.SamplesPassed);
                    }
                }
            }
            GL.Enable(EnableCap.CullFace);
            GL.DepthMask(true);

            colorShader.UnuseShader();
        }
Example #2
0
        public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
        {
            if (global)
            {
                SetParameter(loc_mvp, ref param.ortho, false);

                SetParameter(TextureUnit.Texture0, param.deferredAlbedoMap);
                SetParameter(TextureUnit.Texture1, param.deferredWorldPosMap);
                SetParameter(TextureUnit.Texture2, param.deferredWorldNormalMap);
                SetParameter(TextureUnit.Texture3, param.deferredPhysicalParamsMap);
                SetParameter(TextureUnit.Texture4, param.deferredF0Map);
                SetParameter(TextureUnit.Texture5, param.deferredDepthMap);
                SetParameter(TextureUnit.Texture6, param.deferredShadowMap);
                SetParameter(TextureUnit.Texture8, param.environmentMap);

                SetParameter(loc_resolution, param.resolution);
                SetParameter(loc_resolutionInv, param.resolution.Inverse());
                SetParameter(loc_nearfar, new Vector2(param.camera.Near, param.camera.Far));
                SetParameter(loc_camDir, ref param.cameraDir);
                SetParameter(loc_camPos, ref param.cameraPos);
                SetParameter(loc_gAmbient, MMW.GlobalAmbient);
                SetParameter(loc_ibl, MMW.IBLIntensity);
                SetParameter(loc_fog, MMW.FogIntensity);
                SetParameter(loc_fogcolor, param.camera.ClearColor);

                SetDirectionalLightParameter(loc_dirLight, param.dirLight);
            }
        }
Example #3
0
        protected void RenderToDepthMap(RenderTexture rt, ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            // レンダーターゲットをセット
            rt.Bind(Color4.White);

            depthShader.UseShader();
            //depthShader.SetUniqueParameter(sp, true);

            foreach (var sh in sm)
            {
                foreach (var mat in sh.Value)
                {
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible || !sub.CastShadow)
                        {
                            continue;
                        }
                        sp.world = sub.WorldTransform;
                        depthShader.SetUniqueParameter(sp, false);

                        if (sub.Animator != null)
                        {
                            sub.Animator.BindMotion(1);
                            depthShader.SetParameter(depthShader.loc_skin, 1);
                        }
                        else
                        {
                            depthShader.SetParameter(depthShader.loc_skin, 0);
                        }
                        Drawer.DrawSubMesh(sub.SubMesh);
                    }
                }
            }
        }
Example #4
0
 public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
 {
     if (!global)
     {
         var mvp = param.world * param.viewProj;
         SetParameter(loc_mvp, ref mvp, false);
     }
 }
Example #5
0
        protected void DrawMeshes(ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            foreach (var sh in sm)
            {
                sh.Key.UseShader();
                sh.Key.SetUniqueParameter(sp, true);
                foreach (var mat in sh.Value)
                {
                    mat.Key.ApplyShaderParam();
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible)
                        {
                            continue;
                        }

                        sp.world = sub.WorldTransform;

                        // ls = MMW.lightSorts[sub.GameObject];
                        //sp.pointLights = ls.first;
                        //sp.spotLights = ls.second;
                        sh.Key.SetUniqueParameter(sp, false);

                        if (sub.Morpher != null)
                        {
                            sub.Morpher.UseMorph(0);
                        }
                        if (sub.Animator != null)
                        {
                            sub.Animator.BindMotion(1);
                        }
                        else
                        {
                            Animator.BindIdentity(1);
                        }
                        Drawer.DrawSubMesh(sub.SubMesh);
                        if (sub.Animator != null)
                        {
                            sub.Animator.UnbindMotion(1);
                        }
                        else
                        {
                            Animator.UnbindIdentity(1);
                        }
                        if (sub.Morpher != null)
                        {
                            sub.Morpher.UnuseMorph(0);
                        }
                    }
                }
                sh.Key.UnuseShader();
            }

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
        public void Draw(double deltaTime, Camera camera)
        {
            if (MeshRenderer == null)
            {
                return;
            }

            var drawMeshDic = new Dictionary <Material, List <SubMesh> >();

            for (var i = 0; i < MeshRenderer.MaterialCount; i++)
            {
                var mat = MeshRenderer.GetMaterialAt(i);
                drawMeshDic.Add(mat, new List <SubMesh>());
            }
            foreach (var sm in MeshRenderer.Mesh.subMeshes)
            {
                var mat = MeshRenderer.GetMaterial(sm.materialIndex);
                drawMeshDic[mat].Add(sm);
            }

            var sp = new ShaderUniqueParameter()
            {
                camera          = camera,
                cameraDir       = camera.WorldDirection,
                cameraPos       = camera.Transform.WorldPosition,
                deltaTime       = deltaTime,
                dirLight        = DirLight,
                environmentMap  = camera.EnvironmentMap,
                proj            = Projection,
                resolution      = new Vector2(MMW.Width, MMW.Height),
                projInverse     = Projection.Inverted(),
                view            = View,
                viewInverse     = View.Inverted(),
                viewProj        = View * Projection,
                viewProjInverse = (View * Projection).Inverted(),
                world           = Model,
                worldInv        = Model.Inverted(),
                skinning        = false,
                morphing        = false,
            };

            sh.UseShader();
            sh.SetUniqueParameter(sp, true);
            foreach (var mat in drawMeshDic)
            {
                mat.Key.ApplyShaderParam();
                foreach (var sub in mat.Value)
                {
                    sh.SetUniqueParameter(sp, false);
                    Drawer.DrawSubMesh(sub);
                }
            }
            sh.UnuseShader();
        }
Example #7
0
 public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
 {
     if (!global)
     {
         var mi  = param.world.Inverted();
         var mvp = param.world * param.viewProj;
         SetParameter(loc_mvp, ref mvp, false);
         SetParameter(loc_mit, ref mi, true);
         SetParameterByName("lightDir", param.dirLight.WorldDirection);
     }
 }
Example #8
0
 public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
 {
     if (!global)
     {
         var mi  = param.world.Inverted();
         var mvp = param.world * param.viewProj;
         SetParameter(loc_mvp, ref mvp, false);
     }
     else
     {
         SetParameter(loc_color, ref color);
     }
 }
Example #9
0
        public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
        {
            if (!global)
            {
                var mi  = param.world.Inverted();
                var mvp = param.world * param.viewProj;
                SetParameter(loc_m, ref param.world, false);
                SetParameter(loc_mit, ref mi, true);
                SetParameter(loc_mvp, ref mvp, false);
                SetParameter(loc_shadowMV1, param.world * param.shadowDepthBias1, false);
                SetParameter(loc_shadowMV2, param.world * param.shadowDepthBias2, false);
                SetParameter(loc_shadowMV3, param.world * param.shadowDepthBias3, false);
                SetParameter(loc_uniqueColor, ref param.uniqueColor);
            }
            else
            {
                SetParameter(loc_camPos, ref param.cameraPos);
                SetParameter(loc_camDir, ref param.cameraDir);
                SetParameter(loc_lightDir, param.dirLight.WorldDirection);
                SetParameter(loc_lightColor, param.dirLight.Color);
                SetParameter(loc_lightIntensity, param.dirLight.Intensity);
                SetParameter(loc_gAmbient, MMW.GlobalAmbient);

                if (param.shadowDepthMap1 != null)
                {
                    SetParameter(TextureUnit.Texture2, param.shadowDepthMap1);
                }
                else
                {
                    SetParameter(TextureUnit.Texture2, whiteMap);
                }

                if (param.shadowDepthMap2 != null)
                {
                    SetParameter(TextureUnit.Texture3, param.shadowDepthMap2);
                }
                else
                {
                    SetParameter(TextureUnit.Texture3, whiteMap);
                }

                if (param.shadowDepthMap3 != null)
                {
                    SetParameter(TextureUnit.Texture4, param.shadowDepthMap3);
                }
                else
                {
                    SetParameter(TextureUnit.Texture4, whiteMap);
                }
            }
        }
Example #10
0
        protected internal override void OnLoad()
        {
            base.OnLoad();

            CreateShadowMap();

            whiteMap    = MMW.GetAsset <Texture2D>("WhiteMap");
            depthShader = (DepthShader)MMW.GetAsset <Shader>("Depth");
            colorShader = (ColorShader)MMW.GetAsset <Shader>("Color");

            depthRT = new RenderTexture(MMW.RenderResolution);
            depthRT.ColorFormat0 = PixelInternalFormat.Rgba16f;
            depthRT.Load();

            colorRT = new RenderTexture(MMW.RenderResolution);
            colorRT.ColorFormat0 = MMW.Configuration.DefaultPixelFormat;
            colorRT.Load();
            randColors = new Color4[ushort.MaxValue + 1];
            for (var i = 0; i < randColors.Length; i++)
            {
                randColors[i] = new Color4(
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    1.0f);
            }

            shadowDepthBias = Matrix4.CreateScale(0.5f) * Matrix4.CreateTranslation(0.5f, 0.5f, 0.5f);

            velocityShader          = (VelocityShader)MMW.GetAsset <Shader>("Velocity");
            velocityRT              = new RenderTexture(MMW.RenderResolution);
            velocityRT.ColorFormat0 = PixelInternalFormat.Rgba16f;
            velocityRT.Load();

            sp = new ShaderUniqueParameter()
            {
                camera = this,
            };

            getter.Add("Orthographic", obj => Orthographic);
            getter.Add("Up", obj => Up);
            getter.Add("Width", obj => Width);
            getter.Add("Height", obj => Height);
            getter.Add("Aspect", obj => Aspect);
            getter.Add("FoV", obj => FoV);
            getter.Add("Near", obj => Near);
            getter.Add("Far", obj => Far);
            getter.Add("Depth", obj => Depth);
            getter.Add("ClearColor", obj => ClearColor);
        }
        public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
        {
            if (!global)
            {
                var mvp    = param.world * param.viewProj;
                var oldmvp = param.oldWorld * param.oldViewProj;
                SetParameter(loc_m, ref param.world, false);
                SetParameter(loc_mit, ref param.worldInv, true);
                SetParameter(loc_mvp, ref mvp, false);
                SetParameter(loc_oldmvp, ref oldmvp, false);
                SetParameter(loc_shadowMV1, param.world * param.shadowDepthBias1, false);
                SetParameter(loc_shadowMV2, param.world * param.shadowDepthBias2, false);
                SetParameter(loc_shadowMV3, param.world * param.shadowDepthBias3, false);
            }
            else
            {
                SetParameter(loc_camPos, ref param.cameraPos);
                SetParameter(loc_camDir, ref param.cameraDir);
                SetParameter(loc_resolution, MMW.RenderResolution.ToVector2().Inverse());
                SetParameter(loc_deltaTime, param.deltaTime);

                if (param.shadowDepthMap1 != null)
                {
                    SetParameter(TextureUnit.Texture3, param.shadowDepthMap1);
                }
                else
                {
                    SetParameter(TextureUnit.Texture3, whiteMap);
                }

                if (param.shadowDepthMap2 != null)
                {
                    SetParameter(TextureUnit.Texture4, param.shadowDepthMap2);
                }
                else
                {
                    SetParameter(TextureUnit.Texture4, whiteMap);
                }

                if (param.shadowDepthMap3 != null)
                {
                    SetParameter(TextureUnit.Texture5, param.shadowDepthMap3);
                }
                else
                {
                    SetParameter(TextureUnit.Texture5, whiteMap);
                }
            }
        }
 public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
 {
     if (!global)
     {
         var mi     = param.world.Inverted();
         var mvp    = param.world * param.viewProj;
         var oldMvp = param.oldWorld * param.oldViewProj;
         SetParameter(loc_mit, ref mi, true);
         SetParameter(loc_mvp, ref mvp, false);
         SetParameter(loc_oldmvp, ref oldMvp, false);
     }
     else
     {
         SetParameter(loc_deltaTime, (float)param.deltaTime);
     }
 }
Example #13
0
        protected void RenderToColorMap(RenderTexture rt, ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            // レンダーターゲットをセット
            rt.Bind(Color4.Black);

            colorShader.UseShader();
            colorShader.SetUniqueParameter(sp, true);

            ushort index = 0;

            foreach (var sh in sm)
            {
                foreach (var mat in sh.Value)
                {
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible)
                        {
                            continue;
                        }
                        sp.world = sub.WorldTransform;
                        colorShader.SetUniqueParameter(sp, false);
                        colorShader.SetParameter(colorShader.loc_color, ref randColors[index++]);

                        if (sub.Animator != null)
                        {
                            sub.Animator.BindMotion(1);
                        }
                        else
                        {
                            Animator.BindIdentity(1);
                        }
                        Drawer.DrawSubMesh(sub.SubMesh);
                        if (sub.Animator != null)
                        {
                            sub.Animator.UnbindMotion(1);
                        }
                        else
                        {
                            Animator.UnbindIdentity(1);
                        }
                    }
                }
            }
        }
Example #14
0
        public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
        {
            if (!global)
            {
                var mi  = param.world.Inverted();
                var mvp = param.world * param.viewProj;
                SetParameter(loc_m, ref param.world, false);
                SetParameter(loc_mvp, ref mvp, false);
                SetParameter(loc_shadowMV1, param.world * param.shadowDepthBias1, false);
                SetParameter(loc_shadowMV2, param.world * param.shadowDepthBias2, false);
                SetParameter(loc_shadowMV3, param.world * param.shadowDepthBias3, false);
            }
            else
            {
                SetParameter(loc_camPos, ref param.cameraPos);

                if (param.shadowDepthMap1 != null)
                {
                    SetParameter(TextureUnit.Texture0, param.shadowDepthMap1);
                }
                else
                {
                    SetParameter(TextureUnit.Texture0, whiteMap);
                }

                if (param.shadowDepthMap2 != null)
                {
                    SetParameter(TextureUnit.Texture1, param.shadowDepthMap2);
                }
                else
                {
                    SetParameter(TextureUnit.Texture1, whiteMap);
                }

                if (param.shadowDepthMap3 != null)
                {
                    SetParameter(TextureUnit.Texture2, param.shadowDepthMap3);
                }
                else
                {
                    SetParameter(TextureUnit.Texture2, whiteMap);
                }
            }
        }
Example #15
0
        protected void RenderToVelocityMap(RenderTexture rt, ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            // レンダーターゲットをセット
            rt.Bind(Color4.Black);

            velocityShader.UseShader();
            velocityShader.SetUniqueParameter(sp, true);

            foreach (var sh in sm)
            {
                foreach (var mat in sh.Value)
                {
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible)
                        {
                            continue;
                        }
                        sp.world    = sub.WorldTransform;
                        sp.oldWorld = sub.OldWorldTransform;
                        velocityShader.SetUniqueParameter(sp, false);

                        if (sub.Animator != null)
                        {
                            sub.Animator.BindMotion(1, 2);
                        }
                        else
                        {
                            Animator.BindIdentity(1, 2);
                        }
                        Drawer.DrawSubMesh(sub.SubMesh);
                        if (sub.Animator != null)
                        {
                            sub.Animator.UnbindMotion(1, 2);
                        }
                        else
                        {
                            Animator.UnbindIdentity(1, 2);
                        }
                    }
                }
            }
        }
Example #16
0
 public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
 {
     if (!global)
     {
         var mi  = param.world.Inverted();
         var mvp = param.world * param.viewProj;
         SetParameter(loc_m, ref param.world, false);
         SetParameter(loc_mit, ref mi, true);
         SetParameter(loc_mvp, ref mvp, false);
     }
     else
     {
         SetParameter(loc_camPos, ref param.cameraPos);
         SetParameter(loc_camDir, ref param.cameraDir);
         SetParameter(loc_lightDir, param.dirLight.WorldDirection);
         SetParameter(loc_lightColor, param.dirLight.Color);
         SetParameter(loc_lightIntensity, param.dirLight.Intensity);
         SetParameter(loc_gAmbient, MMW.GlobalAmbient);
     }
 }
Example #17
0
        public override void SetUniqueParameter(ShaderUniqueParameter param, bool global)
        {
            if (!global)
            {
                var mi  = param.world.Inverted();
                var mvp = param.world * param.viewProj;
                SetParameter(loc_m, ref param.world, false);
                SetParameter(loc_mit, ref mi, true);
                SetParameter(loc_mvp, ref mvp, false);
                SetParameter(loc_shadowMV1, param.world * param.shadowDepthBias1, false);
                SetParameter(loc_shadowMV2, param.world * param.shadowDepthBias2, false);
                SetParameter(loc_shadowMV3, param.world * param.shadowDepthBias3, false);

                if (param.pointLights != null)
                {
                    for (var i = 0; i < PointLightNum; i++)
                    {
                        if (i >= param.pointLights.Count)
                        {
                            SetParameter(loc_pointLights[i].intensity, 0.0f);
                            break;
                        }
                        SetPointLightParameter(loc_pointLights[i], param.pointLights[i]);
                    }
                }

                if (param.spotLights != null)
                {
                    for (var i = 0; i < SpotLightNum; i++)
                    {
                        if (i >= param.spotLights.Count)
                        {
                            SetParameter(loc_spotLights[i].intensity, 0.0f);
                            break;
                        }
                        SetSpotLightParameter(loc_spotLights[i], param.spotLights[i]);
                    }
                }
            }
            else
            {
                SetParameter(loc_camPos, ref param.cameraPos);
                SetParameter(loc_camDir, ref param.cameraDir);
                SetParameter(loc_gAmbient, MMW.GlobalAmbient);
                SetParameter(loc_ibl, MMW.IBLIntensity);
                SetParameter(loc_resolution, MMW.RenderResolution.ToVector2().Inverse());

                SetDirectionalLightParameter(loc_dirLight, param.dirLight);

                if (param.environmentMap != null)
                {
                    SetParameter(TextureUnit.Texture2, param.environmentMap);
                }
                else
                {
                    SetParameter(TextureUnit.Texture2, environmentMap);
                }

                if (param.shadowDepthMap1 != null)
                {
                    SetParameter(TextureUnit.Texture3, param.shadowDepthMap1);
                }
                else
                {
                    SetParameter(TextureUnit.Texture3, whiteMap);
                }

                if (param.shadowDepthMap2 != null)
                {
                    SetParameter(TextureUnit.Texture4, param.shadowDepthMap2);
                }
                else
                {
                    SetParameter(TextureUnit.Texture4, whiteMap);
                }

                if (param.shadowDepthMap3 != null)
                {
                    SetParameter(TextureUnit.Texture5, param.shadowDepthMap3);
                }
                else
                {
                    SetParameter(TextureUnit.Texture5, whiteMap);
                }

                SetParameter(loc_skinning, param.skinning ? 1 : 0);
                SetParameter(loc_morphing, param.morphing ? 1 : 0);
            }
        }
        protected void DrawDeferredMeshes(ShaderUniqueParameter sp, Dictionary <Shader, Dictionary <Material, List <SubMeshData> > > sm)
        {
            foreach (var sh in sm)
            {
                sh.Key.UseShader();
                sh.Key.SetUniqueParameter(sp, true);
                foreach (var mat in sh.Value)
                {
                    mat.Key.ApplyShaderParam();
                    foreach (var sub in mat.Value)
                    {
                        if (!sub.Visible)
                        {
                            continue;
                        }

                        //int result;
                        //GL.GetQueryObject(sub.OcclusionQuery, GetQueryObjectParam.QueryResult, out result);
                        //if (result == 0)
                        //{
                        //    continue;
                        //}


                        sp.world    = sub.WorldTransform;
                        sp.worldInv = sub.WorldTransformInv;
                        sp.oldWorld = sub.OldWorldTransform;

                        sh.Key.SetUniqueParameter(sp, false);

                        if (sub.Morpher != null)
                        {
                            sub.Morpher.UseMorph(0);
                        }
                        if (sub.Animator != null)
                        {
                            sub.Animator.BindMotion(1, 2);
                        }
                        else
                        {
                            AAnimator.BindIdentity(1, 2);
                        }

                        Drawer.DrawSubMesh(sub.SubMesh, sub.MeshRenderer.BeginMode);

                        if (sub.Animator != null)
                        {
                            sub.Animator.UnbindMotion(1, 2);
                        }
                        else
                        {
                            AAnimator.UnbindIdentity(1, 2);
                        }
                        if (sub.Morpher != null)
                        {
                            sub.Morpher.UnuseMorph(0);
                        }
                    }
                }
                sh.Key.UnuseShader();
            }

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
        protected internal override void OnLoad()
        {
            CreateShadowMap();

            depthShader = (DepthShader)MMW.GetAsset <Shader>("Depth");

            deferredRT              = new RenderTexture(MMW.RenderResolution);
            deferredRT.MultiBuffer  = 8;
            deferredRT.ColorFormat0 = PixelInternalFormat.Rgba8;            // albedo
            deferredRT.ColorFormat1 = PixelInternalFormat.Rgb16f;           // world pos
            deferredRT.ColorFormat2 = PixelInternalFormat.Rgb16f;           // world normal
            deferredRT.ColorFormat3 = PixelInternalFormat.Rg8;              // physical params
            deferredRT.ColorFormat4 = PixelInternalFormat.Rgb8;             // f0
            deferredRT.ColorFormat5 = PixelInternalFormat.R32f;             // depth
            deferredRT.ColorFormat6 = PixelInternalFormat.R8;               // shadow
            deferredRT.ColorFormat7 = PixelInternalFormat.Rgba16f;          // velocity
            //deferredRT.ColorFormat8 = PixelInternalFormat.Rgb8;           // unique color
            deferredRT.Load();

            deferredShader = new DeferredPhysicalLightingShader();
            deferredShader.Load();

            backShader = new DeferredBackgroundShader();
            backShader.Load();

            cubeMesh = Mesh.CreateSimpleBoxMesh(Vector3.One * 50.0f);
            for (var i = 0; i < cubeMesh.Vertices.Length; i++)
            {
                cubeMesh.Vertices[i].X *= -1.0f;
            }
            cubeMesh.Load();

            // 影響を及ぼすライト
            lightRT = new RenderTexture(MMW.RenderResolution.Width / 16 + 1, MMW.RenderResolution.Height / 16 + 1);
            lightRT.ColorFormat0 = PixelInternalFormat.Rgb8;
            lightRT.Load();
            plMesh             = Mesh.CreateSimpleSphereMesh(1.0f);
            lightCullingShader = new LightCullingShader();
            lightCullingShader.Load();
            // ライト数格納
            initCounts = new int[lightRT.Size.Width * lightRT.Size.Height];
            GL.GenBuffers(1, out ssbo_count);
            GL.BindBuffer(BufferTarget.ShaderStorageBuffer, ssbo_count);
            GL.BufferData(BufferTarget.ShaderStorageBuffer, initCounts.Length * 4, initCounts, BufferUsageHint.StreamDraw);
            GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
            // ライトインデックス格納
            initIndices = new int[lightRT.Size.Width * lightRT.Size.Height * 64];
            GL.GenBuffers(1, out ssbo_index);
            GL.BindBuffer(BufferTarget.ShaderStorageBuffer, ssbo_index);
            GL.BufferData(BufferTarget.ShaderStorageBuffer, initIndices.Length * 4, initIndices, BufferUsageHint.StreamDraw);
            GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
            // ライト情報
            {
                BufferLight[] tmps = new BufferLight[2048];
                GL.GenBuffers(1, out ssbo_light);
                GL.BindBuffer(BufferTarget.ShaderStorageBuffer, ssbo_light);
                GL.BufferData(BufferTarget.ShaderStorageBuffer, tmps.Length * 20 * 4, tmps, BufferUsageHint.StreamDraw);
                GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
            }

            whiteMap = MMW.GetAsset <Texture2D>("WhiteMap");

            randColors = new Color4[ushort.MaxValue + 1];
            for (var i = 0; i < randColors.Length; i++)
            {
                randColors[i] = new Color4(
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    RandomHelper.NextFloat() * 0.5f + 0.5f,
                    1.0f);
            }

            shadowDepthBias = Matrix4.CreateScale(0.5f) * Matrix4.CreateTranslation(0.5f, 0.5f, 0.5f);

            sp = new ShaderUniqueParameter()
            {
                camera = this,
            };

            // オクルージョンカリング用クエリ
            queries = new int[4096];
            GL.GenQueries(queries.Length, queries);
            colorShader = (ColorShader)MMW.GetAsset <Shader>("Color");

            boundsMesh = Mesh.CreateSimpleBoxMesh(Vector3.One);
        }