public override void Act(KeyboardState ks, MouseState ms) { if (ks[Key.Escape]) { CurrentWindow.SetWorld(new GameWorldStart()); return; } if (ks[Key.Left]) { _alpha = HelperGeneral.Clamp(_alpha - 0.0000001f * KWEngine.DeltaTimeFactor, 0.0f, 1f); Console.WriteLine("Alpha: " + _alpha); _sunLightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Right]) { _alpha = HelperGeneral.Clamp(_alpha + 0.0000001f * KWEngine.DeltaTimeFactor, 0.0f, 1f); Console.WriteLine("Alpha: " + _alpha); _sunLightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Up]) { _hardness = HelperGeneral.Clamp(_hardness + 0.001f * KWEngine.DeltaTimeFactor, -0.5f, 0.5f); Console.WriteLine("Hardness: " + _hardness); _sunLightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Down]) { _hardness = HelperGeneral.Clamp(_hardness - 0.001f * KWEngine.DeltaTimeFactor, -0.5f, 0.5f); Console.WriteLine("Hardness: " + _hardness); _sunLightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } }
public override void Prepare() { //KWEngine.LoadModelFromFile("ddstest", @".\models\placeholdertest.gltf"); KWEngine.LoadModelFromFile("MatTest", @".\models\gltftestcube.glb"); KWEngine.LoadModelFromFile("MatTest255", @".\models\gltftestcube255.glb"); KWEngine.LoadModelFromFile("EmissionTest", @".\models\emission_gltf_test.glb"); FOV = 45; SetAmbientLight(1, 1, 1, 0.2f); SetCameraPosition(0, 10, 0); SetCameraTarget(0, 0, 0); SetTextureSkybox(@".\textures\skybox1.dds"); //SetTextureBackground(@".\textures\bg_greenmountains.png"); SetTextureBackgroundBrightnessMultiplier(5f); CreateMetalSphereTestObject(); CreateCubeTestObject(); CreateGLBTestObject(); CreateTerrainTestObject(); //CreateRoomForLightTest(); CreateFreeFloatPlayer(); LightObject sun = new LightObject(LightType.Sun, true); sun.SetPosition(30, 30, 30); sun.SetFOVBiasCoefficient(0.02f); sun.SetColor(1, 1, 1, 3); AddLightObject(sun); DebugShowPerformanceInTitle = PerformanceUnit.FramesPerSecond; //DebugShadowLight = sun; DebugShowCoordinateSystemGrid = GridType.GridXZ; }
public override void Prepare() { FOV = 90; KWEngine.LoadModelFromFile("ArenaOuter", @".\Models\ArenaOuter\ArenaOuter.fbx"); KWEngine.LoadModelFromFile("ArenaPlatform", @".\Models\ArenaOuter\ArenaPlatform.obj"); KWEngine.LoadModelFromFile("ArenaPlatforms", @".\Models\ArenaOuter\ArenaPlatforms.fbx"); KWEngine.LoadModelFromFile("AK47", @".\models\ak47.obj"); KWEngine.BuildTerrainModel("Arena", @".\textures\heightmapArena.png", @".\textures\sand_diffuse.dds", 150, 10, 150, 7.5f, 7.5f); Immovable terra = new Immovable(); terra.SetModel("Arena"); terra.SetPosition(0, -0.5f, 0); terra.IsShadowCaster = true; terra.SetTexture(@".\textures\sand_normal.dds", TextureType.Normal); AddGameObject(terra); Immovable floor = new Immovable(); floor.SetModel("KWCube"); floor.SetScale(80, 5, 80); floor.SetPosition(0, -2.5f, 0); floor.SetTextureRepeat(5, 5); floor.IsCollisionObject = true; floor.IsShadowCaster = true; floor.SetTexture(@".\textures\sand_diffuse.dds"); floor.SetTexture(@".\textures\sand_normal.dds", TextureType.Normal); AddGameObject(floor); Immovable arenaOuter = new Immovable(); arenaOuter.SetModel("ArenaOuter"); arenaOuter.IsCollisionObject = true; arenaOuter.IsShadowCaster = true; AddGameObject(arenaOuter); Immovable arenaPlatforms = new Immovable(); arenaPlatforms.SetModel("ArenaPlatforms"); arenaPlatforms.IsCollisionObject = true; arenaPlatforms.IsShadowCaster = true; AddGameObject(arenaPlatforms); PlatformUpDown testPlatform = new PlatformUpDown(); testPlatform.SetModel("ArenaPlatform"); testPlatform.SetScale(1.5f); testPlatform.SetMetalness(1); testPlatform.SetRoughness(0.5f); testPlatform.SetPosition(15, 1.5f, 0); testPlatform.IsCollisionObject = true; testPlatform.IsShadowCaster = true; AddGameObject(testPlatform); _player = new Player(); _player.SetModel("KWCube"); _player.SetScale(1, 2, 1); _player.IsShadowCaster = false; _player.IsCollisionObject = true; _player.SetPosition(25, 1f, 25); _player.FPSEyeOffset = 0.75f; _player.UpdateLast = true; AddGameObject(_player); SetFirstPersonObject(_player, 230); SetFirstPersonObjectItemModel("AK47", true, true); SetFirstPersonObjectItemModelViewOffset(0.5f, -1, 0); SetTextureSkybox(@".\textures\skybox1.dds"); DebugShowPerformanceInTitle = PerformanceUnit.FramesPerSecond; _sunLightWithShadow = new LightObject(LightType.Sun, true); _sunLightWithShadow.SetPosition(200, 200, 50); _sunLightWithShadow.SetTarget(25, 25, 0); _sunLightWithShadow.SetColor(1, 0.75f, 0.5f, 2.5f); _sunLightWithShadow.SetNearAndFarBounds(100, 400); _sunLightWithShadow.SetFOV(125); _sunLightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); AddLightObject(_sunLightWithShadow); //DebugShadowLight = _sunLightWithShadow; SetAmbientLight(1, 0.75f, 0.5f, 0.3f); SetTextureBackgroundBrightnessMultiplier(4); }
public override void Act(KeyboardState ks, MouseState ms) { if (ks[Key.Escape]) { CurrentWindow.SetWorld(new GameWorldStart()); return; } if (ks[Key.Left]) { _alpha = HelperGeneral.Clamp(_alpha - 0.000001f * KWEngine.DeltaTimeFactor, 0.0000001f, 1f); Console.WriteLine("Alpha: " + _alpha); _sunlightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Right]) { _alpha = HelperGeneral.Clamp(_alpha + 0.000001f * KWEngine.DeltaTimeFactor, 0.0000001f, 1f); Console.WriteLine("Alpha: " + _alpha); _sunlightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Up]) { _hardness = HelperGeneral.Clamp(_hardness + 0.001f * KWEngine.DeltaTimeFactor, -0.5f, 0.5f); Console.WriteLine("Hardness: " + _hardness); _sunlightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.Down]) { _hardness = HelperGeneral.Clamp(_hardness - 0.001f * KWEngine.DeltaTimeFactor, -0.5f, 0.5f); Console.WriteLine("Hardness: " + _hardness); _sunlightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); } if (ks[Key.H]) { _zNear = HelperGeneral.Clamp(_zNear + 0.5f * KWEngine.DeltaTimeFactor, 0.01f, 1000); Console.WriteLine("z-Near: " + _zNear); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } if (ks[Key.G]) { _zNear = HelperGeneral.Clamp(_zNear - 0.5f * KWEngine.DeltaTimeFactor, 0.01f, 1000); Console.WriteLine("z-Near: " + _zNear); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } if (ks[Key.N]) { _zFar = HelperGeneral.Clamp(_zFar + 0.5f * KWEngine.DeltaTimeFactor, 0.01f, 1000); Console.WriteLine("z-Far: " + _zFar); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } if (ks[Key.B]) { _zFar = HelperGeneral.Clamp(_zFar - 0.5f * KWEngine.DeltaTimeFactor, 0.01f, 1000); Console.WriteLine("z-Far: " + _zFar); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } long currentTimeStamp = GetCurrentTimeInMilliseconds(); if (ks[Key.Number1] && (currentTimeStamp - _timestampLast) > COOLDOWN) { RemoveLightObject(_sunlightWithShadow); _zNear = 0.01f; _zFar = 50.0f; _sunlightWithShadow = new LightObject(LightType.Sun, true); _sunlightWithShadow.SetPosition(sunX, 10, 15f); _sunlightWithShadow.SetTarget(0, 5, 0); _sunlightWithShadow.SetFOV(35); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); _sunlightWithShadow.SetColor(1, 1, 1, 2); AddLightObject(_sunlightWithShadow); _timestampLast = currentTimeStamp; zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } if (ks[Key.Number2] && (currentTimeStamp - _timestampLast) > COOLDOWN) { RemoveLightObject(_sunlightWithShadow); _zNear = 0.01f; _zFar = 50f; _sunlightWithShadow = new LightObject(LightType.Directional, true); _sunlightWithShadow.SetPosition(sunX, 10f, 15f); _sunlightWithShadow.SetTarget(0, 5, 0); _sunlightWithShadow.SetFOV(180); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); _sunlightWithShadow.SetColor(1, 1, 1, 2); AddLightObject(_sunlightWithShadow); _timestampLast = currentTimeStamp; zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); } }
private void CreateRoomForLightTest() { SetAmbientLight(1, 1, 1, 0.25f); Cube e1 = new Cube(); e1.SetModel("KWCube"); e1.SetPosition(0, 2, 0); e1.IsShadowCaster = true; AddGameObject(e1); Cube c1 = new Cube(); c1.Name = "BACK WALL"; c1.SetModel("KWCube"); c1.SetScale(20, 10, 2); c1.SetPosition(0, 5, -11); c1.IsShadowCaster = true; c1.SetTexture(@".\textures\pavement01.jpg"); AddGameObject(c1); Cube c2 = new Cube(); c2.Name = "FLOOR"; c2.SetModel("KWCube"); c2.SetScale(20, 2, 20); c2.SetPosition(0, -1, 0); c2.SetTexture(@".\textures\pavement01.jpg"); c2.IsShadowCaster = true; AddGameObject(c2); Cube c3 = new Cube(); c3.SetModel("KWCube"); c3.SetScale(2, 10, 20); c3.SetPosition(-11, 5, 0); c3.SetTexture(@".\textures\pavement01.jpg"); c3.IsShadowCaster = true; AddGameObject(c3); Cube c4 = new Cube(); c4.SetModel("KWCube"); c4.SetScale(2, 10, 20); c4.SetPosition(+11, 5, 0); c4.IsShadowCaster = true; c4.SetTexture(@".\textures\pavement01.jpg"); AddGameObject(c4); // Testing Cubes and Spheres Cube box1 = new Cube(); box1.SetModel("KWCube"); box1.SetPosition(-5, 0.5f, 2f); box1.SetScale(1); box1.IsShadowCaster = true; AddGameObject(box1); Cube box2 = new Cube(); box2.SetModel("KWCube"); box2.SetPosition(0, 0.5f, -5.5f); box2.SetScale(1); box2.SetColor(1, 0, 0); box2.IsShadowCaster = true; //box2.SetMetalness(0.9f); box2.Opacity = 1; AddGameObject(box2); Cube box3 = new Cube(); box3.SetModel("KWCube"); box3.SetPosition(5, 0.5f, -8f); box3.SetScale(1); box3.SetColor(0, 1, 0); box3.IsShadowCaster = true; AddGameObject(box3); _sunlightWithShadow = new LightObject(LightType.Directional, true); _sunlightWithShadow.SetPosition(sunX, 10, 15f); _sunlightWithShadow.SetTarget(0, 5, 0); //_sunlightWithShadow.SetFOV(35); _sunlightWithShadow.SetFOV(180); _sunlightWithShadow.SetNearAndFarBounds(_zNear, _zFar); _sunlightWithShadow.SetColor(1, 1, 1, 2); _sunlightWithShadow.SetFOVBiasCoefficient(_alpha, _hardness); AddLightObject(_sunlightWithShadow); DebugShowPerformanceInTitle = PerformanceUnit.FramesPerSecond; //DebugShadowLight = _sunlightWithShadow; zNearFar.SetText("near: " + Math.Round(_zNear, 1) + " | far: " + Math.Round(_zFar, 1)); AddHUDObject(zNearFar); }
private void CreateRoomForLightTest() { SetAmbientLight(1, 1, 1, 0.25f); KWEngine.BuildTerrainModel("Terrain", @".\textures\heightmap2.png", @".\textures\sand_diffuse.dds", 20, 2, 20, 5, 5); Cube e1 = new Cube(); e1.SetModel("KWCube"); e1.SetPosition(0, 2, 0); e1.IsShadowCaster = true; AddGameObject(e1); Cube c1 = new Cube(); c1.SetModel("KWCube"); c1.SetScale(20, 10, 2); c1.SetPosition(0, 5, -11); c1.IsShadowCaster = true; c1.SetTexture(@".\textures\pavement01.jpg"); AddGameObject(c1); /* * Cube c2 = new Cube(); * c2.SetModel("KWCube"); * c2.SetScale(20, 2, 20); * c2.SetPosition(0, -1, 0); * c2.SetTexture(@".\textures\pavement01.jpg"); * c2.IsShadowCaster = true; * AddGameObject(c2); */ Cube c2 = new Cube(); c2.SetModel("Terrain"); c2.SetPosition(0, 0, 0); c2.IsShadowCaster = true; AddGameObject(c2); Cube c3 = new Cube(); c3.SetModel("KWCube"); c3.SetScale(2, 10, 20); c3.SetPosition(-11, 5, 0); c3.SetTexture(@".\textures\pavement01.jpg"); c3.IsShadowCaster = true; AddGameObject(c3); Cube c4 = new Cube(); c4.SetModel("KWCube"); c4.SetScale(2, 10, 20); c4.SetPosition(+11, 5, 0); c4.IsShadowCaster = true; c4.SetTexture(@".\textures\pavement01.jpg"); AddGameObject(c4); // Testing Cubes and Spheres Cube box1 = new Cube(); box1.SetModel("KWCube"); box1.SetPosition(-5, 1, 0); box1.SetScale(2); box1.IsShadowCaster = true; AddGameObject(box1); Cube box2 = new Cube(); box2.SetModel("KWCube"); box2.SetPosition(0, 0.5f, -3); box2.SetScale(1); box2.IsShadowCaster = true; //box2.SetMetalness(0.9f); box2.Opacity = 1; AddGameObject(box2); Cube box3 = new Cube(); box3.SetModel("KWCube"); box3.SetPosition(0, 3, -7.5f); box3.SetScale(3); box3.IsShadowCaster = true; AddGameObject(box3); _pointlightWithShadow = new LightObject(LightType.Point, true); _pointlightWithShadow.SetPosition(0, 5, 0); _pointlightWithShadow.SetNearAndFarBounds(1, 15); _pointlightWithShadow.SetColor(1, 0, 0, 2); _pointlightWithShadow.SetFOVBiasCoefficient(_momentBias, _depthBias); AddLightObject(_pointlightWithShadow); }
public override void Prepare() { KWEngine.LoadModelFromFile("UBot", @".\Models\JumpAndRun\UBot.fbx"); SetTextureSkybox(@".\Textures\skybox3.dds"); SetTextureBackgroundBrightnessMultiplier(4); SetAmbientLight(1, 1, 1, 0.25f); WorldDistance = 50; // Player object: _player = new Player(); _player.SetModel("UBot"); _player.SetScale(1.8f); _player.SetRotation(0, 180, 0); _player.SetMetalness(0.25f); _player.Name = "Player"; //_player.SetRoughness(1); _player.SetPosition(0, 0, 0); _player.IsCollisionObject = true; _player.IsShadowCaster = true; _player.UpdateLast = true; AddGameObject(_player); Platform floor = new Platform(); floor.SetModel("KWCube"); floor.SetTexture(@".\textures\mpanel_diffuse.dds"); floor.SetTexture(@".\textures\mpanel_normal.dds", TextureType.Normal); //floor.SetTexture(@".\textures\mpanel_roughness.dds", TextureType.Roughness); //floor.SetTexture(@".\textures\mpanel_metalness.dds", TextureType.Metalness); floor.SetRoughness(0.25f); floor.SetMetalness(0.1f); floor.SetTextureRepeat(5, 5); floor.IsCollisionObject = true; floor.SetPosition(0, -1f, 0); floor.SetScale(50, 2, 50); floor.Name = "Floor"; floor.IsShadowCaster = true; AddGameObject(floor); _sun = new LightObject(LightType.Sun, true); _sun.SetPosition(-200, 100, 50); _sun.SetTarget(0, 0, 0); _sun.SetFOV(45); _sun.SetNearAndFarBounds(200, 350); _sun.SetColor(1, 1, 1, 4); _sun.SetFOVBiasCoefficient(0.00003f, 0f); AddLightObject(_sun); //DebugShadowLight = _sun; SetCameraPosition(0, 0, 10); SetCameraTarget(0, 0, 0); FOV = 90; CurrentWindow.CursorVisible = false; CurrentWindow.CursorGrabbed = true; // Place some obstacles: Immovable i1 = new Immovable(); i1.SetModel("KWCube"); i1.SetPosition(2.5f, 1f, -5); i1.SetScale(2); i1.IsPickable = true; i1.Name = "Obstacle Box #1"; i1.SetRoughness(0.5f); i1.SetColor(1, 0.25f, 0.25f); i1.SetTexture(@".\textures\MetalPlates006_1K_ColorBright.jpg"); //i1.SetSpecularReflectionEnabled(true); i1.IsShadowCaster = true; i1.IsCollisionObject = true; AddGameObject(i1); // Place HUD crosshair: _crosshair = new HUDObject(HUDObjectType.Image, CurrentWindow.Width / 2, CurrentWindow.Height / 2); _crosshair.SetTexture(@".\textures\crosshair.dds"); _crosshair.SetScale(64, 64); AddHUDObject(_crosshair); DebugShowPerformanceInTitle = PerformanceUnit.FramesPerSecond; }