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 SLaserBurnParticlesObject(SSObject burningObject, int particleCapacity = 100, SSTexture texture = null) : base(new SLaserBurnParticleSystem (particleCapacity), SSTexturedQuad.doubleFaceInstance, _defaultUsageHint) { _burningObject = burningObject; if (_burningObject != null) { // do this now because render may never get called otherwise due to frustum culling // and world mat will never get updated and never rendered this.worldMat = _burningObject.worldMat; } renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; renderState.alphaBlendingOn = true; renderState.blendFactorSrcRGB = renderState.blendFactorSrcAlpha = BlendingFactorSrc.SrcAlpha; renderState.blendFactorDestRGB = renderState.blendFactorDestAlpha = BlendingFactorDest.One; // bypass frustum culling so camera updates are sent to activate particle emission renderState.frustumCulling = false; base.selectable = false; base.simulateOnUpdate = false; base.simulateOnRender = false; base.colorMaterial = SSColorMaterial.pureAmbient; base.textureMaterial = new SSTextureMaterial(null, null, texture, null); }
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; }
public SExplosionRenderManager(int particleCapacity = 500, SSTexture texture = null) : base(new SExplosionSystem(particleCapacity), SSTexturedQuad.DoubleFaceInstance, _defaultUsageHint ) { renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.alphaBlendingOn = true; //renderState.depthTest = true; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; simulateOnUpdate = true; Name = "simple expolsion renderer"; 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; var tex = texture ?? SExplosionSystem.getDefaultTexture(); textureMaterial = new SSTextureMaterial(null, null, tex, null); }
public SLaserBurnParticlesObject(int particleCapacity = 100, SSTexture texture = null) : base(new SLaserBurnParticleSystem (particleCapacity), SSTexturedQuad.DoubleFaceInstance, _defaultUsageHint) { renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; renderState.alphaBlendingOn = true; renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha; renderState.blendFactorDest = BlendingFactorDest.One; // bypass frustum culling so camera updates are sent to activate particle emission renderState.frustumCulling = false; base.selectable = false; base.simulateOnUpdate = true; 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.textureMaterial = new SSTextureMaterial(null, null, texture, null); }
public SExplosionRenderManager(int particleCapacity = 500, SSTexture texture = null) : base(new SExplosionSystem(particleCapacity), SSTexturedQuad.DoubleFaceInstance, _defaultUsageHint) { renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.alphaBlendingOn = true; //renderState.depthTest = true; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; simulateOnUpdate = true; Name = "simple expolsion renderer"; 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; var tex = texture ?? SExplosionSystem.getDefaultTexture(); textureMaterial = new SSTextureMaterial(null, null, tex, null); }
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); } }
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 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 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)); }
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)); }
public SSkyboxRenderer(SSTexture[] textures = null) { this.renderState.depthTest = true; this.renderState.depthWrite = false; this.renderState.lighted = false; this.renderState.frustumCulling = false; this.renderState.noShader = true; this.textures = new SSTexture[(int)Face.NumFaces]; for (int i = 0; i < (int)Face.NumFaces; ++i) { SSTexture tex = (textures != null) ? textures [i] : null; tex = tex ?? SSAssetManager.GetInstance<SSTexture>(defaultTextures [i]); this.textures [i] = tex; } }
public SSkyboxRenderer(SSTexture[] textures = null) { this.renderState.depthTest = true; this.renderState.lighted = false; this.renderState.frustumCulling = false; this.renderState.noShader = true; this.textures = new SSTexture[(int)Face.NumFaces]; for (int i = 0; i < (int)Face.NumFaces; ++i) { SSTexture tex = (textures != null) ? textures [i] : null; tex = tex ?? SSAssetManager.GetInstance <SSTexture>(defaultTextures [i]); this.textures [i] = tex; } }
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; }
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); }
public SLaserBurnParticlesObject(SSObject burningObject, int particleCapacity = 100, SSTexture texture = null) : base(new SLaserBurnParticleSystem(particleCapacity), SSTexturedQuad.DoubleFaceInstance, _defaultUsageHint) { _burningObject = burningObject; if (_burningObject != null) { // do this now because render may never get called otherwise due to frustum culling // and world mat will never get updated and never rendered this.worldMat = _burningObject.worldMat; } renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; renderState.alphaBlendingOn = true; renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha; renderState.blendFactorDest = BlendingFactorDest.One; // bypass frustum culling so camera updates are sent to activate particle emission renderState.frustumCulling = false; base.selectable = false; base.simulateOnUpdate = false; base.simulateOnRender = false; base.colorMaterial = SSColorMaterial.pureAmbient; base.textureMaterial = new SSTextureMaterial(null, null, texture, null); }
protected override void setupScene() { base.setupScene(); var mesh = SSAssetManager.GetInstance <SSMesh_wfOBJ> ("./drone2/", "Drone2.obj"); // add drone SSObject droneObj = new SSObjectMesh(mesh); scene.AddObject(droneObj); droneObj.renderState.lighted = true; droneObj.AmbientMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); droneObj.DiffuseMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); droneObj.SpecularMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); droneObj.EmissionMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); droneObj.ShininessMatColor = 10.0f; //droneObj.EulerDegAngleOrient(-40.0f,0.0f); droneObj.Pos = new OpenTK.Vector3(0, 0, -15f); droneObj.Name = "drone 1"; // add second drone SSObject drone2Obj = new SSObjectMesh( SSAssetManager.GetInstance <SSMesh_wfOBJ>("./drone2/", "Drone2.obj") ); scene.AddObject(drone2Obj); drone2Obj.renderState.lighted = true; drone2Obj.AmbientMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); drone2Obj.DiffuseMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); droneObj.SpecularMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); drone2Obj.EmissionMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); drone2Obj.ShininessMatColor = 10.0f; drone2Obj.EulerDegAngleOrient(-40f, 0f); drone2Obj.Pos = new OpenTK.Vector3(0f, 0f, 0f); drone2Obj.Name = "drone 2"; // 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); } // instanced asteroid ring //if (false) { var roidmesh = SSAssetManager.GetInstance <SSMesh_wfOBJ> ("simpleasteroid", "asteroid.obj"); var ringGen = new BodiesRingGenerator( 120f, 50f, Vector3.Zero, Vector3.UnitY, 250f, 0f, (float)Math.PI * 2f, 1f, 3f, 1f, 0.5f //10f, 30f, 1f, 20f ); var ringEmitter = new SSBodiesFieldEmitter(ringGen); ringEmitter.particlesPerEmission = 10000; //ringEmitter.ParticlesPerEmission = 10; var ps = new SSParticleSystem(10000); ps.addEmitter(ringEmitter); Console.WriteLine("Packing 10k asteroids into a ring. This may take a second..."); ps.emitAll(); asteroidRingRenderer = new SSInstancedMeshRenderer(ps, roidmesh, BufferUsageHint.StaticDraw); asteroidRingRenderer.simulateOnUpdate = false; asteroidRingRenderer.depthRead = true; asteroidRingRenderer.depthWrite = true; asteroidRingRenderer.Name = "instanced asteroid renderer"; asteroidRingRenderer.renderState.castsShadow = true; asteroidRingRenderer.renderState.receivesShadows = true; scene.AddObject(asteroidRingRenderer); } // particle system test // particle systems should be drawn last (if it requires alpha blending) //if (false) { // setup an emitter var box = new ParticlesSphereGenerator(new Vector3(0f, 0f, 0f), 10f); var emitter = new SSParticlesFieldEmitter(box); //emitter.EmissionDelay = 5f; emitter.particlesPerEmission = 1; emitter.emissionInterval = 0.5f; emitter.life = 1000f; emitter.colorOffsetComponentMin = new Color4(0.5f, 0.5f, 0.5f, 1f); emitter.colorOffsetComponentMax = new Color4(1f, 1f, 1f, 1f); emitter.velocityComponentMax = new Vector3(.3f); emitter.velocityComponentMin = new Vector3(-.3f); emitter.angularVelocityMin = new Vector3(-0.5f); emitter.angularVelocityMax = new Vector3(0.5f); emitter.dragMin = 0f; emitter.dragMax = .1f; RectangleF[] uvRects = new RectangleF[18 * 6]; float tileWidth = 1f / 18f; float tileHeight = 1f / 6f; for (int r = 0; r < 6; ++r) { for (int c = 0; c < 18; ++c) { uvRects [r * 18 + c] = new RectangleF(tileWidth * (float)r, tileHeight * (float)c, tileWidth, tileHeight); } } emitter.spriteRectangles = uvRects; var periodicExplosiveForce = new SSPeriodicExplosiveForceEffector(); periodicExplosiveForce.effectInterval = 3f; periodicExplosiveForce.explosiveForceMin = 1000f; periodicExplosiveForce.explosiveForceMax = 5000f; periodicExplosiveForce.effectDelay = 5f; periodicExplosiveForce.centerMin = new Vector3(-30f, -30f, -30f); periodicExplosiveForce.centerMax = new Vector3(30f, 30f, 30f); //periodicExplosiveForce.Center = new Vector3 (10f); // make a particle system SSParticleSystem cubesPs = new SSParticleSystem(1000); cubesPs.addEmitter(emitter); cubesPs.addEffector(periodicExplosiveForce); // test a renderer var tex = SSAssetManager.GetInstance <SSTextureWithAlpha>(".", "elements.png"); var cubesRenderer = new SSInstancedMeshRenderer(cubesPs, SSTexturedNormalCube.Instance); cubesRenderer.Pos = new Vector3(0f, 0f, -30f); cubesRenderer.alphaBlendingEnabled = false; cubesRenderer.depthRead = true; cubesRenderer.depthWrite = true; cubesRenderer.Name = "cube particle renderer"; cubesRenderer.renderState.castsShadow = true; cubesRenderer.renderState.receivesShadows = true; cubesRenderer.textureMaterial = new SSTextureMaterial(null, null, tex, null); scene.AddObject(cubesRenderer); //cubesRenderer.renderState.visible = false; // test explositons //if (false) { SimpleExplosionRenderer aer = new SimpleExplosionRenderer(100); aer.Pos = cubesRenderer.Pos; scene.AddObject(aer); periodicExplosiveForce.explosionEventHandlers += (pos, force) => { aer.showExplosion(pos, force / periodicExplosiveForce.explosiveForceMin * 1.5f); }; } } }
public SLaserBurnParticlesObject(SSObject burningObject, int particleCapacity = 100, SSTexture texture = null) : base(new SLaserBurnParticleSystem(particleCapacity), SSTexturedQuad.DoubleFaceInstance, _defaultUsageHint) { _burningObject = burningObject; renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; renderState.alphaBlendingOn = true; renderState.blendFactorSrc = BlendingFactorSrc.SrcAlpha; renderState.blendFactorDest = BlendingFactorDest.One; // bypass frustum culling so camera updates are sent to activate particle emission renderState.frustumCulling = false; base.selectable = false; base.simulateOnUpdate = false; base.simulateOnRender = 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.textureMaterial = new SSTextureMaterial(null, null, texture, null); }
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); } }
protected override void setupScene() { base.setupScene(); // checkerboard floor #if true { SSTexture tex = SSAssetManager.GetInstance <SSTexture> (".", "checkerboard.png"); const float tileSz = 4f; const int gridSz = 10; var tileVertices = new SSVertex_PosNormTex[SSTexturedNormalQuad.c_doubleFaceVertices.Length]; SSTexturedNormalQuad.c_doubleFaceVertices.CopyTo(tileVertices, 0); for (int v = 0; v < tileVertices.Length; ++v) { tileVertices[v].TexCoord *= (float)gridSz; } var quadMesh = new SSVertexMesh <SSVertex_PosNormTex>(tileVertices); quadMesh.textureMaterial = new SSTextureMaterial(tex); var tileObj = new SSObjectMesh(quadMesh); tileObj.Name = "Tiles"; tileObj.selectable = false; tileObj.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, (float)Math.PI / 2f)); tileObj.Scale = new Vector3(tileSz * gridSz); //tileObj.boundingSphere = new SSObjectSphere(0f); main3dScene.AddObject(tileObj); } #endif // skeleton mesh test #if true { SSSkeletalAnimation animIdle = SSAssetManager.GetInstance <SSSkeletalAnimationMD5>("./boneman", "boneman_idle.md5anim"); SSSkeletalAnimation animRunning = SSAssetManager.GetInstance <SSSkeletalAnimationMD5>("./boneman", "boneman_running.md5anim"); SSSkeletalAnimation animAttack = SSAssetManager.GetInstance <SSSkeletalAnimationMD5>("./boneman", "boneman_attack.md5anim"); SSSkeletalMesh[] meshes = SSAssetManager.GetInstance <SSSkeletalMeshMD5[]>("./boneman", "boneman.md5mesh"); var tex = SSAssetManager.GetInstance <SSTexture>("./boneman", "skin.png"); foreach (var skeliMesh in meshes) { #if true var renderMesh0 = new SSSkeletalRenderMesh(skeliMesh); var obj0 = new SSObjectMesh(renderMesh0); obj0.MainColor = Color4.DarkGray; obj0.Name = "grey bones (bind pose)"; obj0.Pos = new Vector3(-18f, 0f, -18f); obj0.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); main3dScene.AddObject(obj0); tracker0 = new SSSimpleObjectTrackingJoint(obj0); tracker0.jointPositionLocal = animIdle.computeJointFrame(11, 0).position; tracker0.neutralViewOrientationLocal = animIdle.computeJointFrame(11, 0).orientation; tracker0.neutralViewDirectionBindPose = Vector3.UnitY; tracker0.neutralViewUpBindPose = Vector3.UnitZ; renderMesh0.addCustomizedJoint(11, tracker0); #endif #if true var renderMesh1 = new SSSkeletalRenderMesh(skeliMesh); var obj1 = new SSObjectMesh(renderMesh1); obj1.MainColor = Color4.DarkRed; obj1.Name = "red bones (running loop)"; obj1.Pos = new Vector3(6f, 0f, -12f); obj1.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); main3dScene.AddObject(obj1); renderMesh1.playAnimationLoop(animRunning, 0f); #endif #if true var renderMesh2 = new SSSkeletalRenderMesh(skeliMesh); renderMesh2.playAnimationLoop(animIdle, 0f, "all"); renderMesh2.playAnimationLoop(animRunning, 0f, "LeftClavicle", "RightClavicle"); var obj2 = new SSObjectMesh(renderMesh2); obj2.MainColor = Color.Green; obj2.Name = "green bones (idle + running loop mixed)"; obj2.Pos = new Vector3(0f, 0f, -12f); obj2.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); main3dScene.AddObject(obj2); #endif #if true var renderMesh3 = new SSSkeletalRenderMesh(skeliMesh); renderMesh3.playAnimationLoop(animIdle, 0f, "all"); var obj3 = new SSObjectMesh(renderMesh3); obj3.MainColor = Color.DarkCyan; obj3.Name = "blue bones (idle loop)"; obj3.Pos = new Vector3(-6f, 0f, -12f); obj3.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); main3dScene.AddObject(obj3); #endif // state machines setup for skeletal render mesh 4 and 5 var skeletonWalkDescr = new SSAnimationStateMachine(); skeletonWalkDescr.addState("idle", animIdle, true); skeletonWalkDescr.addState("running1", animRunning); skeletonWalkDescr.addState("running2", animRunning); skeletonWalkDescr.addAnimationEndsTransition("idle", "running1", 0.3f); skeletonWalkDescr.addAnimationEndsTransition("running1", "running2", 0f); skeletonWalkDescr.addAnimationEndsTransition("running2", "idle", 0.3f); var skeletonAttackDescr = new SSAnimationStateMachine(); skeletonAttackDescr.addState("inactive", null, true); skeletonAttackDescr.addState("attack", animAttack); skeletonAttackDescr.addStateTransition(null, "attack", 0.5f); skeletonAttackDescr.addAnimationEndsTransition("attack", "inactive", 0.5f); #if true // state machine test (in slow motion) var renderMesh4 = new SSSkeletalRenderMesh(skeliMesh); renderMesh4.timeScale = 0.25f; var obj4 = new SSObjectMesh(renderMesh4); obj4.MainColor = Color.DarkMagenta; obj4.Name = "magenta bones (looping idle/walk; interactive attack; slowmo)"; obj4.Pos = new Vector3(-12f, 0f, 0f); obj4.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); main3dScene.AddObject(obj4); var renderMesh4WallSm = renderMesh4.addStateMachine(skeletonWalkDescr, "all"); renderMesh4AttackSm = renderMesh4.addStateMachine(skeletonAttackDescr, "LeftClavicle", "RightClavicle"); tracker4 = new SSSimpleObjectTrackingJoint(obj4); tracker4.jointPositionLocal = animRunning.computeJointFrame(11, 0).position; tracker4.neutralViewOrientationLocal = animRunning.computeJointFrame(11, 0).orientation; tracker4.neutralViewDirectionBindPose = Vector3.UnitY; renderMesh4.addCustomizedJoint(11, tracker4); #endif #if true // another mesh, using the same state machine but running at normal speed var renderMesh5 = new SSSkeletalRenderMesh(skeliMesh); var renderMesh5WalkSm = renderMesh5.addStateMachine(skeletonWalkDescr, "all"); renderMesh5AttackSm = renderMesh5.addStateMachine(skeletonAttackDescr, "LeftClavicle", "RightClavicle"); var obj5 = new SSObjectMesh(renderMesh5); obj5.Name = "orange bones (looping idle/walk, interactive attack + parametric neck rotation)"; obj5.Pos = new Vector3(12f, 0f, 0f); obj5.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); obj5.MainColor = Color4.DarkOrange; main3dScene.AddObject(obj5); renderMesh5NeckJoint = new SSPolarJoint(); renderMesh5NeckJoint.positionOffset = new Vector3(0f, 0.75f, 0f); renderMesh5.addCustomizedJoint("UpperNek", renderMesh5NeckJoint); #endif } } #endif #if true // bob mesh test { var bobMeshes = SSAssetManager.GetInstance <SSSkeletalMeshMD5[]>( "./bob_lamp/", "bob_lamp_update.md5mesh"); var bobAnim = SSAssetManager.GetInstance <SSSkeletalAnimationMD5>( "./bob_lamp/", "bob_lamp_update.md5anim"); var bobRender = new SSSkeletalRenderMesh(bobMeshes); bobRender.playAnimationLoop(bobAnim, 0f); bobRender.alphaBlendingEnabled = true; bobRender.timeScale = 0.5f; var bobObj = new SSObjectMesh(bobRender); bobObj.Name = "Bob"; bobObj.Pos = new Vector3(10f, 0f, 10f); bobObj.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2f)); alpha3dScene.AddObject(bobObj); } #endif }
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); } }