本文整理汇总了C#中ShaderProgram.Create方法的典型用法代码示例。如果您正苦于以下问题:C# ShaderProgram.Create方法的具体用法?C# ShaderProgram.Create怎么用?C# ShaderProgram.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialise
/// <summary>
/// Initialises the scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="width">The width of the screen.</param>
/// <param name="height">The height of the screen.</param>
public void Initialise(OpenGL gl, float width, float height)
{
// Set a blue clear colour.
gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);
// Create the shader program.
var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
shaderProgram = new ShaderProgram();
shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
shaderProgram.AssertValid(gl);
// Create a perspective projection matrix.
const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);
// Create a view matrix to move us back a bit.
viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));
// Create a model matrix to make the model a little bigger.
modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));
// Now create the geometry for the square.
CreateVerticesForSquare(gl);
}
示例2: Initialise
/// <summary>
/// Initialises the Scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void Initialise(OpenGL gl)
{
// We're going to specify the attribute locations for the position and normal,
// so that we can force both shaders to explicitly have the same locations.
const uint positionAttribute = 0;
const uint normalAttribute = 1;
var attributeLocations = new Dictionary<uint, string>
{
{positionAttribute, "Position"},
{normalAttribute, "Normal"},
};
// Create the per pixel shader.
shaderPerPixel = new ShaderProgram();
shaderPerPixel.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);
// Create the toon shader.
shaderToon = new ShaderProgram();
shaderToon.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);
// Generate the geometry and it's buffers.
trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
}
示例3: DoInitialize
protected override void DoInitialize()
{
{
var computeProgram = new ShaderProgram();
var shaderCode = new ShaderCode(File.ReadAllText(
@"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader);
var shader = shaderCode.CreateShader();
computeProgram.Create(shader);
shader.Delete();
this.computeProgram = computeProgram;
}
{
Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename);
if (bitmap.Width != 512 || bitmap.Height != 512)
{
bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero);
}
OpenGL.GenTextures(1, this.input_image);
OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]);
// Lock the image bits (so that we can pass them to OGL).
BitmapData bitmapData = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
//GL.ActiveTexture(GL.GL_TEXTURE0);
OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F,
bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
bitmapData.Scan0);
// Unlock the image.
bitmap.UnlockBits(bitmapData);
/* We require 1 byte alignment when uploading texture data */
//GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
/* Clamping to edges is important to prevent artifacts when scaling */
OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
/* Linear filtering usually looks best for text */
OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
bitmap.Dispose();
}
{
//GL.ActiveTexture(GL.GL_TEXTURE0);
OpenGL.GenTextures(1, this.intermediate_image);
OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]);
OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
}
{
// This is the texture that the compute program will write into
//GL.ActiveTexture(GL.GL_TEXTURE0);
OpenGL.GenTextures(1, this.output_image);
OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]);
OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
}
{
var bufferable = new ImageProcessingModel();
ShaderCode[] simpleShader = new ShaderCode[2];
simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader);
simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader);
var propertyNameMap = new PropertyNameMap();
propertyNameMap.Add("vert", "position");
propertyNameMap.Add("uv", "uv");
var pickableRenderer = new PickableRenderer(
bufferable, simpleShader, propertyNameMap, "position");
pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]");
pickableRenderer.Initialize();
pickableRenderer.SetUniform("output_image",
new samplerValue(
BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0));
this.renderer = pickableRenderer;
}
}