public Material(Renderer renderer, Direct3D.Material material, string diffuseMapFilename) { if (renderer == null) throw new ArgumentNullException("renderer", "Cannot create a material with a null renderer reference."); this.renderer = renderer; d3dMaterial = material; diffuseMap = new Texture(renderer, diffuseMapFilename); }
public Material(Renderer renderer, string diffuseMapFilename) { if (renderer == null) throw new ArgumentNullException("renderer", "Cannot create a material with a null renderer reference."); this.renderer = renderer; d3dMaterial = new Direct3D.Material(); d3dMaterial.Ambient = DefaultAmbientColor; d3dMaterial.Diffuse = DefaultDiffuseColor; d3dMaterial.Specular = DefaultSpecularColor; d3dMaterial.SpecularSharpness = DefaultShininess; diffuseMap = new Texture(this.renderer, diffuseMapFilename); }
/// <summary> /// Initializes the BloomPostProcessor. /// </summary> public BloomPostProcessor(Renderer renderer) { if (renderer == null) throw new ArgumentNullException("renderer", "Can't create the BloomPostProcessor with a " + "null Renderer reference."); this.renderer = renderer; brightPassTex = new Texture(renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true); blurHorizontalTex = new Texture(renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true); blurVerticalTex = new Texture(renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true); finalBloomImage = new Texture(renderer, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height, true); fullscreenQuad = Mesh.Rectangle(renderer, Color.Black, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height); bloomEffect = GlobalResourceCache.CreateEffectFromFile(renderer, "Effect Files\\Bloom.fx"); }
public void SetValue(string name, Texture val) { effect.SetValue(GetHandle(name), val.D3DTexture); }
public Light(Renderer renderer, float range, float intensity, Vector2 position, Color color) { if (renderer == null) { Log.Write("'renderer' is null."); throw new ArgumentNullException("renderer", "Can't create a Light with a null " + "renderer reference."); } if (intensity < 0.0f || intensity > 1.0f) { Log.Write("'intensity' is out of range."); throw new ArgumentOutOfRangeException("intensity", intensity, "'intensity' is outside of the range [0,1]."); } this.renderer = renderer; this.range = range; this.intensity = intensity; this.position = position; this.color = Color; // Allocate memory for the attenuation map attenuationMap = new Texture(renderer, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height, true); CreateAttenuationCircle(); CreateAttenuationMap(); }
/// <summary> /// Create a texture from a file. If the texture has already been created, the cached /// version is returned. /// </summary> public static Texture CreateTextureFromFile(Renderer renderer, string filename) { // Search cache first foreach (string cachedFilename in textureCache.Keys) { if (StringHelper.CaseInsensitiveCompare(cachedFilename, filename)) return textureCache[cachedFilename] as Texture; } Texture newTex = new Texture(renderer, filename); textureCache.Add(filename, newTex); return newTex; }
/// <summary> /// Initializes the game. Loads all resources. /// </summary> protected override void InitializeGame() { Cursor.Hide(); mouse = new MouseDevice(this); renderer.ProjectionMode = ProjectionMode.Orthogonal; renderer.ViewMatrix = Matrix.LookAtLH(new Vector3(0, 0, 5.0f), new Vector3(), new Vector3(0, 1, 0)); effect = GlobalResourceCache.CreateEffectFromFile(renderer, "Effect Files\\Dynamic2DLightingEffect.fx"); rectMesh = Mesh.Rectangle(renderer, Color.White, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height, 1.0f); material = GlobalResourceCache.CreateMaterialFromFile(renderer, "Materials\\roughWallMaterial.xml"); light = new Light(renderer, 350, 1.0f, new Vector2(), Color.Red); sceneImage = new Texture(renderer, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height, true); lightMesh = Mesh.Circle(renderer, Color.Yellow, Color.Yellow, 6, 16); bloomPostProcessor = new BloomPostProcessor(renderer); bloomPostProcessor.Blur = 3.5f; bloomPostProcessor.BloomScale = 1.5f; bloomPostProcessor.BrightPassThreshold = 0.4f; poly1 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.Blue, Color.Blue, 65, 8)); poly1.Position = new Vector2(-150.0f, 150.0f); poly2 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.Red, Color.Purple, 50, 4)); poly2.Position = new Vector2(200.0f, 0.0f); poly3 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.SaddleBrown, Color.SeaGreen, 60, 32)); poly3.Position = new Vector2(-250.0f, -200.0f); this.KeyDown += new KeyEventHandler(OnKeyDown); }
/// <summary> /// Binds a texture to an Effect parameter. /// </summary> public void BindTexture(string effectParameterName, Texture texture) { if (currentEffect != null) currentEffect.SetValue(effectParameterName, texture); }