public override void DrawModelWithEffect(Matrix world, Matrix view, Matrix projection, TextureCube reflectionTexture, Vector3 cameraPosition) { RasterizerState previous = _device.RasterizerState; _device.RasterizerState = RasterizerState.CullCounterClockwise; foreach (ModelMesh mesh in _model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = _effect; // Basic _effect.Parameters["Projection"].SetValue(projection); _effect.Parameters["View"].SetValue(view); _effect.Parameters["World"].SetValue((world * _localWorld) * mesh.ParentBone.Transform * Matrix.CreateTranslation(_position)); // Specular _effect.Parameters["ViewVector"].SetValue(Matrix.Invert(view).Translation); // Bump _effect.Parameters["NormalMap"].SetValue(normalmap); // Reflection _effect.Parameters["ReflectionTexture"].SetValue(reflectionTexture); _effect.Parameters["CameraPosition"].SetValue(cameraPosition); // Fog _effect.Parameters["FogColor"].SetValue(Color.Gray.ToVector3()); _effect.Parameters["FogEnd"].SetValue(30f); _effect.Parameters["FogStart"].SetValue(20f); // Other _effect.Parameters["TextureColorDefault"].SetValue(Color.Gray.ToVector4()); _effect.Parameters["AmbientLightColor"].SetValue(Color.Gold.ToVector3()); } mesh.Draw(); } _device.RasterizerState = previous; }
void game_InitializeEvent(object sender, EventArgs e) { Matrix mWaterWorld = Matrix.Identity;// r* t; /*-------------------------------------------------------------------------- * Create the water and fill in the info structure *--------------------------------------------------------------------------*/ WaterInfoTest info = new WaterInfoTest(); info.fxFilename = System.Windows.Forms.Application.StartupPath + @"\Shaders\Water.fx"; info.vertRows = 513; info.vertCols = 513; info.dx = 5.25f; //spaccing of grid lines - big distance info.dz = 5.25f; //info.dx = 0.5f; // small distance //info.dz = 0.5f; info.waveMapFileName0 = System.Windows.Forms.Application.StartupPath + @"\Content\wave0.dds"; info.waveMapFileName1 = System.Windows.Forms.Application.StartupPath + @"\Content\wave1.dds"; info.waveNMapVelocity0 = new Vector2(0.03f, 0.05f); info.waveNMapVelocity1 = new Vector2(-0.01f, 0.03f); info.texScale = 24.0f; info.toWorld = mWaterWorld; TextureCube mEnvMap = TextureCube.FromFile(game.GraphicsDevice, System.Windows.Forms.Application.StartupPath + @"\Content\EnvMap.dds"); water = new Water(game, info, mEnvMap); //mWaterColor = new ColorValue( ( 255 * .13f ), ( 255 * .19f ), ( 255 * .22f ) ); //use a sky model with a Hoffman-Preethem scattering method //mSkyModel = new SkyModel( 2000, mGDevice, typeof( Hoffman_Preethem ), mTerrain.Textures ); //mGlarePostProcess = new GlarePostProcess( mGDevice, mGDevice.Viewport.Width, mGDevice.Viewport.Height ); //mEnablePostProcess = true; }
private void RenderHiDef(TextureCube texture, Matrix orientation, float exposure, RenderContext context) { var graphicsDevice = context.GraphicsService.GraphicsDevice; var savedRenderState = new RenderStateSnapshot(graphicsDevice); graphicsDevice.RasterizerState = RasterizerState.CullNone; graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; graphicsDevice.BlendState = BlendState.Opaque; var cameraNode = context.CameraNode; Matrix view = cameraNode.View; Matrix projection = cameraNode.Camera.Projection; // Cube maps are left handed --> Sample with inverted z. (Otherwise, the // cube map and objects or texts in it are mirrored.) var mirrorZ = Matrix.CreateScale(1, 1, -1); _parameterWorldViewProjection.SetValue( (Matrix)(projection * view * new Matrix(orientation, Vector3.Zero) * mirrorZ)); _parameterExposure.SetValue(new Vector4(exposure, exposure, exposure, 1)); _textureParameter.SetValue(texture); if (context.IsHdrEnabled()) { _passLinear.Apply(); } else { _passGamma.Apply(); } _submesh.Draw(); savedRenderState.Restore(); }
public void Draw(Scene scene, Matrix world, Matrix view, Matrix projection, TextureCube reflectionTexture, Vector3 cameraPosition, RenderPass pass) { foreach (AbstractEntity entity in scene.Entities) { entity.Draw(world, view, projection, reflectionTexture, cameraPosition, pass); } }
public SkyModel(Game1 game, Model model, TextureCube Texture) : base(game, model) { effect = game.Content.Load <Effect>("skysphere_effect"); effect.Parameters["CubeMap"].SetValue(Texture); SetModelEffect(effect, false); }
public Skybox(string skyboxTexture, ContentManager Content) { skyBox = Content.Load <Model>("SkyboxImages/cube"); skyBoxTexture = Content.Load <TextureCube>(skyboxTexture); skyBoxEffect = Content.Load <Effect>("SkyboxShaders/Skybox"); }
/// <summary> /// PX, NX, PY, NY, PZ, NZ /// </summary> /// <param name="textures"></param> /// <returns></returns> public static TextureCube CreateCubeMap(Texture2D[] textures) { if (textures.Length != 6) { throw new Exception($"Can't create the CubeMap, 6 textures required, {textures.Length} provided."); } var width = textures[0].Width; var height = textures[0].Height; var cubeMap = new TextureCube(Application.GraphicsDevice, width, false, SurfaceFormat.Color); var textureData = new Color[width * height]; for (var i = 0; i < 6; i++) { if (textures[i].Width != width || textures[i].Height != height) { throw new Exception($"The size of the texture at index {i} have not the same size of the first texture. {width}x{height} required."); } textures[i].GetData <Color>(textureData); cubeMap.SetData <Color>((CubeMapFace)i, textureData); } return(cubeMap); }
public Reflection(ContentManager Content) { sphere = Content.Load <Model>("Models/UntexturedSphere"); //skyBoxTexture = Content.Load<TextureCube>("Skybox/EmptySpace"); skyBoxTexture = Content.Load <TextureCube>("Skybox/my_sky"); reflection = Content.Load <Effect>("Shaders/Reflection"); }
/// <summary> /// Renders a skybox. /// </summary> /// <param name="texture">The cube map with the sky texture.</param> /// <param name="orientation">The orientation of the skybox.</param> /// <param name="exposure">The exposure factor that is multiplied to the cube map values to change the brightness. /// (Usually 1 or higher).</param> /// <param name="context"> /// The render context. (<see cref="RenderContext.CameraNode"/> needs to be set.) /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="texture"/> or <paramref name="context"/> is <see langword="null"/>. /// </exception> public void Render(TextureCube texture, Matrix orientation, float exposure, RenderContext context) { if (texture == null) { throw new ArgumentNullException("texture"); } if (context == null) { throw new ArgumentNullException("context"); } context.Validate(_effect); context.ThrowIfCameraMissing(); var graphicsDevice = context.GraphicsService.GraphicsDevice; if (graphicsDevice.GraphicsProfile == GraphicsProfile.Reach) { RenderReach(texture, orientation, exposure, context); } else { RenderHiDef(texture, orientation, exposure, context); } }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Model = Content.Load <Model>("redtorus"); ModelPosition = Vector3.Zero; projectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, 4.0f / 3.0f, 1.0f, 10000f); // Load the effect, the texture it uses, and // the model used for drawing it SkySphereEffect = Content.Load <Effect>("SkySphere"); TextureCube SkyboxTexture = Content.Load <TextureCube>("uffizi_cross"); SkySphere = Content.Load <Model>("SphereHighPoly"); // Set the parameters of the effect SkySphereEffect.Parameters["ViewMatrix"].SetValue( myCamera.ViewMatrix); SkySphereEffect.Parameters["ProjectionMatrix"].SetValue( projectionMatrix); SkySphereEffect.Parameters["SkyboxTexture"].SetValue( SkyboxTexture); // Set the Skysphere Effect to each part of the Skysphere model foreach (ModelMesh mesh in SkySphere.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = SkySphereEffect; } } }
public void Draw(GameTime gameTime, ICamera cam, TextureCube skyTexture, Matrix proj) { // start the shader //oceanEffect.Begin(); //oceanEffect.CurrentTechnique.Passes[0].Begin(); // set the transforms oceanEffect.Parameters["World"].SetValue(Matrix.Identity); oceanEffect.Parameters["View"].SetValue(cam.CameraMatrix); oceanEffect.Parameters["Projection"].SetValue(proj); oceanEffect.Parameters["EyePos"].SetValue(cam.Position); // choose and set the ocean textures int oceanTexIndex = ((int)(gameTime.TotalGameTime.TotalSeconds) % 4); oceanEffect.Parameters["normalTex"].SetValue(OceanNormalMaps[(oceanTexIndex + 1) % 4]); oceanEffect.Parameters["normalTex2"].SetValue(OceanNormalMaps[(oceanTexIndex) % 4]); oceanEffect.Parameters["textureLerp"].SetValue((((((float)gameTime.TotalGameTime.TotalSeconds) - (int)(gameTime.TotalGameTime.TotalSeconds)) * 2 - 1) * 0.5f) + 0.5f); // set the time used for moving waves oceanEffect.Parameters["time"].SetValue((float)gameTime.TotalGameTime.TotalSeconds * 0.02f); // set the sky texture oceanEffect.Parameters["cubeTex"].SetValue(skyTexture); //oceanEffect.CommitChanges(); oceanEffect.CurrentTechnique.Passes[0].Apply(); // draw our geometry //Global.Graphics.VertexDeclaration = OceanVD; Global.Graphics.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, OceanVerts, 0, 2); // and we're done! //oceanEffect.CurrentTechnique.Passes[0].End(); //oceanEffect.End(); }
public override void LoadContent() { base.LoadContent(); _model = Game.Content.Load <Model>("Background/cube"); _textureCube = Game.Content.Load <TextureCube>("Background/Sunset"); LoadMesh(_model, "Shader_background"); }
public TextureCube Generate(Texture2D equirectangularTexture) { // I don't seem to have problems with 'Pre-filter convolution artifacts' but in case of // problems check that section: https://learnopengl.com/PBR/IBL/Specular-IBL this.Device.BlendState = BlendState.Opaque; this.Device.DepthStencilState = DepthStencilState.None; this.Device.RasterizerState = RasterizerState.CullCounterClockwise; this.Device.SamplerStates[0] = SamplerState.LinearClamp; this.Effect.EquirectangularTexture = equirectangularTexture; this.Effect.EquirectangularTextureSampler = SamplerState.LinearClamp; var cubeMap = new TextureCube(this.Device, resolution, true, SurfaceFormat.HalfVector4); var mipResolution = resolution; for (var mipMapLevel = 0; mipMapLevel < cubeMap.LevelCount; mipMapLevel++) { var roughness = mipMapLevel / (cubeMap.LevelCount - 1.0f); this.Effect.Roughness = roughness; CubeMapUtilities.RenderFaces(this.Device, cubeMap, mipResolution, SurfaceFormat.HalfVector4, mipMapLevel, this.Apply); mipResolution /= 2; } return(cubeMap); }
public SkyModel(Game1 game, Model model, TextureCube Texture) : base(game,model) { effect = game.Content.Load<Effect>("skysphere_effect"); effect.Parameters["CubeMap"].SetValue(Texture); SetModelEffect(effect, false); }
public void Load(ContentManager contentManager) { _contentManager = new ThreadSafeContentManager(contentManager.ServiceProvider) { RootDirectory = "Content" }; rollTexture2D = _contentManager.Load <Texture2D>("Graphical User Interface/ring"); skyboxCube = _contentManager.Load <TextureCube>("ShaderModules/Skybox/skyboxCubemap"); fresnelMap = _contentManager.Load <Texture>("ShaderModules/AnimatedModelShader/fresnel2"); model = _contentManager.Load <Model>("ShaderModules/Skybox/isosphere" /*"ShaderModules/AnimatedModelShader/cube"*/); _skyboxRenderModule = new SkyboxRenderModule(); _skyboxRenderModule.Load(_contentManager, "ShaderModules/Skybox/skybox", "ShaderModules/Skybox/isosphere"); _skyboxRenderModule.SetSkybox(skyboxCube); _animatedModelShader = new AnimatedModelShader(); _animatedModelShader.Load(_contentManager, "ShaderModules/AnimatedModelShader/AnimatedModelShader"); _animatedModelShader.EnvironmentMap = skyboxCube; _animatedModelShader.FresnelMap = fresnelMap; int test = 1024; int level = 7; int outp = test >> level; _ambientOcclusionShader = new AmbientOcclusionShader(); _ambientOcclusionShader.Load(_contentManager, "ShaderModules/AmbientOcclusionShader/AmbientOcclusionShader"); }
public void Read() { // Console.WriteLine ( "Thread:" + System.Threading.Thread.CurrentThread.Name + // System.Threading.Thread.CurrentThread ); Diff = Help.IOHelp.ReadVec3(); Spec = Help.IOHelp.ReadVec3(); Shine = Help.IOHelp.ReadFloat(); if (Help.IOHelp.ReadBool()) { ColorMap = new Texture2D(); ColorMap.Read(); } if (Help.IOHelp.ReadBool()) { NormalMap = new Texture2D(); NormalMap.Read(); } if (Help.IOHelp.ReadBool()) { SpecularMap = new Texture2D(); SpecularMap.Read(); } if (Help.IOHelp.ReadBool()) { ExtraMap = new Texture2D(); ExtraMap.Read(); } if (Help.IOHelp.ReadBool()) { var path = Help.IOHelp.ReadString(); EnvironmentMap = new TextureCube(path); } }
private void DrawModel(RenderEffectTechniques technique, Model model, Matrix world, IViewPoint viewPoint) { var bones = model.Bones.Count; if (SharedBoneMatrix is null || SharedBoneMatrix.Length < bones) { SharedBoneMatrix = new Matrix[bones]; } model.CopyAbsoluteBoneTransformsTo(SharedBoneMatrix); for (var iMesh = 0; iMesh < model.Meshes.Count; iMesh++) { var mesh = model.Meshes[iMesh]; for (var iEffect = 0; iEffect < mesh.Effects.Count; iEffect++) { var effect = mesh.Effects[iEffect]; this.Effect.Wrap(effect); this.Effect.World = SharedBoneMatrix[mesh.ParentBone.Index] * world; this.Effect.View = viewPoint.View; this.Effect.Projection = viewPoint.Projection; this.Effect.InverseViewProjection = InverseViewProjection; this.Effect.Skybox = this.Skybox; this.Effect.CameraPosition = viewPoint.Position; this.Effect.Apply(technique); } mesh.Draw(); } }
public bool Bake(TextureCube texture, RenderWrap renderWrap, ref object tag) { var tex = renderWrap.GetTex2D(Source); if (tex == null || tex.Status != GraphicsObjectStatus.loaded) { return(false); } renderWrap.SetRootSignature("Csu"); int width = texture.width; int height = texture.height; var writer = renderWrap.Writer; writer.Write(width); writer.Write(height); writer.SetCBV(0); renderWrap.SetSRVs(new string[] { Source }); renderWrap.SetUAV(texture, 0, 0); renderWrap.Dispatch("ConvertToCube.hlsl", null, width / 8, height / 8, 6); for (int i = 1; i < texture.mipLevels; i++) { int mipPow = 1 << i; renderWrap.SetSRVLim(texture, i - 1, 0); renderWrap.SetUAV(texture, i, 0); writer.Write(width / mipPow); writer.Write(height / mipPow); writer.Write(i - 1); writer.SetCBV(0); renderWrap.Dispatch("GenerateCubeMipMap.hlsl", null, width / mipPow / 8, height / mipPow / 8, 6); } return(true); }
protected override void LoadContent() { cube = Game.Content.Load <Model>(@"Models\cube"); texture = Game.Content.Load <TextureCube>(pathToTexture); effect = Game.Content.Load <Effect>(@"Effects\Skybox"); base.LoadContent(); }
/// <summary> /// Initializes a new instance of the <see cref="SkyboxNode" /> class. /// </summary> /// <param name="texture">The cube map texture (using premultiplied alpha).</param> public SkyboxNode(TextureCube texture) { Texture = texture; Color = new Vector3F(1, 1, 1); Alpha = 1.0f; Encoding = ColorEncoding.SRgb; }
/// <summary> /// Creates a reflection textureCube /// </summary> static TextureCube GetReflectCube() { if (reflectCube != null) { return(reflectCube); } Color[] cc = new Color[] { new Color(1, 0, 0), new Color(0.9f, 0, 0.1f), new Color(0.8f, 0, 0.2f), new Color(0.7f, 0, 0.3f), new Color(0.6f, 0, 0.4f), new Color(0.5f, 0, 0.5f), new Color(0.4f, 0, 0.6f), new Color(0.3f, 0, 0.7f), new Color(0.2f, 0, 0.8f), new Color(0.1f, 0, 0.9f), new Color(0.1f, 0, 0.9f), new Color(0.0f, 0, 1.0f), }; reflectCube = new TextureCube(ShipGameGame.GetInstance().GraphicsDevice, 8, true, SurfaceFormat.Color); Random rand = new Random(); for (int s = 0; s < 6; s++) { Color[] sideData = new Color[reflectCube.Size * reflectCube.Size]; for (int i = 0; i < sideData.Length; i++) { sideData[i] = cc[rand.Next(cc.Length)]; } reflectCube.SetData((CubeMapFace)s, sideData); } return(reflectCube); }
public static Texture BeginGetTempTexture(Type type) { if (type == typeof(Texture)) type = typeof(Texture2D); for (int i = 0; i < textureCache.Count; i++) { if (textureCache[i].GetType() == type) { Texture t = textureCache[i]; textureCache.RemoveAt(i); return t; } } //create. SurfaceFormat format = SurfaceFormat.HalfSingle; Texture texture = null; if (type == typeof(Texture2D)) texture = new Texture2D(GraphicsDevice, 2, 2, false, format); if (type == typeof(Texture3D)) texture = new Texture3D(GraphicsDevice, 2, 2, 2, false, format); if (type == typeof(TextureCube)) texture = new TextureCube(GraphicsDevice, 2, false, format); return texture; }
public override void Load(XmlElement xmlNode) { base.Load(xmlNode); if (xmlNode.HasAttribute("NormalMapTextureName")) { String normalMapTextureName = xmlNode.GetAttribute("NormalMapTextureName"); normalMapTexture = State.Content.Load <Texture2D>(normalMapTextureName); } if (xmlNode.HasAttribute("FresnelBias")) { fresnelBias = float.Parse(xmlNode.GetAttribute("FresnelBias")); } if (xmlNode.HasAttribute("FresnelPower")) { fresnelPower = float.Parse(xmlNode.GetAttribute("FresnelPower")); } if (xmlNode.HasAttribute("ReflectionAmount")) { reflectAmount = float.Parse(xmlNode.GetAttribute("ReflectionAmount")); } if (xmlNode.HasAttribute("EnvironmentMapTextureName")) { String envMapName = xmlNode.GetAttribute("EnvironmentMapTextureName"); envMap = State.Content.Load <TextureCube>(envMapName); } }
public ShadowMapSystem( GraphicsDevice device, IComponentContainer <ShadowMap> shadowMaps, IComponentContainer <CascadedShadowMap> cascadedShadowMaps, ModelSystem modelSystem, IMeterRegistry meterRegistry) { this.Device = device; this.ShadowMaps = shadowMaps; this.CascadedShadowMaps = cascadedShadowMaps; this.ModelSystem = modelSystem; this.MeterRegistry = meterRegistry; this.MeterRegistry.CreateGauge(ShadowMapCounter); this.MeterRegistry.CreateGauge(ShadowMapTotal); this.MeterRegistry.CreateGauge(ShadowMapStep, "step"); this.NullSkybox = new TextureCube(device, 1, false, SurfaceFormat.Color); this.NullSkybox.SetData(CubeMapFace.PositiveX, new Color[] { Color.White }); this.NullSkybox.SetData(CubeMapFace.NegativeX, new Color[] { Color.White }); this.NullSkybox.SetData(CubeMapFace.PositiveY, new Color[] { Color.White }); this.NullSkybox.SetData(CubeMapFace.NegativeY, new Color[] { Color.White }); this.NullSkybox.SetData(CubeMapFace.PositiveZ, new Color[] { Color.White }); this.NullSkybox.SetData(CubeMapFace.NegativeZ, new Color[] { Color.White }); }
/// <summary> /// Creates a new SkyBox /// </summary> /// <param name="model">The geometry to use for SkyBox.</param> /// <param name="texture">The SkyBox texture to use.</param> /// <param name="effect">The SkyBox fx to use.</param> /// <param name="size">The SkyBox fx to use.</param> public SkyBox(Model model, TextureCube texture, Effect effect, float size) { Model = model; Texture = texture; Effect = effect; Size = size; }
public override void LoadContent() { base.LoadContent(); // To hacked for now if (!_environmentTextureLoaded && _environmentTextureNames != null) { // Detect the texture size if it doesn't specified if (_environmentTextureSize == 0) { Texture2D firstTexture = YnG.Content.Load <Texture2D>(_environmentTextureNames[0]); _environmentTextureSize = Math.Min(firstTexture.Width, firstTexture.Height); } // Create the environment texture _environmentTexture = new TextureCube(YnG.GraphicsDevice, _environmentTextureSize, _enableTextureMipmap, SurfaceFormat.Color); Texture2D texture = null; // Temp texture Color[] textureData; // Temp textureData array string[] tempTextureNames = new string[6]; // If the texture array has not a size of 6, we replace empty texture by the latest int nbTextures = _environmentTextureNames.Length; for (int i = 0; i < 6; i++) { if (i < nbTextures) // Texture { tempTextureNames[i] = _environmentTextureNames[i]; } else // Copied texture { tempTextureNames[i] = _environmentTextureNames[nbTextures - 1]; } // Load the texture and add it to the TextureCube texture = YnG.Content.Load <Texture2D>(tempTextureNames[i]); textureData = new Color[texture.Width * texture.Height]; texture.GetData <Color>(textureData); _environmentTexture.SetData <Color>((CubeMapFace)i, textureData); } // Update the texture names array _environmentTextureNames = tempTextureNames; _environmentTextureLoaded = true; // If the first texture is null we create a dummy texture with the same size of environment texture if (_texture == null) { _texture = YnGraphics.CreateTexture(Color.White, _environmentTextureSize, _environmentTextureSize); _textureLoaded = true; } } if (!_effectLoaded) { _effect = new EnvironmentMapEffect(YnG.GraphicsDevice); _effectLoaded = true; } }
protected override void freeInternalResources() { if (_texture != null) { _texture.Dispose(); _texture = null; } if (_normTexture != null) { _normTexture.Dispose(); _normTexture = null; } if (_cubeTexture != null) { _cubeTexture.Dispose(); _cubeTexture = null; } #if !SILVERLIGHT if (_volumeTexture != null) { _volumeTexture.Dispose(); _volumeTexture = null; } #endif }
public void Draw(GameTime gameTime, TextureCube skyTexture) { var graphicsDevice = _graphicsDevice; graphicsDevice.RasterizerState = new RasterizerState { FillMode = FillMode.Solid }; graphicsDevice.SetVertexBuffer(_vertexBuffer); graphicsDevice.Indices = _indexBuffer; _oceanEffect.Parameters["World"].SetValue(GetWorldMatrix()); _oceanEffect.Parameters["View"].SetValue(_camera.ViewMatrix); _oceanEffect.Parameters["Projection"].SetValue(_camera.ProjectionMatrix); _oceanEffect.Parameters["EyePos"].SetValue(_camera.Position); // set the sky texture //_oceanEffect.Parameters["cubeTex"].SetValue(skyTexture); // choose and set the ocean textures var oceanTexIndex = (int)gameTime.TotalGameTime.TotalSeconds % 4; _oceanEffect.Parameters["normalTex"].SetValue(OceanNormalMaps[0]); _oceanEffect.Parameters["normalTex2"].SetValue(OceanNormalMaps[3]); _oceanEffect.Parameters["textureLerp"].SetValue(0.5f); _oceanEffect.Parameters["time"].SetValue((float)gameTime.TotalGameTime.TotalSeconds * 0.02f); _oceanEffect.CurrentTechnique = _oceanEffect.Techniques["Ocean"]; _oceanEffect.CurrentTechnique.Passes[0].Apply(); //foreach (var pass in _oceanEffect.CurrentTechnique.Passes) //{ // pass.Apply(); //var primitiveCount = _indices.Count / 3; graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _vertices.ToArray(), 0, 2); //} }
public void Generate(GraphicsDevice device, ContentManager content, Texture2D[] textures, float size = 250.0f) { if (textures.Length != 6) { throw new Exception("The array of texture names must contains 6 elements."); } if (SkyboxEffect == null) { SkyboxEffect = content.Load <Effect>("FX/SkyboxEffect"); } _geometry.Size = new Vector3(size); _geometry.Build(); _texture = new TextureCube(device, textures[0].Width, false, SurfaceFormat.Color); Color[] textureData; for (int i = 0; i < 6; i++) { textureData = new Color[textures[i].Width * textures[i].Height]; textures[i].GetData <Color>(textureData); _texture.SetData <Color>((CubeMapFace)i, textureData); } Enabled = true; }
public override void Initialize(Microsoft.Xna.Framework.Content.ContentManager contentLoader, ComponentManifest manifest) { SkyTexture = contentLoader.Load<TextureCube>((string)(manifest.Properties[ManifestKeys.TEXTURE])); OnEnvironmentMapAdded(EventArgs.Empty); base.Initialize(contentLoader, manifest); }
private void SetFaceData(TextureCube cube, CubeMapFace face, Texture2D data) { var colors = new Color[data.Width * data.Height]; data.GetData(colors); cube.SetData(face, colors); }
// loads new skybox content public Enviroment(string skyboxTexture, ContentManager Content) { skyBox = Content.Load<Model>("Models/skyboxCube"); skyBoxTexture = Content.Load<TextureCube>("Effects/Sunset"); skyBoxEffect = Content.Load<Effect>("Effects/Skybox"); terrain = Content.Load<Model>("Models/desert"); }
public Skybox(string[] skyboxTextures, ContentManager Content, GraphicsDevice g) { skyBox = Content.Load <Model>("skybox/cube"); skyBoxEffect = Content.Load <Effect>("Skybox"); skyBoxTexture = new TextureCube(g, 512, false, SurfaceFormat.Color); byte[] data = new byte[512 * 512 * 4]; Texture2D tempTexture = Content.Load <Texture2D>(skyboxTextures[0]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.PositiveX, data); tempTexture = Content.Load <Texture2D>(skyboxTextures[1]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.NegativeX, data); tempTexture = Content.Load <Texture2D>(skyboxTextures[2]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.PositiveY, data); tempTexture = Content.Load <Texture2D>(skyboxTextures[3]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.NegativeY, data); tempTexture = Content.Load <Texture2D>(skyboxTextures[4]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.PositiveZ, data); tempTexture = Content.Load <Texture2D>(skyboxTextures[5]); tempTexture.GetData <byte>(data); skyBoxTexture.SetData <byte>(CubeMapFace.NegativeZ, data); }
public override void LoadContent(ContentManager Content, GraphicsDeviceManager graphics, SpriteBatch spriteBatch) { myEffect = Content.Load <Effect>("HomeWork3"); day = Content.Load <Texture2D>("day"); night = Content.Load <Texture2D>("night"); clouds = Content.Load <Texture2D>("clouds"); moon = Content.Load <Texture2D>("2k_moon"); sky = Content.Load <TextureCube>("sky_cube"); sphere = Content.Load <Model>("uv_sphere"); foreach (ModelMesh mesh in sphere.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { meshPart.Effect = myEffect; } } cube = Content.Load <Model>("cube"); foreach (ModelMesh mesh2 in cube.Meshes) { foreach (ModelMeshPart meshPart in mesh2.MeshParts) { meshPart.Effect = myEffect; } } }
public void Test() { var device = GraphicsDevice.New(); // Compile a toolkit effect from a file var result = EffectCompiler.CompileFromFile("toto.fx"); // Check that we don't have any errors Assert.False(result.HasErrors); var bytecode = result.EffectData; var effect = new Effect(device, bytecode); var tex1 = TextureCube.New(device, 64, PixelFormat.R8.UNorm); var samplerState = device.SamplerStates.PointWrap; effect.Parameters["SkyBoxTexture"].SetResource(tex1); effect.Parameters["SkyBoxSampler"].SetResource(samplerState); effect.Techniques[0].Passes[0].Apply(); Console.WriteLine(effect.Parameters.Count); effect.Dispose(); device.Dispose(); }
/// <summary> /// 加载 /// </summary> protected override void LoadContent() { // 创建一个新的SpriteBatch,可以用来抽取的纹理。 spriteBatch = new SpriteBatch(base.Game.GraphicsDevice); // Load the effect, the texture it uses, and // the model used for drawing it SkySphereEffect = base.Game.Content.Load <Effect>("SkySphere"); //TextureCube SkyboxTexture = // base.Game.Content.Load<TextureCube>("uffizi_cross"); TextureCube SkyboxTexture = base.Game.Content.Load <TextureCube>("skyboxtexture"); SkySphere = base.Game.Content.Load <Model>("SphereHighPoly"); // Set the parameters of the effect SkySphereEffect.Parameters["ViewMatrix"].SetValue(view); SkySphereEffect.Parameters["ProjectionMatrix"].SetValue(projection); SkySphereEffect.Parameters["SkyboxTexture"].SetValue(SkyboxTexture); // Set the Skysphere Effect to each part of the Skysphere model foreach (ModelMesh mesh in SkySphere.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = SkySphereEffect; } } }
/// <summary> /// Initializes a new instance of the <see cref="SkyboxNode" /> class. /// </summary> /// <param name="texture">The cube map texture (using premultiplied alpha).</param> public SkyboxNode(TextureCube texture) { Texture = texture; Color = new Vector3F(1, 1, 1); Alpha = 1.0f; Encoding = ColorEncoding.SRgb; }
/// <summary> /// Creates a new skybox /// </summary> /// <param name="skyboxTexture">the name of the skybox texture to use</param> public Skybox(string skyboxTexture, float size, ContentManager Content) { skyBox = Content.Load<Model>("Models/cube"); skyBoxTexture = Content.Load<TextureCube>("Skybox/" + skyboxTexture); skyBoxEffect = Content.Load<Effect>("Skybox/Skybox"); this.size = size; }
public static void RenderFaces(GraphicsDevice device, TextureCube cubeMap, int resolution, SurfaceFormat format, int mipMapLevel, Action <Matrix> applyEffect) { using var faceRenderTarget = new RenderTarget2D(device, resolution, resolution, false, format, DepthFormat.None, 0, RenderTargetUsage.DiscardContents); using var cube = new CubeMapCube(device); var data = new HalfVector4[resolution * resolution]; var faces = CubeMapFaces; for (var i = 0; i < faces.Count; i++) { var face = faces[i]; var view = GetViewForFace(face); var projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1.0f, 0.1f, 1.5f); device.SetRenderTarget(faceRenderTarget); device.Clear(Color.CornflowerBlue); applyEffect(view * projection); device.SetVertexBuffer(cube.VertexBuffer, 0); device.Indices = cube.IndexBuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cube.Primitives); device.SetRenderTarget(null); faceRenderTarget.GetData(data); cubeMap.SetData(face, mipMapLevel, null, data, 0, data.Length); } }
public void LoadContent(TextureCube t, Effect e) { skyEffect = e; skyTex = t; skyEffect.Parameters["tex"].SetValue(skyTex); }
public Sphere(GraphicsDevice device, Model model, Effect effect, TextureCube skyboxTexture) : base(device, Vector3.Zero, Quaternion.Identity, 1f) { this.Position = new Vector3(-2f, 1f, 0f); this.effect = effect; this.model = model; this.skyboxTexture = skyboxTexture; }
public void LoadContent(ContentManager content, GraphicsDevice gfxDevice) { skyEffect = content.Load<Effect>(@"Effects\skyEffect"); skyTexture = content.Load<TextureCube>(@"Textures\Skybox\SkyBoxTex"); skyEffect.Parameters["tex"].SetValue(skyTexture); CreateCubeVertexBuffer(gfxDevice); CreateCubeIndexBuffer(gfxDevice); }
public SkyBox(Vector3 pos, string skyboxTexture, ContentManager Content) { this.position = pos; skyBox = Content.Load<Model>("Assets/Models/Terrain/10x10x10Box1"); skyBoxTexture = Content.Load<TextureCube>(skyboxTexture); skyBoxEffect = Content.Load<Effect>("Assets/Effects/SkyBox"); // skyBoxEffect = Content.Load<Effect>("Assets/Effects/Rainfall"); }
protected override void LoadContent() { skyBox = karoGame.Content.Load<Model>("cube"); texture = karoGame.Content.Load<TextureCube>("Islands"); skyBoxEffect = karoGame.Content.Load<Effect>("SkyBox"); base.LoadContent(); }
public SkySphere( VisionContent vtContent, TextureCube texture) : base(new VisionEffect(vtContent.Load<Effect>("effects/skysphere"))) { _sphere = new SpherePrimitive<VertexPosition>(vtContent.GraphicsDevice, (p, n, t, tx) => new VertexPosition(p), 20000, 10, false); Effect.Texture = texture; }
public SkySphere(ContentManager Content, GraphicsDevice graphicsDevice, TextureCube Texture) { model = new Models(Content, Content.Load<Model>("models//skySphere"), Vector3.Zero, Vector3.Zero, new Vector3(-100000), graphicsDevice); effect = Content.Load<Effect>("shaders//SkyBox"); effect.Parameters["CubeMap"].SetValue(Texture); model.SetModelEffect(effect, false); this.graphics = graphicsDevice; }
// Creates a new skybox instance using the texture provided public Skybox(string skyboxTexture, ContentManager Content) { // Loads cube model skyBox = Content.Load<Model>("Models/cube"); // Loads texture skyBoxTexture = Content.Load<TextureCube>(skyboxTexture); // Loads fx file skyBoxEffect = Content.Load<Effect>("Effects/Skybox"); }
public void Init(Microsoft.Xna.Framework.Graphics.Model model, Effect effect, TextureCube texture) { m_model = model; m_effect = effect; m_cubemap = texture; m_scale = new Vector3(2000.0f, 2000.0f, 2000.0f); m_position = new Vector3(0.0f, -500.0f, 0.0f); }
public Skybox(GraphicsDevice device, TextureCube environment, Effect shader) { this.Environment = environment; this.Shader = shader; this.Device = device; this.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); this.VertexBuffer = new VertexBuffer(device, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly); this.IndexBuffer = new IndexBuffer(device, 36 * sizeof(ushort), BufferUsage.WriteOnly, IndexElementSize.SixteenBits); VertexPositionColor[] vertices = new VertexPositionColor[8]; vertices[0].Position = new Vector3(-1, 1, 1); vertices[1].Position = new Vector3(1, 1, 1); vertices[2].Position = new Vector3(1, 1, -1); vertices[3].Position = new Vector3(-1, 1, -1); vertices[4].Position = new Vector3(-1, -1, 1); vertices[5].Position = new Vector3(1, -1, 1); vertices[6].Position = new Vector3(1, -1, -1); vertices[7].Position = new Vector3(-1, -1, -1); this.VertexBuffer.SetData(vertices, 0, 8); vertices = null; ushort[] indices = new ushort[36]; // top indices[0] = 0; indices[1] = 1; indices[2] = 3; indices[3] = 2; indices[4] = 3; indices[5] = 1; //bottom indices[6] = 5; indices[7] = 4; indices[8] = 6; indices[9] = 7; indices[10] = 6; indices[11] = 4; // front indices[12] = 3; indices[13] = 2; indices[14] = 7; indices[15] = 6; indices[16] = 7; indices[17] = 2; // back indices[18] = 1; indices[19] = 0; indices[20] = 4; indices[21] = 4; indices[22] = 5; indices[23] = 1; // left indices[24] = 0; indices[25] = 3; indices[26] = 4; indices[27] = 4; indices[28] = 3; indices[29] = 7; // right indices[30] = 2; indices[31] = 1; indices[32] = 6; indices[33] = 5; indices[34] = 6; indices[35] = 1; this.IndexBuffer.SetData(indices, 0, 36); indices = null; }
public static void Initialize(ContentManager Content, string strEffectLocation, string strModelLocation, string strTextureLocation) { _SkyboxEffect = Content.Load<Effect>(strEffectLocation); SkyboxModel = Content.Load<Model>(strModelLocation); SkyboxTexture = Content.Load<TextureCube>(strTextureLocation); TextureOffsetX = TextureOffsetY = 0; for (int m = 0; m < SkyboxModel.Meshes.Count; m++) for (int p = 0; p < SkyboxModel.Meshes[m].MeshParts.Count; p++) SkyboxModel.Meshes[m].MeshParts[p].Effect = _SkyboxEffect; }
public Enemy(Game game, Effect effect) : base(game) { mechEffect = effect; mech = game.Content.Load<Model>("mech8"); texCube = game.Content.Load<TextureCube>("CubeMap"); effect.Parameters["cubetex"].SetValue(texCube); foreach(ModelMesh mesh in mech.Meshes) foreach (ModelMeshPart meshPart in mesh.MeshParts) meshPart.Effect = mechEffect.Clone(); }
void IResource.Destroy() { if (texture2D != null) texture2D.Dispose(); texture2D = null; if (texture3D != null) texture3D.Dispose(); texture3D = null; if (textureCube != null) textureCube.Dispose(); textureCube = null; }
public Skybox(Game game) { this.game = game; this.Position = Vector3.Zero; this.Scale = new Vector3(1, 1, 1); this.skyeffect = this.game.Content.Load<Effect>("Shaders/SkyEffect2"); this.skycube = this.game.Content.Load<TextureCube>("Skyboxes/Mountains"); this.skyeffect.Parameters["skycube"].SetValue(this.skycube); this.CreateVertices(); this.CreateIndices(); }
public Sky(ContentManager Content, GraphicsDevice GraphicsDevice, TextureCube Texture) : base(Content.Load<Model>("skysphere_mesh"), Vector3.Zero, Vector3.Zero, new Vector3(100000), GraphicsDevice) { effect = Content.Load<Effect>("skysphere_effect"); effect.Parameters["CubeMap"].SetValue(Texture); this.SetModelEffect(effect); this.graphics = GraphicsDevice; }
/// <inheritdoc/> protected override void CloneCore(Light source) { // Clone Light properties. base.CloneCore(source); Shape = source.Shape.Clone(); // Clone EnvironmentLight properties. var sourceTyped = (EnvironmentLight)source; Color = sourceTyped.Color; DiffuseIntensity = sourceTyped.DiffuseIntensity; SpecularIntensity = sourceTyped.SpecularIntensity; HdrScale = sourceTyped.HdrScale; EnvironmentMap = sourceTyped.EnvironmentMap; }
public override void DrawModelWithEffect(Matrix world, Matrix view, Matrix projection, TextureCube reflectionTexture, Vector3 cameraPosition) { foreach (var item in _effect.CurrentTechnique.Passes) { foreach (ModelMesh mesh in _model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = _effect; // Basic _effect.Parameters["Projection"].SetValue(projection); _effect.Parameters["View"].SetValue(view); _effect.Parameters["World"].SetValue((world * _localWorld) * mesh.ParentBone.Transform * Matrix.CreateTranslation(_position)); // Diffuse _effect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world))); // Specular _effect.Parameters["ViewVector"].SetValue(Matrix.Invert(view).Translation); // Textured _effect.Parameters["ModelTexture"].SetValue(_texture); // Bump _effect.Parameters["NormalMap"].SetValue(normalmap); // Reflection _effect.Parameters["SkyboxTexture"].SetValue(reflectionTexture); _effect.Parameters["CameraPosition"].SetValue(cameraPosition); // Fog _effect.Parameters["FogColor"].SetValue(Color.White.ToVector3()); _effect.Parameters["FogEnd"].SetValue(20f); _effect.Parameters["FogStart"].SetValue(10f); /*_effect.Parameters["CameraPosition"].SetValue(cameraPosition); _effect.Parameters["FogEnabled"].SetValue(true); _effect.Parameters["FogDistance"].SetValue(Vector3.Distance(_position,cameraPosition)); _effect.Parameters["FogColor"].SetValue(Color.DarkGoldenrod.ToVector4()); _effect.Parameters["FogEnd"].SetValue(30.0f); _effect.Parameters["FogStart"].SetValue(20.0f); _effect.Parameters["ReflectedTexture"].SetValue(reflectionTexture); _effect.Parameters["ModelTexture"].SetValue(_texture); _effect.Parameters["NormalMap"].SetValue(normalmap); _effect.Parameters["Projection"].SetValue(projection); _effect.Parameters["View"].SetValue(view); _effect.Parameters["ViewVector"].SetValue(view.Backward); _effect.Parameters["World"].SetValue((world * _localWorld) * mesh.ParentBone.Transform * Matrix.CreateTranslation(_position)); _effect.Parameters["WorldInverseTranspose"].SetValue( Matrix.Transpose(Matrix.Invert(world * mesh.ParentBone.Transform)));*/ } mesh.Draw(); } } }
public void Load(ContentManager content) { model = content.Load<Model>("Sphere"); texture = content.Load<TextureCube>("SunInSpace"); effect = content.Load<Effect>("SkySphere"); effect.Parameters["SurfaceTexture"].SetValue(texture); foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = effect; } } }
private void LoadContent() { skyEffect = Game.Content.Load<Effect>("SkyEffect"); skyTex = Game.Content.Load<TextureCube>("SkyBoxTex"); skyEffect.Parameters["tex"].SetValue(skyTex); SkyWorld = Matrix.Identity; View = Matrix.CreateLookAt(position, originalView, Vector3.Up); Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(Game1._fov), Game.GraphicsDevice.Viewport.AspectRatio, 1, 20); //Backreference calls CreateCubeVertexBuffer(); CreateCubeIndexBuffer(); }
/// <summary> /// Renders a skybox. /// </summary> /// <param name="texture">The cube map with the sky texture.</param> /// <param name="orientation">The orientation of the skybox.</param> /// <param name="exposure">The exposure factor that is multiplied to the cube map values to change the brightness. /// (Usually 1 or higher).</param> /// <param name="context"> /// The render context. (<see cref="RenderContext.CameraNode"/> needs to be set.) /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="texture"/> or <paramref name="context"/> is <see langword="null"/>. /// </exception> public void Render(TextureCube texture, Matrix33F orientation, float exposure, RenderContext context) { if (texture == null) throw new ArgumentNullException("texture"); if (context == null) throw new ArgumentNullException("context"); context.Validate(_effect); context.ThrowIfCameraMissing(); var graphicsDevice = context.GraphicsService.GraphicsDevice; if (graphicsDevice.GraphicsProfile == GraphicsProfile.Reach) RenderReach(texture, orientation, exposure, context); else RenderHiDef(texture, orientation, exposure, context); }
public virtual void Draw(Matrix world, Matrix view, Matrix projection, TextureCube reflectionTexture, Vector3 cameraPosition, RenderPass pass) { if (_visible) { if (_effect != null) { if (cameraPosition != null) { DrawModelWithEffect(world, view, projection, reflectionTexture, cameraPosition); } } else { DrawModel(world, view, projection, pass); } } }