protected virtual void setupScene()
        {
            hud2dScene       = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            environmentScene = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            sunFlareScene    = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            sunDiskScene     = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);

            main3dScene = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            main3dScene.renderConfig.frustumCulling     = true;
            main3dScene.renderConfig.usePoissonSampling = true;
            main3dScene.BeforeRenderObject += this.beforeRenderObjectHandler;

            alpha3dScene = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            alpha3dScene.renderConfig.frustumCulling     = true;
            alpha3dScene.renderConfig.usePoissonSampling = false;
            alpha3dScene.BeforeRenderObject += this.beforeRenderObjectHandler;

            // 0. Add Lights
            var light = new SSDirectionalLight(LightName.Light0);

            light.Direction = new Vector3(0f, 0f, -1f);
                        #if true
            if (OpenTKHelper.areFramebuffersSupported())
            {
                if (main3dScene.renderConfig.pssmShader != null && main3dScene.renderConfig.instancePssmShader != null)
                {
                    //if (false) {
                    light.ShadowMap = new SSParallelSplitShadowMap(TextureUnit.Texture7);
                }
                else
                {
                    light.ShadowMap = new SSSimpleShadowMap(TextureUnit.Texture7);
                }
            }
            if (!light.ShadowMap.IsValid)
            {
                light.ShadowMap = null;
            }
                        #endif
            main3dScene.AddLight(light);

                        #if true
            if (light.ShadowMap != null)
            {
                shadowmapDebugQuad       = new SSObjectHUDQuad(light.ShadowMap.TextureID);
                shadowmapDebugQuad.Scale = new Vector3(0.3f);
                shadowmapDebugQuad.Pos   = new Vector3(50f, 200, 0f);
                hud2dScene.AddObject(shadowmapDebugQuad);
            }
                        #endif
        }
예제 #2
0
        protected virtual void setupScene()
        {
            scene            = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            sunDiskScene     = new SSScene();
            sunFlareScene    = new SSScene();
            hudScene         = new SSScene();
            environmentScene = new SSScene();

            scene.renderConfig.frustumCulling = true;              // TODO: fix the frustum math, since it seems to be broken.
            scene.BeforeRenderObject         += beforeRenderObjectHandler;

            // 0. Add Lights
            var light = new SSDirectionalLight(LightName.Light0);

            light.Direction = new Vector3(0f, 0f, -1f);
                        #if true
            if (OpenTKHelper.areFramebuffersSupported())
            {
                if (scene.renderConfig.pssmShader != null && scene.renderConfig.instancePssmShader != null)
                {
                    light.ShadowMap = new SSParallelSplitShadowMap(TextureUnit.Texture7);
                }
                else
                {
                    light.ShadowMap = new SSSimpleShadowMap(TextureUnit.Texture7);
                }
            }
            if (!light.ShadowMap.IsValid)
            {
                light.ShadowMap = null;
            }
                        #endif
            scene.AddLight(light);

                        #if true
            var smapDebug = new SSObjectHUDQuad(light.ShadowMap.TextureID);
            smapDebug.Scale = new Vector3(0.3f);
            smapDebug.Pos   = new Vector3(50f, 200, 0f);
            hudScene.AddObject(smapDebug);
                        #endif

            // setup a sun billboard object and a sun flare spriter renderer
            {
                var sunDisk      = new SSMeshDisk();
                var sunBillboard = new SSObjectBillboard(sunDisk, true);
                sunBillboard.MainColor = new Color4(1f, 1f, 0.8f, 1f);
                sunBillboard.Pos       = new Vector3(0f, 0f, 18000f);
                sunBillboard.Scale     = new Vector3(600f);
                sunBillboard.renderState.frustumCulling = false;
                sunBillboard.renderState.lighted        = false;
                sunBillboard.renderState.castsShadow    = false;
                sunDiskScene.AddObject(sunBillboard);

                SSTexture    flareTex         = SSAssetManager.GetInstance <SSTextureWithAlpha>(".", "sun_flare.png");
                const float  bigOffset        = 0.8889f;
                const float  smallOffset      = 0.125f;
                RectangleF[] flareSpriteRects =
                {
                    new RectangleF(0f,                      0f,          1f, bigOffset),
                    new RectangleF(0f,               bigOffset, smallOffset, smallOffset),
                    new RectangleF(smallOffset,      bigOffset, smallOffset, smallOffset),
                    new RectangleF(smallOffset * 2f, bigOffset, smallOffset, smallOffset),
                    new RectangleF(smallOffset * 3f, bigOffset, smallOffset, smallOffset),
                };
                float[] spriteScales = { 20f, 1f, 2f, 1f, 1f };
                var     sunFlare     = new SimpleSunFlareMesh(sunDiskScene, sunBillboard, flareTex,
                                                              flareSpriteRects, spriteScales);
                sunFlare.Scale = new Vector3(2f);
                sunFlare.renderState.lighted = false;
                sunFlareScene.AddObject(sunFlare);
            }
        }