public DeckObject GetPointedObject() { Point point = DeckProgram.MainForm.PointToClient(Cursor.Position); int nodeRenderId = Horde3DUtils.pickNode(CameraHid, point.X / ((float)DeckProgram.MainForm.ClientRectangle.Width), 1 - point.Y / ((float)DeckProgram.MainForm.ClientRectangle.Height)); if (nodeRenderId == 0) { return(null); } int nodeParentRenderId = nodeRenderId; while (nodeParentRenderId != h3d.H3DRootNode) { nodeRenderId = nodeParentRenderId; nodeParentRenderId = h3d.getNodeParent(nodeParentRenderId); } if (this.m_hordeIdObjectIdDictionary.ContainsKey(nodeRenderId)) { Guid objectId = m_hordeIdObjectIdDictionary[nodeRenderId]; if (DeckProgram.DeckScene.ContainsObject(objectId)) { return(DeckProgram.DeckScene.GetObject(objectId)); } } return(null); }
/// <summary> /// All application initialization is performed here, before the main loop thread is executed and the render panel is displayed for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderForm_Load(object sender, EventArgs e) { LogUtil.Info("MainForm startup begin."); try { //renderPanel.MakeCurrent(); if (!Horde3DUtils.initOpenGL(GetDC(renderPanel.Handle).ToInt32())) { throw new Exception("Failed to initialize OpenGL"); } if (!DeckProgram.DeckRenderer.Startup()) { MessageBox.Show( "Failed to init application.\nMake sure you have an OpenGL 2.0 compatible graphics card with the latest drivers installed!\nAlso verify if the pipeline config file exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); h3d.release(); Environment.Exit(0); } LogUtil.Debug("Initial panel size: " + renderPanel.ClientSize.Width + "," + renderPanel.ClientSize.Height); //ResizeChildren(); } catch (Exception ex) { LogUtil.Error("Error in MainForm initialization: " + ex.ToString()); } LogUtil.Info("MainForm startup end."); }
public void init() { // Init random generator _rand = new Random((int)DateTime.Now.Ticks); // Load character with walk animation int characterRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "man.scene.xml", 0); int characterWalkRes = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "man.anim", 0); Horde3DUtils.loadResourcesFromDisk("content"); // Add characters for (int i = 0; i < 100; ++i) { Particle p = new Particle(); // Add character to scene and apply animation p.node = Horde3D.addNodes(Horde3D.RootNode, characterRes); Horde3D.setupModelAnimStage(p.node, 0, characterWalkRes, string.Empty, false); // Characters start in a circle formation p.px = (float)Math.Sin((i / 100.0f) * 6.28f) * 20.0f; p.pz = (float)Math.Cos((i / 100.0f) * 6.28f) * 20.0f; chooseDestination(ref p); Horde3D.setNodeTransform(p.node, p.px, 0.02f, p.pz, 0, 0, 0, 1, 1, 1); _particles.Add(p); } }
/// <summary> /// Release the engine and free all objects as well as associated memory, after the form is closed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderForm_FormClosed(object sender, FormClosedEventArgs e) { // stop stop watch process stopWatch.Stop(); // release h3d app.release(); Horde3DUtils.releaseOpenGL(); Environment.Exit(0); }
public void Process() { CurrentFramesPerSecond = DeckProgram.MainForm.FramesPerSecond; m_timer += 1 / CurrentFramesPerSecond; h3d.setOption(h3d.H3DOptions.DebugViewMode, IsDebugViewMode ? 1.0f : 0.0f); h3d.setOption(h3d.H3DOptions.WireframeMode, IsWireframeMode ? 1.0f : 0.0f); if (!IsFreeze) { m_animationTime += 1.0f / CurrentFramesPerSecond; m_demo.Process(m_animationTime, AnimationBlendingWeight, CurrentFramesPerSecond); } Matrix cameraTranslationMatrix = Matrix.CreateTranslation(DeckProgram.DeckRudder.CameraLocation.X, DeckProgram.DeckRudder.CameraLocation.Y, DeckProgram.DeckRudder.CameraLocation.Z); Matrix cameraTransformationMatrix = Matrix.Multiply(DeckProgram.DeckRudder.CameraOrientationMatrix, cameraTranslationMatrix); h3d.setNodeTransMat(CameraHid, cameraTransformationMatrix.ToArray(MatrixElementOrder.RowMajor)); Matrix lightTranslationMatrix = Matrix.CreateTranslation(DeckProgram.DeckRudder.FlashlightLocation.X, DeckProgram.DeckRudder.FlashlightLocation.Y, DeckProgram.DeckRudder.FlashlightLocation.Z); Matrix lightTransformationMatrix = Matrix.Multiply(DeckProgram.DeckRudder.FlashlightOrientationMatrix, lightTranslationMatrix); h3d.setNodeTransMat(LightHid, lightTransformationMatrix.ToArray(MatrixElementOrder.RowMajor)); // Set camera parameters //h3d.setNodeTransform(CameraHid, DeckProgram.DeckRudder.CX, DeckProgram.DeckRudder.CY, DeckProgram.DeckRudder.CZ // , DeckProgram.DeckRudder.RX, DeckProgram.DeckRudder.RY, 0, 1, 1, 1); //horde3d 1.0 if (StatisticsMode > 0) { Horde3DUtils.showFrameStats(m_fontMaterialHid, m_panelMaterialHid, StatisticsMode); string text = string.Format("Weight: {0:F2}", AnimationBlendingWeight); Horde3DUtils.showText(text, 0.03f, 0.24f, 0.026f, 1, 1, 1, m_fontMaterialHid, 5); } // Show logo /*h3d.showOverlay( 0.75f, 0.8f, 0, 1, 0.75f, 1, 0, 0, * 1, 1, 1, 0, 1, 0.8f, 1, 1, * 1, 1, 1, 1, m_logoMaterialHid, 7 ); */ // Render scene h3d.render(CameraHid); //horde3D 1.0 h3d.finalizeFrame(); //horde3D 1.0 h3d.clearOverlays(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1 / fps; Horde3D.setOption(Horde3D.EngineOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); if (!_freeze) { _animTime += 1.0f / _curFPS; // Do animation blending Horde3D.setModelAnimParams(_knight, 0, _animTime * 24.0f, _weight); Horde3D.setModelAnimParams(_knight, 1, _animTime * 24.0f, 1.0f - _weight); // Animate particle system Horde3D.advanceEmitterTime(_particleSys, 1.0f / _curFPS); } // Set camera parameters Horde3D.setNodeTransform(Horde3D.PrimeTimeCam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); if (_showFPS) { // Avoid updating FPS text every frame to make it readable if (_timer > 0.3f) { _fpsText = string.Format("FPS: {0:F2}", fps); _timer = 0; } // Show text if (_fpsText != null) { Horde3DUtils.showText(_fpsText, 0, 0.95f, 0.03f, 0, _fontMatRes); } string text = string.Format("Weight: {0:F2}", _weight); Horde3DUtils.showText(text, 0, 0.91f, 0.03f, 0, _fontMatRes); } // Show logo Horde3D.showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0, 1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1, 7, _logoMatRes); // Render scene Horde3D.render(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1f / fps; h3d.setOption(h3d.H3DOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); h3d.setOption(h3d.H3DOptions.WireframeMode, _wireframeMode ? 1.0f : 0.0f); if (!_freeze) { _animTime += 1.0f / _curFPS; // Do animation blending h3d.setModelAnimParams(_knight, 0, _animTime * 24.0f, _weight); h3d.setModelAnimParams(_knight, 1, _animTime * 24.0f, 1.0f - _weight); h3d.updateModel(_knight, (int)(h3d.H3DModelUpdateFlags.Animation | h3d.H3DModelUpdateFlags.Geometry)); // Animate particle system int cnt = cnt = h3d.findNodes(_particleSys, "", (int)h3d.H3DNodeTypes.Emitter); for (int i = 0; i < cnt; ++i) { h3d.updateEmitter(h3d.getNodeFindResult(i), 1.0f / _curFPS); } } // Set camera parameters h3d.setNodeTransform(_cam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); //horde3d 1.0 if (_statMode > 0) { Horde3DUtils.showFrameStats(_fontMatRes, _panelMatRes, _statMode); string text = string.Format("Weight: {0:F2}", _weight); Horde3DUtils.showText(text, 0.03f, 0.24f, 0.026f, 1, 1, 1, _fontMatRes); } // Show logo float ww = h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportWidthI) / (float)h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportHeightI); float[] ovLogo = new float[] { ww - 0.4f, 0.8f, 0, 1, ww - 0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3d.showOverlays(ovLogo, 4, 1, 1, 1, 1, _logoMatRes, 0); // Render scene h3d.render(_cam); //horde3D 1.0 h3d.finalizeFrame(); //horde3D 1.0 h3d.clearOverlays(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
/// <summary> /// The main loop. This method is executed by the application event handler each time the application is idle. /// </summary> public void MainLoop() { KeyHandling(); MouseMovement(); CalcFPS(); // render app.mainLoop(fps); Horde3DUtils.swapBuffers(); // if mouse tracking is disabled call Invalidate() to redraw the scene Invalidate(); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1f / fps; h3d.setOption(h3d.H3DOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); h3d.setOption(h3d.H3DOptions.WireframeMode, _wireframeMode ? 1.0f : 0.0f); if (!_freeze) { // Set animation time h3d.setMaterialUniform(_computeMatRes, "deltaTime", 1.0f / 30.0F, 0, 0, 0); // Set attractor point float angle = (float)_timer * 0.5f; float attractorX = (float)Math.Cos(angle); float attractorY = (float)Math.Cos(angle) * (float)Math.Sin(angle); float attractorZ = (float)Math.Sin(angle); h3d.setMaterialUniform(_computeMatRes, "attractor", attractorX * 2, attractorY * 2, attractorZ * 2, 0); // Perform computing h3d.compute(_computeMatRes, "COMPUTE", _computeGroupX /*1024*/, _computeGroupY /*1*/, 1); } // Set camera parameters h3d.setNodeTransform(_cam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); //horde3d 1.0 Horde3DUtils.showFrameStats(_fontMatRes, _panelMatRes, _statMode); // Show logo float ww = h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportWidthI) / (float)h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportHeightI); float[] ovLogo = new float[] { ww - 0.4f, 0.8f, 0, 1, ww - 0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3d.showOverlays(ovLogo, 4, 1, 1, 1, 1, _logoMatRes, 0); // Render scene h3d.render(_cam);//horde3D 1.0 h3d.finalizeFrame(); //horde3D 1.0 h3d.clearOverlays(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
/// <summary> /// All application initialization is performed here, before the main loop thread is executed and the render panel is displayed for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderForm_Load(object sender, EventArgs e) { if (!Horde3DUtils.initOpenGL(GetDC(renderPanel.Handle).ToInt32())) { throw new Exception("Failed to initialize OpenGL"); } if (!app.init()) { MessageBox.Show("Failed to init application\nMake sure you have an OpenGL 2.0 compatible graphics card with the latest drivers installed!\nAlso verify if the pipeline config file exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); h3d.release(); Horde3DUtils.releaseOpenGL(); Environment.Exit(0); } app.resize(renderPanel.Size.Width, renderPanel.Size.Height); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1 / fps; Horde3D.setOption(Horde3D.EngineOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); if (!_freeze) { _crowdSim.update(_curFPS); } // Set camera parameters Horde3D.setNodeTransform(Horde3D.PrimeTimeCam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); if (_showFPS) { // Avoid updating FPS text every frame to make it readable if (_timer > 0.3f) { _fpsText = string.Format("FPS: {0:F2}", fps); _timer = 0; } // Show text if (_fpsText != null) { Horde3DUtils.showText(_fpsText, 0, 0.95f, 0.03f, 0, _fontMatRes); } } // Show logo Horde3D.showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0, 1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1, 7, _logoMatRes); // Render scene Horde3D.render(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1f / fps; h3d.setOption(h3d.H3DOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); h3d.setOption(h3d.H3DOptions.WireframeMode, _wireframeMode ? 1.0f : 0.0f); if (!_freeze) { // Set animation time // Calculate animation time in seconds _rotation += 0.05f; h3d.setNodeTransform(_model, 0, 0, 0, _rotation, _rotation, 0, 1, 1, 1); } // Set camera parameters h3d.setNodeTransform(_cam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); //horde3d 1.0 Horde3DUtils.showFrameStats(_fontMatRes, _panelMatRes, _statMode); Horde3DUtils.showText("Up/Down arrows to modify tessellation level", 1.0f, 0.01f, 0.032f, 1, 1, 1, _fontMatRes); // Show logo float ww = h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportWidthI) / (float)h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportHeightI); float[] ovLogo = new float[] { ww - 0.4f, 0.8f, 0, 1, ww - 0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3d.showOverlays(ovLogo, 4, 1, 1, 1, 1, _logoMatRes, 0); // Render scene h3d.render(_cam);//horde3D 1.0 h3d.finalizeFrame(); //horde3D 1.0 h3d.clearOverlays(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
public void mainLoop(float fps) { _curFPS = fps; _timer += 1 / fps; h3d.setOption(h3d.H3DOptions.WireframeMode, _wireframeMode ? 1.0f : 0.0f); h3d.setOption(h3d.H3DOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f); if (!_freeze) { _crowdSim.update(_curFPS); } // Set camera parameters h3d.setNodeTransform(_cam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1); if (_statMode > 0) { Horde3DUtils.showFrameStats(_fontMatRes, _panelMatRes, _statMode); } // Show logo float ww = h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportWidthI) / (float)h3d.getNodeParamI(_cam, (int)h3d.H3DCamera.ViewportHeightI); float[] ovLogo = new float[] { ww - 0.4f, 0.8f, 0, 1, ww - 0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3d.showOverlays(ovLogo, 4, 1, 1, 1, 1, _logoMatRes, 0); // Render scene h3d.render(_cam); // Finish rendering of frame h3d.finalizeFrame(); // Clear Overlays h3d.clearOverlays(); // Write all messages to log file Horde3DUtils.dumpMessages(); }
public bool init() { // Initialize engine if (!h3d.init(h3d.H3DRenderDevice.OpenGL4)) { Horde3DUtils.dumpMessages(); return(false); } if (h3d.getDeviceCapabilities(h3d.H3DDeviceCapabilities.GeometryShaders) == 0 || h3d.getDeviceCapabilities(h3d.H3DDeviceCapabilities.TessellationShaders) == 0) { return(false); } // Set options h3d.setOption(h3d.H3DOptions.LoadTextures, 1); h3d.setOption(h3d.H3DOptions.TexCompression, 0); h3d.setOption(h3d.H3DOptions.FastAnimation, 0); h3d.setOption(h3d.H3DOptions.MaxAnisotropy, 4); h3d.setOption(h3d.H3DOptions.ShadowMapSize, 2048); // Add resources // added horde3d 1.0 // Pipelines _hdrPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/hdr.pipeline.xml", 0); _forwardPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/forward.pipeline.xml", 0); // Overlays _fontMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/font.material.xml", 0); _panelMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/panel.material.xml", 0); _logoMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/logo.material.xml", 0); int lightMatRes = h3d.addResource(( int )h3d.H3DResTypes.Material, "materials/light.material.xml", 0); bool result = createIcosahedron(); if (!result) { return(false); } // Load resources Horde3DUtils.loadResourcesFromDisk("../Content"); // horde3d 1.0 // Add camera _cam = h3d.addCameraNode(h3d.H3DRootNode, "Camera", _forwardPipeRes); ///////////// // Create model and mesh int geo = h3d.findResource((int)h3d.H3DResTypes.Geometry, "icosa"); int mat = h3d.findResource(( int )h3d.H3DResTypes.Material, "material"); int indices = h3d.getResParamI(geo, (int)h3d.H3DGeoRes.GeometryElem, 0, (int)h3d.H3DGeoRes.GeoIndexCountI); int vertices = h3d.getResParamI(geo, (int)h3d.H3DGeoRes.GeometryElem, 0, (int)h3d.H3DGeoRes.GeoVertexCountI); _model = h3d.addModelNode(h3d.H3DRootNode, "model", geo); int mesh = h3d.addMeshNode(_model, "icosahedron", mat, 0, indices, 0, vertices - 1); h3d.setNodeTransform(mesh, 0, 0, 0, 0, 0, 0, 20, 20, 20); h3d.setNodeParamI(mesh, ( int)h3d.H3DMesh.TessellatableI, 1); // Set mesh to use tessellation // Add light source int light = h3d.addLightNode(h3d.H3DRootNode, "Light1", lightMatRes, "LIGHTING", "SHADOWMAP"); h3d.setNodeTransform(light, 125, 25, 85, -10, 55, 0, 1, 1, 1); h3d.setNodeParamF(light, ( int )h3d.H3DLight.RadiusF, 0, 1000); h3d.setNodeParamF(light, ( int )h3d.H3DLight.FovF, 0, 75); h3d.setNodeParamI(light, ( int )h3d.H3DLight.ShadowMapCountI, 3); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ShadowSplitLambdaF, 0, 0.9f); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ShadowMapBiasF, 0, 0.001f); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ColorF3, 0, 0.9f); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ColorF3, 1, 0.7f); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ColorF3, 2, 0.75f); h3d.setNodeParamF(light, ( int )h3d.H3DLight.ColorMultiplierF, 0, 1.0f); _initialized = true; return(true); }
public bool init() { // Initialize engine if (!Horde3D.init()) { Horde3DUtils.dumpMessages(); return(false); } // Set paths for resources Horde3D.setResourcePath(Horde3D.ResourceTypes.SceneGraph, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Geometry, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Animation, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Material, "materials"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Code, "shaders"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Shader, "shaders"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Texture2D, "textures"); Horde3D.setResourcePath(Horde3D.ResourceTypes.TextureCube, "textures"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Effect, "effects"); // Load pipeline configuration if (!Horde3D.loadPipelineConfig("pipeline_Knight.xml")) { Horde3DUtils.dumpMessages(); return(false); } // Set options Horde3D.setOption(Horde3D.EngineOptions.LoadTextures, 1); Horde3D.setOption(Horde3D.EngineOptions.TexCompression, 0); Horde3D.setOption(Horde3D.EngineOptions.FastAnimation, 0); Horde3D.setOption(Horde3D.EngineOptions.AnisotropyFactor, 8); Horde3D.setOption(Horde3D.EngineOptions.ShadowMapSize, 2048); // Add resources // Font _fontMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "font.material.xml", 0); // Logo _logoMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "logo.material.xml", 0); // Environment int envRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "scene.scene.xml", 0); // Knight int knightRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "knight.scene.xml", 0); int knightAnim1Res = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "knight_order.anim", 0); int knightAnim2Res = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "knight_attack.anim", 0); // Particle system int particleSysRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "particleSys1.scene.xml", 0); // Load resources Horde3DUtils.loadResourcesFromDisk("content"); // Add scene nodes // Add environment Horde3D.addNodes(Horde3D.RootNode, envRes); // Add knight _knight = Horde3D.addNodes(Horde3D.RootNode, knightRes); Horde3D.setNodeTransform(_knight, 0, 0, 0, 0, 180, 0, 0.1f, 0.1f, 0.1f); Horde3D.setupModelAnimStage(_knight, 0, knightAnim1Res, string.Empty, false); Horde3D.setupModelAnimStage(_knight, 1, knightAnim2Res, string.Empty, false); // Attach particle system to hand joint int hand = Horde3D.getNodeChild(_knight, "Bip01_R_Hand", 0, true); _particleSys = Horde3D.addNodes(hand, particleSysRes); Horde3D.setNodeTransform(_particleSys, 0, 40, 0, 90, 0, 0, 1, 1, 1); // Add light source int light = Horde3D.addLightNode(Horde3D.RootNode, "Light1", 0, "LIGHTING", "SHADOWMAP"); Horde3D.setNodeTransform(light, 0, 1, 15, 30, 0, 0, 1, 1, 1); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 30); Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 1); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapBias, 0.01f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 1.0f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.7f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.7f); // Customize post processing effects int matRes = Horde3D.findResource(Horde3D.ResourceTypes.Material, "postHDR.material.xml"); // hdrParams: exposure, brightpass threshold, brightpass offset Horde3D.setMaterialUniform(matRes, "hdrParams", 2.5f, 0.6f, 0.06f, 0); _initialized = true; return(true); }
public static bool createIcosahedron() { // Create vertex and index data float phi = (1.0f / ((1.0f + ( float )Math.Sqrt(5.0f)) / 2.0f)); Vec3[] vertPos = { new Vec3(-phi, 1.0f, 0.0f), new Vec3(phi, 1.0f, 0.0f), new Vec3(-phi, -1.0f, 0.0f), new Vec3(phi, -1.0f, 0.0f), new Vec3(0.0f, -phi, 1.0f), new Vec3(0.0f, phi, 1.0f), new Vec3(0.0f, -phi, -1.0f), new Vec3(0.0f, phi, -1.0f), new Vec3(1.0f, 0.0f, -phi), new Vec3(1.0f, 0.0f, phi), new Vec3(-1.0f, 0.0f, -phi), new Vec3(-1.0f, 0.0f, phi) }; float[] vertPosFloat = { -phi, 1.0f, 0.0f, phi, 1.0f, 0.0f, -phi, -1.0f, 0.0f, phi, -1.0f, 0.0f, 0.0f, -phi, 1.0f, 0.0f, phi, 1.0f, 0.0f, -phi, -1.0f, 0.0f, phi, -1.0f, 1.0f, 0.0f, -phi, 1.0f, 0.0f, phi, -1.0f, 0.0f, -phi, -1.0f, 0.0f, phi }; float[] texCoords = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }; int[] indices = { 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 5, 11, 4, 1, 5, 9, 7, 1, 8, 10, 7, 6, 11, 10, 2, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 }; Vec3[] normals = new Vec3[12]; short[] normalsShort = new short[36]; // calculate normals for (int i = 0; i < 12; ++i) { int index0 = indices[i * 3 + 0]; int index1 = indices[i * 3 + 1]; int index2 = indices[i * 3 + 2]; Vec3 v0 = vertPos[index0]; Vec3 v1 = vertPos[index1]; Vec3 v2 = vertPos[index2]; Vec3 e0 = v1 - v0; Vec3 e1 = v2 - v0; Vec3 result = normalize(cross(e0, e1)); normals[index0] = result; normals[index1] = result; normals[index2] = result; // normals[ index0 * 3 + 0 ] += result.x; normals[ index0 * 3 + 1 ] += result.y; normals[ index0 * 3 + 2 ] += result.z; // normals[ index1 * 3 + 0 ] += result.x; normals[ index1 * 3 + 1 ] += result.y; normals[ index1 * 3 + 2 ] += result.z; // normals[ index2 * 3 + 0 ] += result.x; normals[ index2 * 3 + 1 ] += result.y; normals[ index2 * 3 + 2 ] += result.z; } for (int j = 0; j < 12; ++j) { Vec3 v = normalize(normals[j]); normalsShort[j * 3 + 0] = ( short )(v.x * 32767); normalsShort[j * 3 + 1] = ( short )(v.y * 32767); normalsShort[j * 3 + 2] = ( short )(v.z * 32767); } int geo = Horde3DUtils.createGeometryRes("icosa", 12, indices.Length, vertPosFloat, indices, normalsShort, null, null, texCoords, null); if (geo == 0) { return(false); } // Create material String matData = "<Material>\n" + "<Shader source=\"shaders/tessellation.shader\" />" + "<Uniform name=\"tessLevelInner\" a=\"1\" />\n" + "<Uniform name=\"tessLevelOuter\" a=\"1\" />\n" + "<Uniform name=\"matAmbientCol\" a=\"0.04\" b=\"0.04\" c=\"0.04\" />\n" + "<Uniform name=\"matDiffuseCol\" a=\"0\" b=\"0.75\" c=\"0.75\" />\n" + "</Material>"; byte[] matDataBytes = Encoding.ASCII.GetBytes(matData); int mat = h3d.addResource(( int )h3d.H3DResTypes.Material, "material", 0); bool res = h3d.loadResource(mat, matDataBytes, matData.Length); if (!res) { return(false); } return(true); }
public bool init() { // Initialize engine if (!h3d.init(h3d.H3DRenderDevice.OpenGL4)) { Horde3DUtils.dumpMessages(); return(false); } // Set options h3d.setOption(h3d.H3DOptions.LoadTextures, 1); h3d.setOption(h3d.H3DOptions.TexCompression, 0); h3d.setOption(h3d.H3DOptions.MaxAnisotropy, 4); h3d.setOption(h3d.H3DOptions.ShadowMapSize, 2048); h3d.setOption(h3d.H3DOptions.FastAnimation, 1); // Add resources // Pipelines _forwardPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/forward.pipeline.xml", 0); _deferredPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/deferred.pipeline.xml", 0); // Overlays _fontMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/font.material.xml", 0); _panelMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/panel.material.xml", 0); _logoMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/logo.material.xml", 0); // Shader for deferred shading int lightMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "materials/light.material.xml", 0); // Environment int envRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/platform/platform.scene.xml", 0); // Skybox int skyBoxRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/skybox/skybox.scene.xml", 0); // Load resources Horde3DUtils.loadResourcesFromDisk("../Content"); // Add scene nodes // Add camera _cam = h3d.addCameraNode(h3d.H3DRootNode, "Camera", _forwardPipeRes); // Add environment int env = h3d.addNodes(h3d.H3DRootNode, envRes); h3d.setNodeTransform(env, 0, 0, 0, 0, 0, 0, 0.23f, 0.23f, 0.23f); // Add skybox int sky = h3d.addNodes(h3d.H3DRootNode, skyBoxRes); h3d.setNodeTransform(sky, 0, 0, 0, 0, 0, 0, 210, 50, 210); // Add light source int light = h3d.addLightNode(h3d.H3DRootNode, "Light1", lightMatRes, "LIGHTING", "SHADOWMAP"); h3d.setNodeTransform(light, 0, 20, 50, -30, 0, 0, 1, 1, 1); h3d.setNodeParamF(light, (int)h3d.H3DLight.RadiusF, 0, 200); h3d.setNodeParamF(light, (int)h3d.H3DLight.FovF, 0, 90); h3d.setNodeParamI(light, (int)h3d.H3DLight.ShadowMapCountI, 3); h3d.setNodeParamF(light, (int)h3d.H3DLight.ShadowSplitLambdaF, 0, 0.9f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ShadowMapBiasF, 0, 0.001f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 0, 0.9f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 1, 0.7f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 2, 0.75f); _crowdSim = new CrowdSim(); _crowdSim.init(); _initialized = true; return(true); }
public bool Startup() { DeckProgram.DeckScene.ObjectAdd += OnObjectAdd; DeckProgram.DeckScene.ObjectUpdate += OnObjectUpdate; DeckProgram.DeckScene.ObjectRemove += OnObjectRemove; DeckProgram.DeckScene.BubbleAdd += OnBubbleAdd; DeckProgram.DeckScene.BubbleRemove += OnBubbleRemove; // Initialize engine if (!h3d.init()) { Horde3DUtils.dumpMessages(); return(false); } // Set options h3d.setOption(h3d.H3DOptions.LoadTextures, 1); h3d.setOption(h3d.H3DOptions.TexCompression, 0); h3d.setOption(h3d.H3DOptions.FastAnimation, 0); h3d.setOption(h3d.H3DOptions.MaxAnisotropy, 8); h3d.setOption(h3d.H3DOptions.ShadowMapSize, 2048); h3d.setOption(h3d.H3DOptions.TrilinearFiltering, 1); h3d.setOption(h3d.H3DOptions.SampleCount, 8); // Add resources HdrPipeHid = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/hdr.pipeline.xml", 0); ForwardPipeHid = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/forward.pipeline.xml", 0); m_fontMaterialHid = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/font.material.xml", 0); m_panelMaterialHid = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/panel.material.xml", 0); m_logoMaterialHid = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/logo.material.xml", 0); m_bubbleRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/bubble5/bubble5.scene.xml", 0); m_atmosphereRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/whiteatmosphere/whiteatmosphere.scene.xml", 0); // Overlays m_demo.Initialize(); // Load resources Horde3DUtils.loadResourcesFromDisk("content"); // Add camera CameraHid = h3d.addCameraNode(h3d.H3DRootNode, "CameraHid", ForwardPipeHid); // Add light source LightHid = h3d.addLightNode(h3d.H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP"); h3d.setNodeTransform(LightHid, 0, 1, 15, 30, 0, 0, 1, 1, 1); h3d.setNodeTransform(LightHid, 0, 15, 10, -60, 0, 0, 1, 1, 1); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.RadiusF, 0, 30); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.FovF, 0, 60); h3d.setNodeParamI(LightHid, (int)h3d.H3DLight.ShadowMapCountI, 1); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.ShadowMapBiasF, 0, 0.01f); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.ColorF3, 0, 1.0f); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.ColorF3, 1, 0.8f); h3d.setNodeParamF(LightHid, (int)h3d.H3DLight.ColorF3, 2, 0.7f); // Customize post processing effects int matRes = h3d.findResource((int)h3d.H3DResTypes.Material, "pipelines/postHDR.material.xml"); // hdrParams: exposure, brightpass threshold, brightpass offset h3d.setMaterialUniform(matRes, "hdrParams", 2.5f, 0.5f, 0.08f, 0); m_initialized = true; //m_atmosphereHid = h3d.addNodes(h3d.H3DRootNode, m_atmosphereRes); //h3d.setNodeTransform(m_atmosphereHid, 0, 0, 0, 0, 180, 0, 1000f, 1000f, 1000f); return(true); }
public bool init() { // Initialize engine if (!h3d.init(h3d.H3DRenderDevice.OpenGL4)) { Horde3DUtils.dumpMessages(); return(false); } if (h3d.getDeviceCapabilities(h3d.H3DDeviceCapabilities.GeometryShaders) == 0 || h3d.getDeviceCapabilities(h3d.H3DDeviceCapabilities.ComputeShaders) == 0) { return(false); } // Set options h3d.setOption(h3d.H3DOptions.LoadTextures, 1); h3d.setOption(h3d.H3DOptions.TexCompression, 0); h3d.setOption(h3d.H3DOptions.FastAnimation, 0); h3d.setOption(h3d.H3DOptions.MaxAnisotropy, 4); h3d.setOption(h3d.H3DOptions.ShadowMapSize, 2048); // Add resources // added horde3d 1.0 // Pipelines _hdrPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/hdr.pipeline.xml", 0); _forwardPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/forward.pipeline.xml", 0); // Overlays _fontMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/font.material.xml", 0); _panelMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/panel.material.xml", 0); _logoMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/logo.material.xml", 0); // Shader that contains geometry and compute shaders for particles _computeMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "materials/compute.material.xml", 0); int computeDrawMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "materials/computeDraw.material.xml", 0); // 2. Specify compute buffer parameters // Create compute buffer int compBuf = h3d.addResource((int)h3d.H3DResTypes.ComputeBuffer, "CompBuf", 0); // Generate random position data for particles int particlesCount = 1000000; ParticleData[] particles = new ParticleData[particlesCount]; float maxDiapason10 = 10.0f; float minDiapason10 = -10.0f; float maxDiapason3 = 3.0f; float minDiapason3 = -3.0f; float maxDiapason30 = 30.0f; float minDiapason30 = -30.0f; float maxDiapason100 = 100.0f; float minDiapason100 = -100.0f; Random rand = new Random((int)DateTime.Now.Ticks); float x, y, z = 0; float tmpVal = 0; float angle = 0; for (int i = 0; i < particlesCount; i++) { ParticleData data = new ParticleData(); data.position = new vec4(); // Set random position x = (maxDiapason10 + 1 - minDiapason10) * (float)rand.NextDouble() + minDiapason10; y = (maxDiapason3 + 1 - minDiapason3) * (float)rand.NextDouble() + minDiapason3; z = (maxDiapason30 + 1 - minDiapason30) * (float)rand.NextDouble() + minDiapason30; normalize(ref x, ref y, ref z); tmpVal = (maxDiapason100 + 1 - minDiapason100) * (float)rand.NextDouble() + minDiapason100; data.position.x = x * tmpVal; data.position.y = y * tmpVal; data.position.z = z * tmpVal; angle = -(float)Math.Atan2(x, z); data.velocity = new vec4(); data.velocity.x = (float)Math.Cos(angle); data.velocity.y = 0; data.velocity.z = ( float )Math.Sin(angle) * 5.0f; particles[i] = data; } // Set size of the compute buffer h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.ComputeBufElem, 0, (int)h3d.H3DComputeBufRes.CompBufDataSizeI, particlesCount * 32); // Mark that compute buffer will be used for rendering as a vertex buffer h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.ComputeBufElem, 0, (int)h3d.H3DComputeBufRes.CompBufDrawableI, 1); // Set vertex binding parameters. // Name - name of the parameter. Used for binding parameter to shader variable. // Size - number of components (4 float for particle position, so 4), // Offset - number of bytes. For second parameter it is 16, because the first parameter had 4 floats (16 bytes) h3d.setResParamStr(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 0, (int)h3d.H3DComputeBufRes.DrawParamsNameStr, "partPosition"); h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 0, (int)h3d.H3DComputeBufRes.DrawParamsSizeI, /*3*/ 4); h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 0, (int)h3d.H3DComputeBufRes.DrawParamsOffsetI, 0); h3d.setResParamStr(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 1, (int)h3d.H3DComputeBufRes.DrawParamsNameStr, "partVelocity"); h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 1, (int)h3d.H3DComputeBufRes.DrawParamsSizeI, /*3*/ 4); h3d.setResParamI(compBuf, (int)h3d.H3DComputeBufRes.DrawParamsElem, 1, (int)h3d.H3DComputeBufRes.DrawParamsOffsetI, /*12*/ 16); // Fill compute buffer with generated data IntPtr dataPtr = h3d.mapResStream(compBuf, (int)h3d.H3DComputeBufRes.ComputeBufElem, 0, 0, false, true); // Some unsafe magic to copy array to c pointer unsafe { GCHandle handle = GCHandle.Alloc(particles, GCHandleType.Pinned); try { IntPtr pointer = handle.AddrOfPinnedObject(); memcpy(dataPtr, pointer, particlesCount * 32); } finally { if (handle.IsAllocated) { handle.Free(); } } } h3d.unmapResStream(compBuf); // Load resources Horde3DUtils.loadResourcesFromDisk("../Content"); // horde3d 1.0 // Add camera _cam = h3d.addCameraNode(h3d.H3DRootNode, "Camera", _forwardPipeRes); ///////////// // Add scene nodes // In order to draw the results of compute buffer we need a compute node _compNode = h3d.addComputeNode(h3d.H3DRootNode, "Vortex", computeDrawMatRes, compBuf, 2, particlesCount); // Set node AABB size because currently there is no way to do it otherwise h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMinF, 0, -30.0f); // x h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMinF, 1, -30.0f); // y h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMinF, 2, -30.0f); // z h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMaxF, 0, 30.0f); // x h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMaxF, 1, 30.0f); // y h3d.setNodeParamF(_compNode, (int)h3d.H3DComputeNode.AABBMaxF, 2, 30.0f); // z // Set material uniforms that will not be changed during runtime h3d.setMaterialUniform(_computeMatRes, "totalParticles", ( float )particlesCount, 0, 0, 0); // Calculate number of groups for compute shader int numGroups = (particlesCount % 1024 != 0) ? ((particlesCount / 1024) + 1) : (particlesCount / 1024); double root = Math.Pow(( double )numGroups, ( double )(1.0 / 2.0)); root = Math.Ceiling(root); _computeGroupX = _computeGroupY = ( int )root; _initialized = true; return(true); }
public bool init() { // Initialize engine if (!h3d.init()) { Horde3DUtils.dumpMessages(); return(false); } // Set options h3d.setOption(h3d.H3DOptions.LoadTextures, 1); h3d.setOption(h3d.H3DOptions.TexCompression, 0); h3d.setOption(h3d.H3DOptions.FastAnimation, 0); h3d.setOption(h3d.H3DOptions.MaxAnisotropy, 4); h3d.setOption(h3d.H3DOptions.ShadowMapSize, 2048); // Add resources // added horde3d 1.0 // Pipelines _hdrPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/hdr.pipeline.xml", 0); _forwardPipeRes = h3d.addResource((int)h3d.H3DResTypes.Pipeline, "pipelines/forward.pipeline.xml", 0); // Overlays _fontMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/font.material.xml", 0); _panelMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/panel.material.xml", 0); _logoMatRes = h3d.addResource((int)h3d.H3DResTypes.Material, "overlays/logo.material.xml", 0); // Environment int envRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/sphere/sphere.scene.xml", 0); // Knight int knightRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "models/knight/knight.scene.xml", 0); int knightAnim1Res = h3d.addResource((int)h3d.H3DResTypes.Animation, "animations/knight_order.anim", 0); int knightAnim2Res = h3d.addResource((int)h3d.H3DResTypes.Animation, "animations/knight_attack.anim", 0); // Particle system int particleSysRes = h3d.addResource((int)h3d.H3DResTypes.SceneGraph, "particles/particleSys1/particleSys1.scene.xml", 0); // Load resources Horde3DUtils.loadResourcesFromDisk("../Content"); // horde3d 1.0 // Add camera _cam = h3d.addCameraNode(h3d.H3DRootNode, "Camera", _hdrPipeRes); ///////////// // Add scene nodes // Add environment int env = h3d.addNodes(h3d.H3DRootNode, envRes); h3d.setNodeTransform(env, 0, -20, 0, 0, 0, 0, 20, 20, 20); //horde3d 1.0 // Add knight _knight = h3d.addNodes(h3d.H3DRootNode, knightRes); h3d.setNodeTransform(_knight, 0, 0, 0, 0, 180, 0, 0.1f, 0.1f, 0.1f); h3d.setupModelAnimStage(_knight, 0, knightAnim1Res, 0, string.Empty, false); h3d.setupModelAnimStage(_knight, 1, knightAnim2Res, 0, string.Empty, false); //horde3d 1.0 // Attach particle system to hand joint h3d.findNodes(_knight, "Bip01_R_Hand", (int)h3d.H3DNodeTypes.Joint); int hand = h3d.getNodeFindResult(0); _particleSys = h3d.addNodes(hand, particleSysRes); h3d.setNodeTransform(_particleSys, 0, 40, 0, 90, 0, 0, 1, 1, 1); ///////// // Add light source int light = h3d.addLightNode(h3d.H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP"); h3d.setNodeTransform(light, 0, 1, 15, 30, 0, 0, 1, 1, 1); h3d.setNodeTransform(light, 0, 15, 10, -60, 0, 0, 1, 1, 1); h3d.setNodeParamF(light, (int)h3d.H3DLight.RadiusF, 0, 30); h3d.setNodeParamF(light, (int)h3d.H3DLight.FovF, 0, 90); h3d.setNodeParamI(light, (int)h3d.H3DLight.ShadowMapCountI, 1); h3d.setNodeParamF(light, (int)h3d.H3DLight.ShadowMapBiasF, 0, 0.01f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 0, 1.0f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 1, 0.8f); h3d.setNodeParamF(light, (int)h3d.H3DLight.ColorF3, 2, 0.7f); ///////////// // Customize post processing effects int matRes = h3d.findResource((int)h3d.H3DResTypes.Material, "pipelines/postHDR.material.xml"); // hdrParams: exposure, brightpass threshold, brightpass offset h3d.setMaterialUniform(matRes, "hdrParams", 2.5f, 0.5f, 0.08f, 0); _initialized = true; return(true); }
public bool init() { // Initialize engine if (!Horde3D.init()) { Horde3DUtils.dumpMessages(); return(false); } // Set paths for resources Horde3D.setResourcePath(Horde3D.ResourceTypes.SceneGraph, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Geometry, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Animation, "models"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Material, "materials"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Code, "shaders"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Shader, "shaders"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Texture2D, "textures"); Horde3D.setResourcePath(Horde3D.ResourceTypes.TextureCube, "textures"); Horde3D.setResourcePath(Horde3D.ResourceTypes.Effect, "effects"); // Load pipeline configuration if (!Horde3D.loadPipelineConfig("pipeline_Chicago.xml")) { Horde3DUtils.dumpMessages(); return(false); } // Set options Horde3D.setOption(Horde3D.EngineOptions.LoadTextures, 1); Horde3D.setOption(Horde3D.EngineOptions.TexCompression, 0); Horde3D.setOption(Horde3D.EngineOptions.AnisotropyFactor, 8); Horde3D.setOption(Horde3D.EngineOptions.ShadowMapSize, 2048); Horde3D.setOption(Horde3D.EngineOptions.FastAnimation, 0); // Add resources // Font _fontMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "font.material.xml", 0); // Logo _logoMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "logo.material.xml", 0); // Shader for deferred shading int lightMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "light.material.xml", 0); // Environment int envRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "scene.scene.xml", 0); // Skybox //int skyBoxRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "skybox.scene.xml", 0); // Load resources Horde3DUtils.loadResourcesFromDisk("content"); // Add scene nodes // Add environment Horde3D.addNodes(Horde3D.RootNode, envRes); // Add skybox //int sky = Horde3D.addNodes( Horde3D.RootNode, skyBoxRes ); //Horde3D.setNodeTransform(sky, 0, 0, 0, 0, 0, 0, 210, 50, 210); // Add light source int light = Horde3D.addLightNode(Horde3D.RootNode, "Light1", lightMatRes, "LIGHTING", "SHADOWMAP"); Horde3D.setNodeTransform(light, 0, 25, -25, -120, 0, 0, 1, 1, 1); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 100); Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 3); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowSplitLambda, 0.95f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 0.98f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.6f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.5f); // Add light source light = Horde3D.addLightNode(Horde3D.RootNode, "Light2", lightMatRes, "LIGHTING", "SHADOWMAP"); Horde3D.setNodeTransform(light, 0, 25, 30, -60, 0, 0, 1, 1, 1); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 50); Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 3); Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowSplitLambda, 0.95f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 0.5f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.6f); Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.98f); _crowdSim = new CrowdSim(); _crowdSim.init(); _initialized = true; return(true); }