static void Init(int volumeIndex) { GL.GenBuffers(1, out vertexBuffer); vao = new VertexArrayObject(vertexBuffer); vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, Vertex.SIZE, 0); //7 coef vao.AddAttribute(1, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 12); vao.AddAttribute(2, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 28); vao.AddAttribute(3, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 44); vao.AddAttribute(4, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 60); vao.AddAttribute(5, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 76); vao.AddAttribute(6, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 92); vao.AddAttribute(7, 4, VertexAttribPointerType.Float, false, Vertex.SIZE, 108); vao.Initialize(); var probeLighting = ProbeMapManager.ProbeLighting; var volume = probeLighting.Boxes[volumeIndex]; Vertices = InitProbes(volume).ToArray(); vao.Bind(); GL.BufferData <Vertex>(BufferTarget.ArrayBuffer, Vertex.SIZE * Vertices.Length, Vertices, BufferUsageHint.StaticDraw); }
public override void Prepare(GL_ControlModern control) { var solidColorFrag = new FragmentShader( @"#version 330 uniform vec4 color; out vec4 FragColor; void main(){ FragColor = color; }" ); var solidColorVert = new VertexShader( @"#version 330 in vec3 vPosition; uniform mat4 mtxMdl; uniform mat4 mtxCam; void main(){ gl_Position = mtxMdl * mtxCam * vec4(vPosition.xyz, 1); }" ); defaultShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert, control); int buffer = GL.GenBuffer(); vao = new VertexArrayObject(buffer); vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 12, 0); vao.Initialize(control); }
void Init() { GL.GenBuffers(1, out vbo_position); vao = new VertexArrayObject(vbo_position); vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 12, 0); vao.Initialize(); }
public void PrepareModel(GL_ControlBase control) { int[] buffers = new int[3]; //Load vao GL.GenBuffers(3, buffers); vaoBuffer = buffers[0]; iboBuffer = buffers[1]; iboSelBuffer = buffers[2]; vao = new VertexArrayObject(vaoBuffer); vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 32, 0); vao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 32, 12); vao.AddAttribute(2, 4, VertexAttribPointerType.UnsignedByte, true, 32, 24); vao.AddAttribute(3, 1, VertexAttribPointerType.Float, false, 32, 28); vao.Initialize(control); UpdateVertexData(); }
private static void Submit(PrimitiveType primitiveType, string modelName, List <int> indices, float[] data, Pass pass = Pass.OPAQUE) { int[] buffers = new int[2]; GL.GenBuffers(2, buffers); int indexBuffer = buffers[0]; int vaoBuffer = buffers[1]; VertexArrayObject vao = new VertexArrayObject(vaoBuffer, indexBuffer); vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 7, 0); vao.AddAttribute(1, 4, VertexAttribPointerType.Float, false, sizeof(float) * 7, sizeof(float) * 3); vao.Submit(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Count * sizeof(int), indices.ToArray(), BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, vaoBuffer); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); models.Add(modelName, new ExtraModel(vao, indices.Count, primitiveType, pass)); }
public static void Initialize() { if (!Initialized) { var defaultFrag = new FragmentShader( @"#version 330 uniform sampler2D tex; uniform vec4 color; in vec2 uv; void main(){ gl_FragColor = color * texture(tex,uv); }"); var defaultVert = new VertexShader( @"#version 330 layout(location = 0) in vec4 position; uniform vec2 uvTopLeft; uniform mat4 mtxMdl; uniform mat4 mtxCam; out vec2 uv; vec2 map(vec2 value, vec2 min1, vec2 max1, vec2 min2, vec2 max2) { return min2 + (value - min1) * (max2 - min2) / (max1 - min1); } void main(){ uv = map(position.xy,vec2(-0.5,0.5),vec2(0.5,-0.5), uvTopLeft, uvTopLeft+vec2(0.25,0.25)); gl_Position = mtxCam*mtxMdl*position; }"); DefaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert); int buffer; #region block buffer = GL.GenBuffer(); planeVao = new VertexArrayObject(buffer); planeVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0); planeVao.Submit(); float[] data = new float[] { -0.5f, -0.5f, 0, 0.5f, -0.5f, 0, 0.5f, 0.5f, 0, -0.5f, 0.5f, 0, }; GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); #endregion //texture sheet TextureSheet = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, TextureSheet); var bmp = Properties.Resources.Gizmos; var bmpData = bmp.LockBits( new Rectangle(0, 0, 128 * 4, 128 * 4), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, 128 * 4, 128 * 4, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); bmp.UnlockBits(bmpData); Initialized = true; } }
public static void Initialize(GL_ControlModern control) { if (DefaultShaderProgram != null && DefaultShaderProgram.programs.ContainsKey(control)) { return; } if (DefaultShaderProgram == null) { var solidColorFrag = new FragmentShader( @"#version 330 uniform vec4 color; out vec4 fragColor; void main(){ fragColor = color; }"); var solidColorVert = new VertexShader( @"#version 330 layout(location = 0) in vec4 position; uniform mat4 mtxMdl; uniform mat4 mtxCam; void main(){ gl_Position = mtxCam*mtxMdl*position; }"); var defaultFrag = new FragmentShader( @"#version 330 uniform vec4 color; in vec3 viewPosition; in vec3 normal; void main(){ gl_FragColor = color; }"); var defaultVert = new VertexShader( @"#version 330 layout(location = 0) in vec3 position; layout(location = 1) in vec3 vNormal; uniform mat4 mtxMdl; uniform mat4 mtxCam; out vec3 normal; out vec3 viewPosition; void main(){ normal = vNormal; viewPosition = position; gl_Position = mtxCam*mtxMdl*vec4(position, 1); }"); DefaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert, control); SolidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert, control); int buffer = GL.GenBuffer(); sphereVao = new VertexArrayObject(buffer); sphereVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 24, 0); sphereVao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 24, 12); sphereVao.Initialize(control); List <float> list = new List <float>(); Vertices = GetVertices(1, 32); for (int i = 0; i < Vertices.Length; i++) { list.Add(Vertices[i].Position.X); list.Add(Vertices[i].Position.Y); list.Add(Vertices[i].Position.Z); list.Add(Vertices[i].Normal.X); list.Add(Vertices[i].Normal.Y); list.Add(Vertices[i].Normal.Z); } float[] data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); } else { sphereVao.Initialize(control); DefaultShaderProgram.Link(control); SolidColorShaderProgram.Link(control); } }
public static void Initialize() { if (!Initialized) { var defaultFrag = new FragmentShader( @"#version 330 uniform sampler2D tex; in vec4 fragColor; in vec3 fragPosition; in vec2 uv; void main(){ gl_FragColor = fragColor*((fragPosition.y+2)/3)*texture(tex, uv, 100); }"); var defaultVert = new VertexShader( @"#version 330 layout(location = 0) in vec4 position; uniform vec4 color; uniform mat4 mtxMdl; uniform mat4 mtxCam; out vec4 fragColor; out vec3 fragPosition; out vec2 uv; vec2 map(vec2 value, vec2 min1, vec2 max1, vec2 min2, vec2 max2) { return min2 + (value - min1) * (max2 - min2) / (max1 - min1); } void main(){ fragPosition = position.xyz; uv = map(fragPosition.xz,vec2(-1.0625,-1.0625),vec2(1.0625,1.0625), vec2(0.5,0.5), vec2(0.75,1.0)); gl_Position = mtxCam*mtxMdl*position; fragColor = color; }"); DefaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert); int buffer; #region block buffer = GL.GenBuffer(); blockVao = new VertexArrayObject(buffer); blockVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0); blockVao.Submit(); List <float> list = new List <float>(); Face(ref points, ref list, 0, 1, 2, 3); FaceInv(ref points, ref list, 4, 5, 6, 7); FaceInv(ref points, ref list, 0, 1, 4, 5); Face(ref points, ref list, 2, 3, 6, 7); Face(ref points, ref list, 0, 2, 4, 6); FaceInv(ref points, ref list, 1, 3, 5, 7); float[] data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); #endregion #region lines buffer = GL.GenBuffer(); linesVao = new VertexArrayObject(buffer); linesVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0); linesVao.Submit(); list = new List <float>(); LineFace(ref points, ref list, 0, 1, 2, 3); LineFace(ref points, ref list, 4, 5, 6, 7); Line(ref points, ref list, 0, 4); Line(ref points, ref list, 1, 5); Line(ref points, ref list, 2, 6); Line(ref points, ref list, 3, 7); data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); #endregion #region legacy lines lineDrawList = GL.GenLists(1); GL.NewList(lineDrawList, ListMode.Compile); GL.Begin(PrimitiveType.LineStrip); GL.Vertex3(points[6]); GL.Vertex3(points[2]); GL.Vertex3(points[3]); GL.Vertex3(points[7]); GL.Vertex3(points[6]); GL.Vertex3(points[4]); GL.Vertex3(points[5]); GL.Vertex3(points[1]); GL.Vertex3(points[0]); GL.Vertex3(points[4]); GL.End(); GL.Begin(PrimitiveType.Lines); GL.Vertex3(points[2]); GL.Vertex3(points[0]); GL.Vertex3(points[3]); GL.Vertex3(points[1]); GL.Vertex3(points[7]); GL.Vertex3(points[5]); GL.End(); GL.EndList(); #endregion Initialized = true; } }
public static void Initialize(GL_ControlModern control, float scale) { if (DefaultShaderProgram != null && DefaultShaderProgram.programs.ContainsKey(control)) { return; } if (DefaultShaderProgram == null) { var solidColorFrag = new FragmentShader( @"#version 330 uniform vec4 color; out vec4 fragColor; void main(){ fragColor = color; }"); var solidColorVert = new VertexShader( @"#version 330 layout(location = 0) in vec4 position; uniform mat4 mtxMdl; uniform mat4 mtxCam; void main(){ gl_Position = mtxCam*mtxMdl*position; }"); var defaultFrag = new FragmentShader( @"#version 330 uniform vec4 highlight_color; uniform sampler2D texture0; in vec3 viewPosition; in vec3 normal; in vec2 f_texcoord0; out vec4 fragColor; void main(){ vec4 color = texture(texture0,f_texcoord0); float hc_a = highlight_color.w; vec4 colorComb = vec4(color.rgb * (1-hc_a) + highlight_color.rgb * hc_a, color.a); vec3 displayNormal = (normal.xyz * 0.5) + 0.5; float halfLambert = max(displayNormal.y,0.5); vec4 colorOutput = vec4(colorComb.rgb * halfLambert, colorComb.a); fragColor = colorOutput; }"); var defaultVert = new VertexShader( @"#version 330 layout(location = 0) in vec3 position; layout(location = 1) in vec3 vNormal; layout(location = 2) in vec2 vTexCoord; uniform mat4 mtxMdl; uniform mat4 mtxCam; out vec3 normal; out vec3 viewPosition; out vec2 f_texcoord0; void main(){ normal = vNormal; viewPosition = position; f_texcoord0 = vTexCoord; gl_Position = mtxCam*mtxMdl*vec4(position, 1); }"); DefaultShaderProgram = new ShaderProgram(defaultFrag, defaultVert, control); SolidColorShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert, control); int buffer = GL.GenBuffer(); sphereVao = new VertexArrayObject(buffer); sphereVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 32, 0); sphereVao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 32, 12); sphereVao.AddAttribute(2, 2, VertexAttribPointerType.Float, false, 32, 24); sphereVao.Initialize(control); List <float> list = new List <float>(); Vertices = GetVertices(scale); for (int i = 0; i < Vertices.Length; i++) { list.Add(Vertices[i].Position.X); list.Add(Vertices[i].Position.Y); list.Add(Vertices[i].Position.Z); list.Add(Vertices[i].Normal.X); list.Add(Vertices[i].Normal.Y); list.Add(Vertices[i].Normal.Z); list.Add(Vertices[i].TexCoord.X); list.Add(Vertices[i].TexCoord.Y); } float[] data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); } else { sphereVao.Initialize(control); DefaultShaderProgram.Link(control); SolidColorShaderProgram.Link(control); } }
public static void Initialize(GL_ControlModern control) { if (DefaultShaderProgram != null && DefaultShaderProgram.programs.ContainsKey(control)) { return; } if (DefaultShaderProgram == null) { var solidColorFrag = new FragmentShader( @"#version 330 uniform vec4 color; in vec3 normal; in vec3 viewPosition; void main(){ vec3 xTangent = dFdx( viewPosition ); vec3 yTangent = dFdy( viewPosition ); vec3 faceNormal = normalize( cross( xTangent, yTangent ) ); vec3 displayNormal = (faceNormal.xyz * 0.5) + 0.5; float shading = max(displayNormal.y,0.5); gl_FragColor = color; }"); var solidColorVert = new VertexShader( @"#version 330 layout(location = 0) in vec3 position; layout(location = 1) in vec3 vNormal; uniform mat4 mtxMdl; uniform mat4 mtxCam; out vec3 normal; out vec3 viewPosition; void main(){ normal = vNormal; viewPosition = position; gl_Position = mtxCam*mtxMdl*vec4(position, 1); }"); DefaultShaderProgram = new ShaderProgram(solidColorFrag, solidColorVert, control); int buffer = GL.GenBuffer(); sphereVao = new VertexArrayObject(buffer); sphereVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 24, 0); sphereVao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 24, 12); sphereVao.Initialize(control); List <float> list = new List <float>(); Vertices = GetVertices(10, 2, 15, 32); for (int i = 0; i < Vertices.Length; i++) { var mat = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(90)); Vertices[i].Position = Vector3.TransformPosition(Vertices[i].Position, mat); Vertices[i].Normal = Vector3.TransformNormal(Vertices[i].Normal, mat); list.Add(Vertices[i].Position.X); list.Add(Vertices[i].Position.Y); list.Add(Vertices[i].Position.Z); list.Add(Vertices[i].Normal.X); list.Add(Vertices[i].Normal.Y); list.Add(Vertices[i].Normal.Z); } float[] data = list.ToArray(); GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw); } else { sphereVao.Initialize(control); DefaultShaderProgram.Link(control); } }