// Конструктор protected SkyboxShader() : base() { if (vertexAttrib == null) { vertexAttrib = new VertexAttribute("inPosition"); attribs.Add(vertexAttrib); } if (texCoordAttrib == null) { texCoordAttrib = new VertexAttribute("inTexCoord"); attribs.Add(texCoordAttrib); } if (textureUniform == null) { textureUniform = new TextureUniform("texture"); uniforms.Add(textureUniform); } if (diffuseColor == null) { diffuseColor = new ColorUniform("diffuseColor"); uniforms.Add(diffuseColor); } if (textureMatrix == null) { textureMatrix = new MatrixUniform("textureMatrix"); uniforms.Add(textureMatrix); } }
public void InjectDeferredBuffer(Texture normalBuffer, Texture depthBuffer) { var normalUniform = new TextureUniform("normalBuffer", normalBuffer, TextureUnit.Texture0); var depthUniform = new TextureUniform("depthBuffer", depthBuffer, TextureUnit.Texture1); PointLights.AddSettings(normalUniform, depthUniform); }
public DeferredBuffer() { this.positionUniform = new TextureUniform("positionTexture", null, TextureUnit.Texture0); this.normalUniform = new TextureUniform("normalTexture", null, TextureUnit.Texture1); this.target = new RenderTarget(); this.lightAccumTarget = new RenderTarget(); this.lightAccumUniform = new TextureUniform("diffuseTexture", null); }
/// <summary> /// Binds a texture to a sampler in the shader /// TODO: Refactor or remove this /// </summary> /// <param name="textureUnit">The texture unit to bind the texture to</param> /// <param name="uniform">The uniform name where the texture should be bound.</param> /// <param name="texture">The texture to bind.</param> public void BindTexture2D(TextureUnit textureUnit, TextureUniform uniform, Texture2D texture) { Enable(); GL.ActiveTexture(textureUnit); texture.Bind(); int textureVariableHandle = GL.GetUniformLocation(this.NativeShaderProgramID, uniform.ToString()); GL.Uniform1(textureVariableHandle, (int)uniform); }
public TextureViewModel(TextureUniform uniform) { Assert.NotNull(uniform); TextureUniform = uniform; var name = uniform.Name; if (name.StartsWith("uniform_", StringComparison.InvariantCultureIgnoreCase)) { name = name.Substring(8); } Name = name; Refresh(); }
/// <summary> /// Binds a texture to a sampler in the shader. The name of the sampler must match one of the values in /// <see cref="TextureUniform"/>. /// </summary> /// <param name="textureUnit">The texture unit to bind the texture to.</param> /// <param name="uniform">The uniform where the texture should be bound.</param> /// <param name="texture">The texture to bind.</param> public void BindTexture2D(TextureUnit textureUnit, TextureUniform uniform, Texture2D texture) { if (texture == null) { throw new ArgumentNullException(nameof(texture)); } Enable(); var textureVariableHandle = GL.GetUniformLocation(this.NativeShaderProgramID, uniform.ToString()); GL.Uniform1(textureVariableHandle, (int)uniform); GL.ActiveTexture(textureUnit); texture.Bind(); }
// Конструктор protected MeshShader() : base() { if (vertexAttrib == null) { vertexAttrib = new VertexAttribute("inPosition"); attribs.Add(vertexAttrib); } if (normalAttrib == null) { normalAttrib = new VertexAttribute("inNormal"); attribs.Add(normalAttrib); } if (texCoordAttrib == null) { texCoordAttrib = new VertexAttribute("inTexCoord"); attribs.Add(texCoordAttrib); } if (textureUniform == null) { textureUniform = new TextureUniform("texture"); uniforms.Add(textureUniform); } if (diffuseColor == null) { diffuseColor = new ColorUniform("diffuseColor"); uniforms.Add(diffuseColor); } if (alphaPass == null) { alphaPass = new BoolUniform("discardPass"); uniforms.Add(alphaPass); } if (lightMultiplier == null) { lightMultiplier = new FloatUniform("lightMult"); uniforms.Add(lightMultiplier); } if (textureMatrix == null) { textureMatrix = new MatrixUniform("textureMatrix"); uniforms.Add(textureMatrix); } }
private void loadFont() { var shaders = ShaderManager.Instance; this.MonoFont = Font.FromJsonFile("data/fonts/inconsolata.json"); this.fontTexture = new TextureUniform("diffuseTexture", new Texture("data/fonts/inconsolata.png", true)); this.GameText = new IndexedSurface <UVColorVertexData>(); this.GameText.AddSettings( this.fontTexture, this.gameModelview, this.gameProjection ); shaders.UVColor.UseOnSurface(this.GameText); this.HudText = new IndexedSurface <UVColorVertexData>(); this.HudText.AddSettings( this.fontTexture, this.hudModelview, this.hudProjection ); shaders.UVColor.UseOnSurface(this.HudText); }
private void initFonts(ShaderManager shaders) { this.Font = Font.FromJsonFile("data/gfx/fonts/calibri.json"); this.fontTextureUniform = new TextureUniform("diffuseTexture", new Texture("data/gfx/fonts/calibri.png", true)); this.ScreenFontSurface = new IndexedSurface <UVColorVertexData>(); this.ScreenFontSurface.AddSettings( this.screenModelview, this.gameProjection, this.fontTextureUniform, SurfaceBlendSetting.PremultipliedAlpha ); shaders.UVColor.UseOnSurface(this.ScreenFontSurface); this.GameFontSurface = new IndexedSurface <UVColorVertexData>(); this.GameFontSurface.AddSettings( this.gameModelview, this.gameProjection, this.fontTextureUniform, SurfaceBlendSetting.PremultipliedAlpha ); shaders.UVColor.UseOnSurface(this.GameFontSurface); }
public Graphics(Audio audio) { // Save a pointer to the audio class, for convenience this.Audio = audio; // Load Shader Programs. ShaderProgram uvShader = new ShaderProgram(VertexShader.FromFile("data/shaders/uvcolor_vs.glsl"), FragmentShader.FromFile("data/shaders/uvcolor_fs.glsl")); ShaderProgram objShader = new ShaderProgram(VertexShader.FromFile("data/shaders/obj_vs.glsl"), FragmentShader.FromFile("data/shaders/obj_fs.glsl")); ShaderProgram objShaderHax = new ShaderProgram(VertexShader.FromFile("data/shaders/obj_vs_hax.glsl"), FragmentShader.FromFile("data/shaders/obj_fs.glsl")); this.wallShader = objShader; // Create matrix uniforms used for rendering. this.view2D = new Matrix4Uniform("viewMatrix"); this.projection2D = new Matrix4Uniform("projectionMatrix"); this.view3D = new Matrix4Uniform("viewMatrix"); this.projection3D = new Matrix4Uniform("projectionMatrix"); this.createColorMatrices(); this.WallColorUniform = new Matrix4Uniform("mixColor", this.Blue); this.lightDirection = new Vector3(-1f, -0.5f, -0.4f); this.lightDirection.Normalize(); // Create the surfaces #region Font Surface Texture t = new Texture("data/fonts/freshman.png"); this.FontSurface = new IndexedSurface <UVColorVertexData>(); this.FontSurface.AddSettings( this.view2D, this.projection2D, new TextureUniform("diffuseTexture", t), SurfaceBlendSetting.Alpha, SurfaceDepthMaskSetting.DontMask ); this.FontSurface.SetShaderProgram(uvShader); // the following line loads the json file this.FontGeometry = new FontGeometry(this.FontSurface, amulware.Graphics.Font.FromJsonFile("data/fonts/freshman_monospaced_numbers.json")); // this.FontGeometry.SizeCoefficient = new Vector2(1, -1); // FLIP IT this.MenuFontGeometry = this.FontGeometry; #endregion #region 3D font Surface t = new Texture("data/fonts/freshman.png"); this.FontSurface3D = new IndexedSurface <UVColorVertexData>(); this.FontSurface3D.AddSettings( this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), SurfaceBlendSetting.Alpha, SurfaceDepthMaskSetting.DontMask ); this.FontSurface3D.SetShaderProgram(uvShader); // the following line loads the json file this.FontGeometry3D = new FontGeometry(this.FontSurface3D, amulware.Graphics.Font.FromJsonFile("data/fonts/freshman_monospaced_numbers.json")); this.FontGeometry3D.SizeCoefficient = new Vector2(1, -1); // FLIP IT #endregion #region PacmanSurface MeshData m = new MeshData("data/models/Pacman.obj"); t = new Texture("data/sprites/PacmanTexture.png"); this.pacManModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.PacmanSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.PacmanSurface.AddSettings( this.pacManModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), new Matrix4Uniform("mixColor", Matrix4.Identity) ); this.PacmanSurface.SetShaderProgram(objShader); #endregion #region PacmanMouthSurface (must be placed directly after the 'PacmanSurface') m = new MeshData("data/models/Pacman_mouth.obj"); this.PacManMouthTopTexture = new Texture("data/sprites/OrbTexture.png"); // 't' is the same texture as pacman, 't-top' is a plain white pixel (as used for the orbs). this.PacManMouthBottomTexture = t; this.PacManMouthTextureUniform = new TextureUniform("diffuseTexture", t); this.PacManMouthColorUniform = new Matrix4Uniform("mixColor", Matrix4.Identity); this.PacmanMouthSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.PacmanMouthSurface.AddSettings( this.pacManModel, this.view3D, this.projection3D, this.PacManMouthTextureUniform, new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), this.PacManMouthColorUniform ); this.PacmanMouthSurface.SetShaderProgram(objShaderHax); #endregion #region GhostSurface m = new MeshData("data/models/Ghost.obj"); t = new Texture("data/sprites/GhostTexture.png"); this.GhostColorUniform = new Matrix4Uniform("mixColor", this.Red); this.ghostModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.GhostSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.GhostSurface.AddSettings( this.ghostModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), this.GhostColorUniform ); this.GhostSurface.SetShaderProgram(objShader); #endregion #region OrbSurface m = new MeshData("data/models/Orb.obj"); t = new Texture("data/sprites/OrbTexture.png"); this.orbModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.OrbSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.OrbSurface.AddSettings( this.orbModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), new Matrix4Uniform("mixColor", Matrix4.Identity) ); this.OrbSurface.SetShaderProgram(objShader); #endregion }