示例#1
0
        protected override void setupScene()
        {
            base.setupScene();

            laserOccDiskScene3d = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);
            laserFlareScene2d   = new SSScene(mainShader, pssmShader, instancingShader, instancingPssmShader);

            var mesh = SSAssetManager.GetInstance <SSMesh_wfOBJ>("./drone2/Drone2.obj");

            // add drones
            droneObj1     = new SSObjectMesh(mesh);
            droneObj1.Pos = new OpenTK.Vector3(-20f, 0f, -15f);
            droneObj1.Orient(Quaternion.FromAxisAngle(Vector3.UnitY, (float)Math.PI / 2f));
            //droneObj1.renderState.visible = false;
            droneObj1.Name = "attacker drone";
            main3dScene.AddObject(droneObj1);

            droneObj2           = new SSObjectMesh(mesh);
            droneObj2.Pos       = new OpenTK.Vector3(20f, 0f, -15f);
            droneObj2.Name      = "target drone";
            droneObj2.MainColor = new Color4(1f, 0f, 0.7f, 1f);
            //droneObj2.renderState.visible = false;
            main3dScene.AddObject(droneObj2);

            // manages laser objects
            laserManager = new SLaserManager(alpha3dScene, laserOccDiskScene3d, laserFlareScene2d);

            // tweak the laser start point (by adding an offset in object-local coordinates)
            laserSourceTxfm = Matrix4.CreateTranslation(0f, 1f, 2.75f);

            // debugging snippets:
            //droneObj1.MainColor = Color4.Green;
            //droneObj1.renderState.visible = false;
        }
示例#2
0
        public SSpaceMissilesRenderManager(SSScene objScene, SSScene particleScene, SSScene screenScene,
                                           int particleCapacity = 10000)
        {
            _simulation = new SSpaceMissilesVisualSimulation();

            _objScene = objScene;
            objScene.preRenderHooks += this._preRenderUpdate;

            objScene.preUpdateHooks += _simulation.updateSimulation;
            objScene.preRenderHooks += simulation.updateSimulation;

            _screenScene = screenScene;

            // particle system
            _particlesData    = new SSParticleSystemData(particleCapacity);
            _particleRenderer = new SSInstancedMeshRenderer(
                _particlesData, SSTexturedQuad.SingleFaceInstance);
            _particleRenderer.renderState.alphaBlendingOn = true;
            _particleRenderer.renderState.castsShadow     = false;
            _particleRenderer.renderState.receivesShadows = false;
            _particleRenderer.renderState.depthTest       = true;
            _particleRenderer.renderState.depthWrite      = false;
            //_particleRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.CpuFallback;
            //_particleRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            //_particleRenderer.renderState.visible = false;

            _particleRenderer.AmbientMatColor   = new Color4(1f, 1f, 1f, 1f);
            _particleRenderer.DiffuseMatColor   = new Color4(0f, 0f, 0f, 0f);
            _particleRenderer.EmissionMatColor  = new Color4(0f, 0f, 0f, 0f);
            _particleRenderer.SpecularMatColor  = new Color4(0f, 0f, 0f, 0f);
            _particleRenderer.ShininessMatColor = 0f;

            _particleRenderer.Name = "missile smoke renderer";
            particleScene.AddObject(_particleRenderer);
        }
示例#3
0
            public TargetSpecific(SSScene main3dScene, SSScene hud2dScene)
            {
                _targetObj3dScene           = main3dScene;
                main3dScene.preRenderHooks += preRenderUpdate;

                _outline = new SSObjectMesh();
                _outline.renderState.lighted         = false;
                _outline.renderState.alphaBlendingOn = true;
                _outline.renderState.frustumCulling  = false;
                _outline.renderState.noShader        = true;
                _outline.lineStipplePattern          = 0xFFC0;
                _outline.Name           = "hud target outline";
                _outline.preRenderHook += (obj, rc) => {
                    GL.LineWidth(_targetViewDepth < 0f ? outlineWidthWhenInFront : outlinelineWidthWhenBehind);
                    GL.Disable(EnableCap.LineSmooth);
                };
                hud2dScene.AddObject(_outline);

                _labelBelow = new SSObjectGDISurface_Text();
                _labelBelow.renderState.alphaBlendingOn = true;
                _labelBelow.Name = "hud target label below";
                hud2dScene.AddObject(_labelBelow);

                _labelAbove = new SSObjectGDISurface_Text();
                _labelAbove.renderState.alphaBlendingOn = true;
                _labelAbove.Name = "hud target label above";
                hud2dScene.AddObject(_labelAbove);
            }
        public SSpaceMissilesRenderManager (SSScene objScene, SSScene particleScene, SSScene screenScene,
                                            int particleCapacity = 10000)
        {
            _simulation = new SSpaceMissilesSimulation ();

            _objScene = objScene;
            objScene.preRenderHooks += this._preRenderUpdate;

            objScene.preUpdateHooks += _simulation.updateSimulation;
            objScene.preRenderHooks += simulation.updateSimulation;

            _screenScene = screenScene;

            // particle system
            _particlesData = new SSParticleSystemData (particleCapacity);
            _particleRenderer = new SSInstancedMeshRenderer (
                _particlesData, SSTexturedQuad.SingleFaceInstance);
            _particleRenderer.renderState.alphaBlendingOn = true;
            _particleRenderer.renderState.castsShadow = false;
            _particleRenderer.renderState.receivesShadows = false;
            _particleRenderer.renderState.depthTest = true;
            _particleRenderer.renderState.depthWrite = false;
            //_particleRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.CpuFallback;
            //_particleRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            //_particleRenderer.renderState.visible = false;

            _particleRenderer.AmbientMatColor = new Color4 (1f, 1f, 1f, 1f);
            _particleRenderer.DiffuseMatColor = new Color4 (0f, 0f, 0f, 0f);
            _particleRenderer.EmissionMatColor = new Color4(0f, 0f, 0f, 0f);
            _particleRenderer.SpecularMatColor = new Color4 (0f, 0f, 0f, 0f);
            _particleRenderer.ShininessMatColor = 0f;

            _particleRenderer.Name = "missile smoke renderer";
            particleScene.AddObject(_particleRenderer);
        }
示例#5
0
        public SLaserBeamMiddleObject(SLaser laser,
                                      int beamId,
                                      SSScene cameraScene,
                                      SSTexture middleBackgroundTexture,
                                      SSTexture middleOverlayTexture,
                                      SSTexture inteferenceTexture)
        {
            this._laser       = laser;
            this._beamId      = beamId;
            this._cameraScene = cameraScene;

            this.renderState.castsShadow     = false;
            this.renderState.receivesShadows = false;
            this.renderState.depthTest       = true;
            this.renderState.depthWrite      = false;
            this.renderState.alphaBlendingOn = true;
            //this.renderState.alphaBlendingOn = false;

            renderState.blendFactorSrcRGB  = renderState.blendFactorSrcAlpha = BlendingFactorSrc.SrcAlpha;
            renderState.blendFactorDestRGB = renderState.blendFactorDestAlpha = BlendingFactorDest.One;

            // reset all mat colors. emission will be controlled during rendering
            this.colorMaterial = new SSColorMaterial(Color4Helper.Zero);

            this.middleBackgroundSprite = middleBackgroundTexture;
            this.middleOverlayTexture   = middleOverlayTexture;
            this.interferenceTexture    = inteferenceTexture;

            // initialize non-changing vertex data
            _initMiddleMesh();
            _initInterferenceVertices();

            // force an update to make sure we are not rendering (very noticable) bogus
            Update(0f);
        }
        public SSInstancedSpriteRenderer(
            SSScene cameraScene3d,
            SSInstancesData instanceData,
            SSTexture tex = null
            )
            : base(instanceData,
                   SSTexturedQuad.DoubleFaceInstance,
                   BufferUsageHint.StreamDraw)
        {
            base.renderState.castsShadow     = false;
            base.renderState.receivesShadows = false;
            base.renderState.depthTest       = false;
            base.renderState.depthWrite      = false;
            base.renderState.lighted         = false;
            base.AmbientMatColor             = new Color4(1f, 1f, 1f, 1f);
            base.DiffuseMatColor             = new Color4(0f, 0f, 0f, 0f);
            base.EmissionMatColor            = new Color4(0f, 0f, 0f, 0f);
            base.SpecularMatColor            = new Color4(0f, 0f, 0f, 0f);
            base.ShininessMatColor           = 0f;
            base.selectable = false;
            if (tex != null)
            {
                base.textureMaterial = new SSTextureMaterial(tex);
            }

            this.cameraScene3d = cameraScene3d;
        }
示例#7
0
        public SLaserManager(SSScene beamScene3d, SSScene occDiskScene, SSScene flareScene2d,
            int sprite2dCapacity = 1000, int laserBurnParticlesCapacity = 2000)
        {
            _beamScene3d = beamScene3d;
            _occDiskScene = occDiskScene;
            _flareScene2d = flareScene2d;

            _2dEffectInstanceData = new SInstancedSpriteData (sprite2dCapacity);
            _2dEffectRenderer = new SSInstancedSpriteRenderer (_beamScene3d, _2dEffectInstanceData);
            _2dEffectRenderer.Name = "laser manager's 2d screen effect renderer";

            _2dEffectRenderer.renderState.alphaBlendingOn = true;
            _2dEffectRenderer.renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha;
            _2dEffectRenderer.renderState.blendFactorDest = BlendingFactorDest.One;
            //_2dEffectRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            _flareScene2d.AddObject(_2dEffectRenderer);

            _laserBurnParticles = new SLaserBurnParticlesObject (
                laserBurnParticlesCapacity, SLaserParameters.laserBurnParticlesDefaultTexture());
            _laserBurnParticles.Name = "laser manager's laser burn particle system renderer";
            //_laserBurnParticles.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            _beamScene3d.AddObject(_laserBurnParticles);

            _beamScene3d.preRenderHooks += this._update;
        }
示例#8
0
        public SExplosionManager(SSScene renderScene, int particleCapacity = 500)
        {
            _renderScene = renderScene;
            _particleCapacity = particleCapacity;

            // TODO unattach at the right time
            renderScene.preRenderHooks += _update;
        }
示例#9
0
        public SExplosionManager(SSScene renderScene, int particleCapacity = 500)
        {
            _renderScene      = renderScene;
            _particleCapacity = particleCapacity;

            // TODO unattach at the right time
            renderScene.preRenderHooks += _update;
        }
 public SimpleSunFlareMesh(SSScene sunScene,
                           SSObjectBillboard sun,
                           SSTexture texture,
                           RectangleF[] spriteRects,
                           Vector2[] spriteScales = null)
 {
     init(sunScene, sun, texture, spriteRects, spriteScales);
 }
示例#11
0
 public SimpleSunFlareMesh(SSScene sunScene,
                          SSObjectBillboard sun,
                          SSTexture texture,
                          RectangleF[] spriteRects,
                          Vector2[] spriteScales = null)
 {
     init(sunScene, sun, texture, spriteRects, spriteScales);
 }
        private void init(SSScene sunScene,
                          SSObjectBillboard sun,
                          SSTexture texture,
                          RectangleF[] spriteRects,
                          Vector2[] spriteScales)
        {
            base.textureMaterial = new SSTextureMaterial(texture);
            this.sunBillboard    = sun;
            this.sunScene        = sunScene;
            this.numElements     = spriteRects.Length;
            if (spriteScales == null)
            {
                spriteScales = new Vector2[numElements];
                for (int i = 0; i < numElements; ++i)
                {
                    spriteScales [i] = new Vector2(1f);
                }
            }
            else
            {
                if (spriteScales.Length != numElements)
                {
                    throw new Exception("texture coordinate array size does not match that of sprite scale array");
                    spriteScales = new Vector2[numElements];
                    for (int i = 0; i < numElements; ++i)
                    {
                        spriteScales [i] = new Vector2(1f);
                    }
                }
            }
            this.spriteScales = spriteScales;

            UInt16[] indices = new UInt16[numElements * 6];
            for (int i = 0; i < numElements; ++i)
            {
                int baseLoc = i * 6;
                int baseVal = i * 4;
                indices [baseLoc]     = (UInt16)baseVal;
                indices [baseLoc + 1] = (UInt16)(baseVal + 2);
                indices [baseLoc + 2] = (UInt16)(baseVal + 1);
                indices [baseLoc + 3] = (UInt16)baseVal;
                indices [baseLoc + 4] = (UInt16)(baseVal + 3);
                indices [baseLoc + 5] = (UInt16)(baseVal + 2);
            }
            Mesh = new SSIndexedMesh <SSVertex_PosTex> (null, indices);

            vertices = new SSVertex_PosTex[numElements * 4];
            for (int r = 0; r < spriteRects.Length; ++r)
            {
                RectangleF rect    = spriteRects [r];
                int        baseIdx = r * 4;
                vertices [baseIdx]     = new SSVertex_PosTex(0f, 0f, 0f, rect.Left, rect.Bottom);
                vertices [baseIdx + 1] = new SSVertex_PosTex(0f, 0f, 0f, rect.Right, rect.Bottom);
                vertices [baseIdx + 2] = new SSVertex_PosTex(0f, 0f, 0f, rect.Right, rect.Top);
                vertices [baseIdx + 3] = new SSVertex_PosTex(0f, 0f, 0f, rect.Left, rect.Top);
            }
        }
示例#13
0
 public BeamRuntimeInfo(SLaser laser, int beamId,
                        SSScene beamScene, SSScene occDiskScene,
                        SSInstancedSpriteRenderer sprite2dRenderer)
 {
     _laser            = laser;
     _beamId           = beamId;
     _beamScene        = beamScene;
     _occDiskScene     = occDiskScene;
     _sprite2dRenderer = sprite2dRenderer;
 }
示例#14
0
 public SLaserScreenHitFlareUpdater(
     SLaser laser, int beamId,
     SSScene camera3dScene,
     RectangleF[] rects = null,
     float[] scales     = null
     )
 {
     _rects        = rects ?? _defaultRects;
     _masterScales = scales ?? _defaultMasterScales;
     this._laser   = laser;
     this._beamId  = beamId;
 }
示例#15
0
 public SimpleSunFlareMesh(SSScene sunScene,
                         SSObjectBillboard sun,
                         SSTexture texture,
                         RectangleF[] spriteRects,
                         float[] spriteScales)
 {
     Vector2[] spriteScalesV2 = new Vector2[spriteScales.Length];
     for (int i = 0; i < spriteScalesV2.Length; ++i) {
         spriteScalesV2 [i] = new Vector2 (spriteScales [i]);
     }
     init(sunScene, sun, texture, spriteRects, spriteScalesV2);
 }
 public SLaserScreenHitFlareUpdater(
     SLaser laser, int beamId,
     SSScene camera3dScene,
     RectangleF[] rects = null,
     float[] scales = null
 )
 {
     _rects = rects ?? _defaultRects;
     _masterScales = scales ?? _defaultMasterScales;
     this._laser = laser;
     this._beamId = beamId;
 }
示例#17
0
            public LaserRuntimeInfo(SLaser laser, SSScene beamScene, SSScene occDiskScene,
                                    SSInstancedSpriteRenderer sprite2dRenderer)
            {
                _laser = laser;
                var numBeams = laser.parameters.numBeams;

                _beams = new BeamRuntimeInfo[numBeams];
                for (int i = 0; i < numBeams; ++i)
                {
                    _beams[i] = new BeamRuntimeInfo(laser, i, beamScene, occDiskScene, sprite2dRenderer);
                }
            }
示例#18
0
        public SSunFlareUpdater(
            SSScene sunDiskScene,
            SSObjectOcclusionQueuery sunDiskObj,
            RectangleF[] spriteRects = null,
            float[] spriteScales = null
        )
        {
            this._sunDiskOccScene = sunDiskScene;
            this._sunDiskOccObj = sunDiskObj;

            _rects = spriteRects ?? defaultRects;
            _scales = spriteScales ?? defaultSpriteScales;
        }
 public SimpleSunFlareMesh(SSScene sunScene,
                           SSObjectBillboard sun,
                           SSTexture texture,
                           RectangleF[] spriteRects,
                           float[] spriteScales)
 {
     Vector2[] spriteScalesV2 = new Vector2[spriteScales.Length];
     for (int i = 0; i < spriteScalesV2.Length; ++i)
     {
         spriteScalesV2 [i] = new Vector2(spriteScales [i]);
     }
     init(sunScene, sun, texture, spriteRects, spriteScalesV2);
 }
示例#20
0
        public SSunFlareUpdater(
            SSScene sunDiskScene,
            SSObjectOcclusionQueuery sunDiskObj,
            RectangleF[] spriteRects = null,
            float[] spriteScales     = null
            )
        {
            this._sunDiskOccScene = sunDiskScene;
            this._sunDiskOccObj   = sunDiskObj;

            _rects  = spriteRects ?? defaultRects;
            _scales = spriteScales ?? defaultSpriteScales;
        }
示例#21
0
        public SSSunFlareRenderer(SSScene camera3dScene, SSObjectOcclusionQueuery sunDiskObj,
            SSTexture texture = null)
            : base(camera3dScene, 
                new SInstancedSpriteData(Math.Max(SSunFlareUpdater.defaultRects.Length, 
                                                  SSunFlareUpdater.defaultSpriteScales.Length)),
                texture ?? defaultTexture())
        {
            this.renderState.alphaBlendingOn = true;
            this.renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha;
            this.renderState.blendFactorDest = BlendingFactorDest.OneMinusSrcAlpha;

            addUpdater(new SSunFlareUpdater (camera3dScene, sunDiskObj));
        }
示例#22
0
        public SSSunFlareRenderer(SSScene camera3dScene, SSObjectOcclusionQueuery sunDiskObj,
                                  SSTexture texture = null)
            : base(camera3dScene,
                   new SInstancedSpriteData(Math.Max(SSunFlareUpdater.defaultRects.Length,
                                                     SSunFlareUpdater.defaultSpriteScales.Length)),
                   texture ?? defaultTexture())
        {
            this.renderState.alphaBlendingOn = true;
            this.renderState.blendFactorSrc  = BlendingFactorSrc.SrcAlpha;
            this.renderState.blendFactorDest = BlendingFactorDest.OneMinusSrcAlpha;

            addUpdater(new SSunFlareUpdater(camera3dScene, sunDiskObj));
        }
        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
        }
示例#24
0
        //public SLaserBurnParticlesObject laserBurnParticlesObject {
        //	get { return _laserBurnParticles; }
        //}

        public SLaserManager(SSScene beamScene3d, SSScene occDiskScene, SSScene flareScene2d,
                             int sprite2dCapacity = 1000, int laserBurnParticlesCapacity = 500)
        {
            _beamScene3d  = beamScene3d;
            _occDiskScene = occDiskScene;
            _flareScene2d = flareScene2d;

            _2dEffectInstanceData  = new SInstancedSpriteData(sprite2dCapacity);
            _2dEffectRenderer      = new SSInstancedSpriteRenderer(_beamScene3d, _2dEffectInstanceData);
            _2dEffectRenderer.Name = "laser manager's 2d screen effect renderer";

            _2dEffectRenderer.renderState.alphaBlendingOn = true;
            _2dEffectRenderer.renderState.blendFactorSrc  = BlendingFactorSrc.SrcAlpha;
            _2dEffectRenderer.renderState.blendFactorDest = BlendingFactorDest.One;
            //_2dEffectRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            _flareScene2d.AddObject(_2dEffectRenderer);

            _beamScene3d.preRenderHooks += this._update;

            _maxBurnParticlesPerObject = laserBurnParticlesCapacity;
        }
示例#25
0
 public SSInstancedSpriteRenderer(
     SSScene cameraScene3d,
     SSInstancesData instanceData,
     SSTexture tex = null
     )
     : base(instanceData,
            SSTexturedQuad.doubleFaceInstance,
            BufferUsageHint.StreamDraw)
 {
     base.renderState.castsShadow     = false;
     base.renderState.receivesShadows = false;
     base.renderState.depthTest       = false;
     base.renderState.depthWrite      = false;
     base.renderState.lighted         = false;
     base.colorMaterial = SSColorMaterial.pureAmbient;
     base.selectable    = false;
     if (tex != null)
     {
         base.textureMaterial = new SSTextureMaterial(tex);
     }
     this.cameraScene3d = cameraScene3d;
 }
示例#26
0
        //public SLaserBurnParticlesObject laserBurnParticlesObject {
        //    get { return _laserBurnParticles; }
        //}
        public SLaserManager(SSScene beamScene3d, SSScene occDiskScene, SSScene flareScene2d,
            int sprite2dCapacity = 1000, int laserBurnParticlesCapacity = 500)
        {
            _beamScene3d = beamScene3d;
            _occDiskScene = occDiskScene;
            _flareScene2d = flareScene2d;

            _2dEffectInstanceData = new SInstancedSpriteData (sprite2dCapacity);
            _2dEffectRenderer = new SSInstancedSpriteRenderer (_beamScene3d, _2dEffectInstanceData);
            _2dEffectRenderer.Name = "laser manager's 2d screen effect renderer";

            _2dEffectRenderer.renderState.alphaBlendingOn = true;
            _2dEffectRenderer.renderState.blendFactorSrcRGB
                = _2dEffectRenderer.renderState.blendFactorSrcAlpha = BlendingFactorSrc.SrcAlpha;
            _2dEffectRenderer.renderState.blendFactorDestRGB
             	= _2dEffectRenderer.renderState.blendFactorDestAlpha = BlendingFactorDest.One;
            //_2dEffectRenderer.renderMode = SSInstancedMeshRenderer.RenderMode.GpuInstancing;
            _flareScene2d.AddObject(_2dEffectRenderer);

            _beamScene3d.preRenderHooks += this._update;

            _maxBurnParticlesPerObject = laserBurnParticlesCapacity;
        }
        public SLaserBeamMiddleObject(SLaser laser,
									   int beamId,
									   SSScene cameraScene,
								       SSTexture middleBackgroundTexture,
									   SSTexture middleOverlayTexture,
                                       SSTexture inteferenceTexture)
        {
            this._laser = laser;
            this._beamId = beamId;
            this._cameraScene = cameraScene;

            this.renderState.castsShadow = false;
            this.renderState.receivesShadows = false;
            this.renderState.depthTest = true;
            this.renderState.depthWrite = false;
            this.renderState.alphaBlendingOn = true;
            //this.renderState.alphaBlendingOn = false;
            this.renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha;
            this.renderState.blendFactorDest = BlendingFactorDest.One;

            // reset all mat colors. emission will be controlled during rendering
            this.AmbientMatColor = new Color4(0f, 0f, 0f, 0f);
            this.DiffuseMatColor = new Color4(0f, 0f, 0f, 0f);
            this.SpecularMatColor = new Color4(0f, 0f, 0f, 0f);
            this.EmissionMatColor = new Color4(0f, 0f, 0f, 0f);

            this.middleBackgroundSprite = middleBackgroundTexture;
            this.middleOverlayTexture = middleOverlayTexture;
            this.interferenceTexture = inteferenceTexture;

            // initialize non-changing vertex data
            _initMiddleMesh ();
            _initInterferenceVertices ();

            // force an update to make sure we are not rendering (very noticable) bogus
            Update(0f);
        }
示例#28
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);
            }
        }
示例#29
0
 public BeamRuntimeInfo(SLaser laser, int beamId, 
                        SSScene beamScene, SSScene occDiskScene,
                        SSInstancedSpriteRenderer sprite2dRenderer)
 {
     _laser = laser;
     _beamId = beamId;
     _beamScene = beamScene;
     _occDiskScene = occDiskScene;
     _sprite2dRenderer = sprite2dRenderer;
 }
示例#30
0
 public LaserRuntimeInfo(SLaser laser, SSScene beamScene, SSScene occDiskScene, 
                         SSInstancedSpriteRenderer sprite2dRenderer)
 {
     _laser = laser;
     var numBeams = laser.parameters.numBeams;
     _beams = new BeamRuntimeInfo[numBeams];
     for (int i = 0; i < numBeams; ++i) {
         _beams[i] = new BeamRuntimeInfo(laser, i, beamScene, occDiskScene, sprite2dRenderer);
     }
 }
示例#31
0
        private void init(SSScene sunScene,
                          SSObjectBillboard sun,
                          SSTexture texture,
                          RectangleF[] spriteRects,
                          Vector2[] spriteScales)
        {
            base.textureMaterial = new SSTextureMaterial (texture);
            this.sunBillboard = sun;
            this.sunScene = sunScene;
            this.numElements = spriteRects.Length;
            if (spriteScales == null) {
                spriteScales = new Vector2[numElements];
                for (int i = 0; i < numElements; ++i) {
                    spriteScales [i] = new Vector2(1f);
                }
            } else {
                if (spriteScales.Length != numElements) {
                    throw new Exception ("texture coordinate array size does not match that of sprite scale array");
                    spriteScales = new Vector2[numElements];
                    for (int i = 0; i < numElements; ++i) {
                        spriteScales [i] = new Vector2(1f);
                    }
                }
            }
            this.spriteScales = spriteScales;

            UInt16[] indices = new UInt16[numElements*6];
            for (int i = 0; i < numElements; ++i) {
                int baseLoc = i * 6;
                int baseVal = i * 4;
                indices [baseLoc] = (UInt16)baseVal;
                indices [baseLoc + 1] = (UInt16)(baseVal + 2);
                indices [baseLoc + 2] = (UInt16)(baseVal + 1);
                indices [baseLoc + 3] = (UInt16)baseVal;
                indices [baseLoc + 4] = (UInt16)(baseVal + 3);
                indices [baseLoc + 5] = (UInt16)(baseVal + 2);
            }
            Mesh = new SSIndexedMesh<SSVertex_PosTex> (null, indices);

            vertices = new SSVertex_PosTex[numElements * 4];
            for (int r = 0; r < spriteRects.Length; ++r) {
                RectangleF rect = spriteRects [r];
                int baseIdx = r * 4;
                vertices [baseIdx]   = new SSVertex_PosTex (0f, 0f, 0f, rect.Left, rect.Bottom);
                vertices [baseIdx+1] = new SSVertex_PosTex (0f, 0f, 0f, rect.Right, rect.Bottom);
                vertices [baseIdx+2] = new SSVertex_PosTex (0f, 0f, 0f, rect.Right, rect.Top);
                vertices [baseIdx+3] = new SSVertex_PosTex (0f, 0f, 0f, rect.Left, rect.Top);
            }
        }
示例#32
0
 public SHudTargetsManager(SSScene main3dScene, SSScene hud2dScene)
 {
     _main3dScene = main3dScene;
     _hud2dScene = hud2dScene;
 }
示例#33
0
            public TargetSpecific(SSScene main3dScene, SSScene hud2dScene)
            {
                _targetObj3dScene = main3dScene;
                main3dScene.preRenderHooks += preRenderUpdate;

                _outline = new SSObjectMesh();
                _outline.renderState.lighted = false;
                _outline.renderState.alphaBlendingOn = true;
                _outline.renderState.frustumCulling = false;
                _outline.renderState.noShader = true;
                _outline.Name = "hud target outline";
                _outline.preRenderHook += (obj, rc) => {
                    GL.LineWidth(_targetIsInFront ? lineWidthWhenInFront : lineWidthWhenBehind);
                    GL.Disable(EnableCap.LineSmooth);
                };
                hud2dScene.AddObject(_outline);

                _labelBelow = new SSObjectGDISurface_Text();
                _labelBelow.renderState.alphaBlendingOn = true;
                _labelBelow.Name = "hud target label below";
                hud2dScene.AddObject(_labelBelow);

                _labelAbove = new SSObjectGDISurface_Text();
                _labelAbove.renderState.alphaBlendingOn = true;
                _labelAbove.Name = "hud target label above";
                hud2dScene.AddObject(_labelAbove);
            }
示例#34
0
 public SHudTargetsManager(SSScene main3dScene, SSScene hud2dScene)
 {
     _main3dScene = main3dScene;
     _hud2dScene  = hud2dScene;
 }