public Water(IContext context, IEnumerable <SeaProvince> provinces) { _bumpMapTexture = context.TextureManager.Create("OceanWater.png").TextureResource; _borderTexture = context.TextureManager.Create("Border.png").TextureResource; _shader = context.Shaders.Get <WaterShader>(); BuildBuffers(context, provinces); }
public Terrain(Device device, String texture, int pitch, Renderer renderer) { HeightMap = new System.Drawing.Bitmap(@"Data/Textures/" + texture); WaterShader = new WaterShader(device); TerrainShader = new TerrainShader(device); _width = HeightMap.Width - 1; _height = HeightMap.Height - 1; _pitch = pitch; _terrainTextures = new ShaderResourceView[4]; _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource; _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource; _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource; _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource; _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f); _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000); _reflectionTexture = new RenderTexture(device, renderer.ScreenSize); _refractionTexture = new RenderTexture(device, renderer.ScreenSize); _renderer = renderer; _bitmap = new Bitmap(device, _refractionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0); _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120); _bumpMap = _renderer.TextureManager.Create("OceanWater.png"); _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png")); BuildBuffers(device); WaveTranslation = new Vector2(0, 0); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the water object. WaterModel?.ShutDown(); WaterModel = null; // Release the reflection shader object. ReflectionShader?.ShutDown(); ReflectionShader = null; // Release the reflection render to texture object. ReflectionTexture?.Shutdown(); ReflectionTexture = null; // Release the refraction render to texture object. RefractionTexture?.Shutdown(); RefractionTexture = null; // Release the sky plane shader object. SkyPlaneShader?.ShutDown(); SkyPlaneShader = null; // Release the sky plane object. SkyPlane?.ShurDown(); SkyPlane = null; // Release the sky dome shader object. SkyDomeShader?.ShutDown(); SkyDomeShader = null; // Release the sky dome object. SkyDome?.ShutDown(); SkyDome = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Render(List <JWaterTile> waterTiles, JCamera camera, JLight light) { PrepareRender(camera, light); foreach (JWaterTile tile in waterTiles) { Matrix4 modelMatrix = JMathUtils.createTransformationMatrix(new Vector3(tile.X, tile.Height, tile.Z), 0, 0, 0, JWaterTile.TILE_SIZE); WaterShader.LoadModelMatrix(modelMatrix); GL.DrawArrays(PrimitiveType.Triangles, 0, WaterQuad.vertexCount); } Unbind(); }
/// <summary> /// Creates a new <see cref="WaterViewSource"/> /// </summary> /// <param name="height">The height of the <see cref="Water"/> planes (Y axis)</param> /// <param name="baseView">The <see cref="View"/> the <see cref="Water"/> planes are shown in</param> /// <param name="clipTolerance">How far to shift the clip plane along its normal vector to reduce graphical glitches at corners</param> private WaterViewSource(double height, View baseView, float clipTolerance) { Height = height; BaseView = baseView; ClipTolerance = clipTolerance; // Create child views var position = new DoubleVector3(0, height, 0); RefractedView = WaterView.CreateRefraction(baseView, new DoublePlane(position, -1 * UpVector), clipTolerance); ReflectedView = WaterView.CreateReflection(baseView, new DoublePlane(position, UpVector), clipTolerance); // Load shaders RefractionOnlyShader = new WaterShader(RefractedView); RefractionReflectionShader = new WaterShader(RefractedView, ReflectedView); }
public JWaterRenderer(JLoader loader, JWaterShader waterShader, Matrix4 projectionMatrix, JWaterFrameBuffer frameBuffer, JWaterTile waterTile) { this.WaterShader = waterShader; this.FrameBuffer = frameBuffer; this.WaterTile = waterTile; dudvMapTexture = JFileUtils.GetPathToResFile("waterDUDV.png"); normalMapTexture = JFileUtils.GetPathToResFile("matchingNormalMap.png"); dudvMap = loader.loadTexture(dudvMapTexture); normalMap = loader.loadTexture(normalMapTexture); distortionVariance = 0; WaterShader.start(); WaterShader.LoadTextures(); WaterShader.LoadProjectionMatrix(projectionMatrix); WaterShader.stop(); SetupVAO(loader); }
public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Light light) { Light newLight = new Light(light.Direction, light.Color, new Vector4(1), light.SpecularPower, light.SpecularColor); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - WaveTranslation.X / 8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _refractionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _refractionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _refractionClippingPlane); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _reflectionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _reflectionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - WaveTranslation.X / 8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, _renderer.Camera.ReflectionMatrix, projectionMatrix, light, _terrainTextures, _reflectionClippingPlane); _renderer.DirectX.SetBackBufferAsRenderTarget(); //Render water deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(WaterVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTexture>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(WaterIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; WaterShader.Render(deviceContext, WaterIndexCount, worldMatrix, viewMatrix, projectionMatrix, _renderer.Camera.ReflectionMatrix, _reflectionTexture.ShaderResourceView, _refractionTexture.ShaderResourceView, _bumpMap.TextureResource, WaveTranslation, _renderer.Camera.Position); //Render terrain deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _noClippingPlane); _bitmap.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _refractionTexture.ShaderResourceView); _bitmap2.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _reflectionTexture.ShaderResourceView); }
public void Shutdown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the refraction shader object. RefractionShader?.ShutDown(); RefractionShader = null; /// Release the render to texture object. RenderReflectionTexture?.Shutdown(); RenderReflectionTexture = null; // Release the render to texture object. RenderRefractionTexture?.Shutdown(); RenderRefractionTexture = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the model object. GroundModel?.Shutdown(); GroundModel = null; // Release the model object. WallModel?.Shutdown(); WallModel = null; // Release the model object. BathModel?.Shutdown(); BathModel = null; // Release the model object. WaterModel?.Shutdown(); WaterModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private void PrepareRender(JCamera camera, JLight light) { WaterShader.start(); WaterShader.LoadViewMatrix(camera); distortionVariance += DISTORTION_SPEED * JGameWindow.FrameTimeSeconds(); distortionVariance %= 1.0f; WaterShader.LoadDistortionVariance(distortionVariance); WaterShader.LoadLight(light); GL.BindVertexArray(WaterQuad.vaoID); GL.EnableVertexAttribArray(0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, FrameBuffer.ReflectionTexture); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, FrameBuffer.RefractionTexture); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, WaterTile.ColorTexture.TextureID); GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2D, dudvMap); GL.ActiveTexture(TextureUnit.Texture4); GL.BindTexture(TextureTarget.Texture2D, normalMap); }
private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, ortho, base view and reflection matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix reflectionMatrix = Camera.ReflectionViewMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, out worldMatrix); // Turn off back face culling and the Z buffer. D3D.TurnOffCulling(); D3D.TurnZBufferOff(); // Render the sky dome using the sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the terrain shader. TerrainModel.Render(D3D.DeviceContext); if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f)) { return(false); } // Translate to the location of the water and render it. Matrix.Translation(240.0f, WaterModel.WaterHeight, 250.0f, out worldMatrix); WaterModel.Render(D3D.DeviceContext); if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, reflectionMatrix, ReflectionTexture.ShaderResourceView, RefractionTexture.ShaderResourceView, WaterModel.Texture.TextureResource, Camera.GetPosition(), WaterModel.NormalMapTiling, WaterModel.WaterTranslation, WaterModel.ReflectRefractScale, WaterModel.RefractionTint, Light.Direction, WaterModel.SpecularShininess)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix); // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
const double HeightResize = 128.0 * 256.0; //512 * 40; public Map(int _Width, int _Height, int InitialHeight, bool _Water, int WaterLevel, int DepthLevel, int AbyssLevel) { Width = _Width; Height = _Height; PreviewTex = new Texture2D(256, 256, TextureFormat.RGBA32, false); TexturemapTex = new Texture2D(Width, Height, TextureFormat.RGBA32, false); TexturemapTex2 = new Texture2D(Width, Height, TextureFormat.RGBA32, false); NormalmapTex = new Texture2D(Width, Height, TextureFormat.DXT5, false); WatermapTex = new Texture2D(Width, Height, TextureFormat.DXT5, false); UncompressedWatermapTex = new Texture2D(WatermapTex.width, WatermapTex.height, TextureFormat.RGBA32, false); UncompressedNormalmapTex = new Texture2D(NormalmapTex.width, NormalmapTex.height, TextureFormat.RGBA32, false); WaterDataTexture = new Texture2D(Width, Height, TextureFormat.RGB24, false); Color SplatTextureColor = new Color(0, 0, 0, 0); Color[] Pixels = new Color[Width * Height]; for (int i = 0; i < Pixels.Length; i++) { Pixels[i] = SplatTextureColor; } TexturemapTex.SetPixels(Pixels); TexturemapTex2.SetPixels(Pixels); TexturemapTex.Apply(); TexturemapTex2.Apply(); Color Bump = new Color(0, 0, 1, 1); for (int i = 0; i < Pixels.Length; i++) { Pixels[i] = Bump; } UncompressedNormalmapTex.SetPixels(Pixels); PreviewTextHeader = DefaultScmapHeaders.Current.PreviewTextHeader; TextureMapHeader = DefaultScmapHeaders.Current.TextureMapHeader; TextureMap2Header = DefaultScmapHeaders.Current.TextureMap2Header; NormalmapHeader = DefaultScmapHeaders.Current.NormalmapHeader; WatermapHeader = DefaultScmapHeaders.Current.WatermapHeader; TerrainTypeData = new byte[Height * Width]; // TerrainTypeData = new List<byte>(); HeightmapData = new ushort[(Height + 1) * (Width + 1)]; WaterDepthBiasMask = new byte[(Height * Width) / 4]; WaterFlatnessMask = new byte[(Height * Width) / 4]; WaterFoamMask = new byte[(Height * Width) / 4]; for (int i = 0; i < WaterDepthBiasMask.Length; i++) { WaterDepthBiasMask[i] = 127; WaterFlatnessMask[i] = 255; WaterFoamMask[i] = 0; } float HeightConversion = InitialHeight / 25.6f; HeightConversion /= 10f; ushort InitialHeightValue = (ushort)((HeightConversion * HeightResize) + 0.5f); Debug.Log(InitialHeightValue); for (int i = 0; i < HeightmapData.Length; i++) { HeightmapData[i] = InitialHeightValue; } //Version VersionMajor = 2; VersionMinor = 56; HeightScale = 0.0078125f; TexPathBackground = "/textures/environment/blackbackground.dds"; TexPathSkyCubemap = "/textures/environment/skycube_evergreen01a.dds"; EnvCubemapsName = new string[3]; EnvCubemapsFile = new string[3]; EnvCubemapsName[0] = "<aeon>"; EnvCubemapsName[1] = "<default>"; EnvCubemapsName[2] = "<seraphim>"; EnvCubemapsFile[0] = "/textures/environment/envcube_aeon_evergreen.dds"; EnvCubemapsFile[1] = "/textures/environment/envcube_evergreen01a.dds"; EnvCubemapsFile[2] = "/textures/environment/envcube_seraphim_evergreen.dds"; Bloom = 0.03f; // 0.145f; TerrainShader = "TTerrain"; LightingMultiplier = 1.54f; SunDirection = new Vector3(0.616f, 0.559f, 0.55473f).normalized; SunAmbience = Vector3.zero; SunColor = new Vector3(1.38f, 1.29f, 1.14f); ShadowFillColor = new Vector3(0.54f, 0.54f, 0.7f); SpecularColor = new Vector4(0.31f, 0, 0, 0); FogColor = new Vector3(0.37f, 0.49f, 0.45f); FogStart = 0; FogEnd = 750; Unknown10 = -1091567891; Unknown11 = 2; Unknown12 = 0; Unknown7 = 13153; Unknown8 = 4; Unknown14 = -8.3f; Unknown15 = 0; WaveGenerators = new List <WaveGenerator>(); Layers = new List <Layer>(); { // 0 Layer NewLayer = new Layer(); NewLayer.PathTexture = "/env/evergreen2/layers/eg_gravel005_albedo.dds"; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 8.75f; Layers.Add(NewLayer); // 1 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 2 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 3 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 4 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 5 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 6 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 7 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 8 NewLayer = new Layer(); NewLayer.PathTexture = ""; NewLayer.PathNormalmap = "/env/tundra/layers/tund_sandlight_normal.dds"; NewLayer.ScaleTexture = 4; NewLayer.ScaleNormalmap = 4; Layers.Add(NewLayer); // 9 NewLayer = new Layer(); NewLayer.PathTexture = "/env/evergreen/layers/macrotexture000_albedo.dds"; NewLayer.PathNormalmap = ""; NewLayer.ScaleTexture = 128; NewLayer.ScaleNormalmap = 1; Layers.Add(NewLayer); } Decals = new List <Decal>(); DecalGroups = new List <IntegerGroup>(); Water = new WaterShader(); Water.Defaults(); Water.HasWater = _Water; Water.Elevation = WaterLevel; Water.ElevationDeep = DepthLevel; Water.ElevationAbyss = AbyssLevel; //Unknown Values Unknown8 = 0; Unknown10 = -1091567891; Unknown11 = 2; Unknown12 = 0; Unknown13 = 0; Unknown14 = 0; Unknown15 = 0; //Minimap Colors (Default) MinimapContourInterval = 24; MinimapDeepWaterColor = new Color(71, 140, 181); MinimapContourColor = new Color(112, 112, 112); MinimapShoreColor = new Color(140, 201, 224); MinimapLandStartColor = new Color(117, 99, 107); MinimapLandEndColor = new Color(206, 206, 176); }
private bool RenderScene() { // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; #region Render Ground Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 1f, 0f, out worldMatrix); // Put the ground model vertex and index buffers on the graphics pipeline to prepare them for drawing. GroundModel.Render(D3D.DeviceContext); // Render the ground model using the light shader. if (!LightShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Wall Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 6f, 8f, out worldMatrix); // Put the wall model vertex and index buffers on the graphics pipeline to prepare them for drawing. WallModel.Render(D3D.DeviceContext); // Render the wall model using the light shader. if (!LightShader.Render(D3D.DeviceContext, WallModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, WallModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Bath Model // Translate to where the bath model will be rendered. Matrix.Translation(0f, 2f, 0f, out worldMatrix); // Put the bath model vertex and index buffers on the graphics pipeline to prepare them for drawing. BathModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!LightShader.Render(D3D.DeviceContext, BathModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, BathModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Water Model // Get the camera reflection view matrix. var reflectionMatrix = Camera.ReflectionViewMatrix; // Translate to where the water model will be rendered. Matrix.Translation(0f, WaterHeight, 0f, out worldMatrix); // Put the water model vertex and index buffers on the graphics pipeline to prepare them for drawing. WaterModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, RenderReflectionTexture.ShaderResourceView, RenderRefractionTexture.ShaderResourceView, WaterModel.TextureCollection.Select(item => item.TextureResource).First(), WaterTranslation, 0.1f)) // was 0.01f for scale originally. { return(false); } #endregion return(true); }
static void Main(string[] args) { Window w = new Window(1920, 1080); EngineCore.AddImage("default.png", "default"); DefaultShader ds = new DefaultShader("default.vert", "default.frag"); String defaultShader = EngineCore.AddShader(ds, "Default"); GUIShader gui = new GUIShader("gui.vert", "gui.frag"); String guiShader = EngineCore.AddShader(gui, "GUI"); WaterShader water = new WaterShader("water.vert", "water.frag"); String waterShader = EngineCore.AddShader(water, "Water"); SkyboxShader skybox = new SkyboxShader("skybox.vert", "skybox.frag"); String skyboxShader = EngineCore.AddShader(skybox, "Skybox"); ShadowShader shadow = new ShadowShader("shadow.vert", "shadow.frag"); String shadowShader = EngineCore.AddShader(shadow, "Shadow"); TerrainShader terrain = new TerrainShader("terrain.vert", "terrain.frag"); String terrainShader = EngineCore.AddShader(terrain, "Terrain"); String cubeModel = EngineCore.AddModel("cubeything.obj", "cube"); String terrainModel = EngineCore.AddModel("terrain.obj", "terrain"); String quad = EngineCore.AddModel("quad.obj", "Quad"); String cubeObj = EngineCore.AddModel("cube.obj", "Cube"); EngineCore.AddModel("tree.obj", "tree"); EngineCore.AddModel("rock.obj", "rock"); Light l = new Light(new Vector3(0, 3, 0), System.Drawing.Color.White); ds.lights.Add(l); terrain.lights.Add(l); Light l2 = new Light(new Vector3(0, 10, 0), System.Drawing.Color.White); water.lights.Add(l2); EngineCore.AddImage("tree.png", "treeImg"); EngineCore.AddImage("rock.png", "rockImg"); String boatObj = EngineCore.AddModel("boat.obj", "Boat"); EngineCore.AddImage("boards.jpg", "Boards"); Boat boat = new Boat(new Vector3(2, 0.2f, 2), new Vector3(0, 34, 0), new Vector3(0.25f, 0.25f, 0.25f), "Boards"); EngineCore.AddObject("Boat", boat); String ground = EngineCore.AddImage("grass.jpg", "Ground"); Terrain terrainObj = new Terrain("New Terrain", "Ground", "heightMap.png"); EngineCore.AddObject("Terrain", terrainObj); EngineCore.AddImage("dudv.png", "DuDvMap"); EngineCore.AddImage("normal.png", "NormalMap"); Water waterObj = new Water(new Vector3(0, 0.25f, 0), System.Drawing.Color.Blue, new Vector2(1920, 1080), "DuDvMap", new Vector3(10, 10, 10)); waterObj.AttachNormalMap("NormalMap"); EngineCore.AddObject("water", waterObj); EngineCore.AddSkybox(new string[] { "Skybox/xpos.png", "Skybox/xneg.png", "Skybox/ypos.png", "Skybox/yneg.png", "Skybox/zpos.png", "Skybox/zneg.png" }, "Skybox", 500); w.Run(); }
private void Unbind() { GL.DisableVertexAttribArray(0); GL.BindVertexArray(0); WaterShader.stop(); }