Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 22 Apr 2005
Offline Last Active Yesterday, 04:43 PM

Topics I've Started

Shader works on laptop, hangs on desktop.

11 January 2014 - 02:32 PM

I recently completed my Single Pass Order Independent Transparency shader.










What that looks like:











Screenshot from my laptop: http://i.imgur.com/9WspPLc.png








Managing Materials / Shaders, Their Inputs, and Different Types of Geometry.

09 September 2013 - 09:28 PM

I wanted to have this great "material" system where I could create a simple description of a material in a text file and slap it on just about any geometry I wanted. Different types of geometry are things like static meshes, animated meshes, particles, instanced geometry, ribbon-trails, etc.

These different types of geometry require different vertex shaders, maybe tessellation or geometry shaders as well, and have inputs to go with those shaders such as bone orientations for animated meshes.


So in my head it made sense to create a Geometry class who's purpose is to contribute the vertex processing part of the shaders, handle the vertex processing inputs, and control how the primitives were submitted to the GPU.


Then to go with it I created a Shading class who supplied the fragment processing part of the shaders, the inputs for the fragment processing, and controlled the order in which "bucket" the draw call should go in. (Transparent, Forward Opaque, Deferred, Glowing, Distortion, etc).


There were agreed upon inputs/outputs between shading stages. (Normal, Position, TextureCoordinate) etc.


This turned out horribly, or at least the way I handled it did.


  • You couldn't have shading that required special vertex shading. Like this.
  • You had to write special shaders for instanced stuff anyway if they were to have any variation in shading. Thus defeating the purpose.
  • Particles were a mess because you have the behavior of a particle influence both the vertex and fragment processing ends. And ultimately defeated the purpose of separating geometry and shading.
  • Forward lighting became problematic because of the multiple shaders for different types of lights while other types of shading like deferred didn't need to know about the light.

So the system is pretty much broken and I need to replace it with a better way of doing things. So how do you handle minimizing your shader rewriting? How do you pair your "materials" with your "geometry"?


I tried to search around for related information but I wasn't entirely sure what to search for so if I've missed a great thread post me a link.




LaTeX math via MathJax?

18 July 2013 - 07:28 AM

A few weeks ago I tried to make a post in the math forum with a bit of LaTeX mixed in. A sticky post said to use the "eqn" tag. The tag seems to query a server to render the latex and serve an image. However it seemed quite easy to break the server so it wouldn't output an image at all.


The other day I was stumbling across the internet and found http://www.mathjax.org/ which renders latex into HTML elements. It seems to function quite well. Has anyone considered this for use in the forums / journals? I did a quick search of the forums and couldn't find any mention of it. So I thought I'd post it here.

Rope Simulation with Point Based Dynamics

17 June 2013 - 01:44 PM




My second issue with his constraint function is 


I attempted to figure out what the constraint function should be.
So I define 


Here's a poorly drawn diagram to illustrate my thoughts.


Simple fullscreen quad not showing up.

30 November 2012 - 12:26 PM

Case Closed:

I'm an idiot, a typo in ibo.Write() caused the program to not write the indices to the IBO and thus it didn't render anything. It works now.

I've been working on a "graphics framework" (I use this term loosely), I've put OpenGL concepts into C++ classes so I can use them more easily, at any rate I decided to give them a simple test of a fullscreen quad. I init opengl to 3.1, set the clear color to blue, and start the renderloop. The quad is set to show up as white, yet I still see blue so the quad is not showing up.

First off here's my code using my framework stuff
[source lang="cpp"]//The quad, it's not there!class ScreenQuad{ Tocs::Graphics::VBO vbo; Tocs::Graphics::IBO ibo; Tocs::Graphics::VAO vao; Tocs::Graphics::Shader QuadShader;public: ScreenQuad(); void Draw (Tocs::Graphics::Texture2D &texture);};struct CrappyVertex{ float x,y,z; float u,v;};//Crappy Fullscreen quad class, meant more as a test than a utilityScreenQuad::ScreenQuad(void) : vbo (4 * sizeof(CrappyVertex)), ibo (6){ CrappyVertex vertices [4] = {{1,1,0,0,0},{-1,1,0,1,0},{1,-1,0,0,1},{-1,-1,0,1,1}}; vbo.Write (vertices,4,0); unsigned short indices[6] = {0,1,2, 1,3,2}; ibo.Write (indices,6,0); VertexFormat format; format.AddMember ("Position",VertexType::Vec3,false); format.AddMember ("TexCoord",VertexType::Vec2,false); vao.Bind (); vao.AddVBO (vbo,format); vao.UnBind (); ShaderCode vertcode (ShaderType::Vertex); vertcode.CompileFromFile ("Quad.vert"); if (!vertcode.Compiled ()) { cout << vertcode.GetCompileErrors () << endl; return; } ShaderCode fragcode (ShaderType::Pixel); fragcode.CompileFromFile ("Quad.frag"); if (!fragcode.Compiled ()) { cout << fragcode.GetCompileErrors () << endl; return; } QuadShader.SetOutput ("Color",0); QuadShader.AddCode (vertcode); QuadShader.AddCode (fragcode); QuadShader.SetAttribute ("InPosition",0); QuadShader.SetAttribute ("InTextureCoordinate",1); QuadShader.Link (); if (!QuadShader.Linked ()) { cout << QuadShader.GetLinkErrors () << endl; } cout << "InPosition: " << QuadShader.GetAttribute ("InPosition") << endl << "InTextureCoordinate: " << QuadShader.GetAttribute ("InTextureCoordinate") << endl << "Color: " << QuadShader.GetOutput ("Color") << endl;}void ScreenQuad::Draw (Tocs::Graphics::Texture2D &texture){ QuadShader.Bind (); //QuadShader["Texture"] = texture; //Segfaults without "Texture" uniform being used. vao.Bind (); ibo.Bind (); GraphicsContext::DrawTriangles (2); ibo.UnBind (); vao.UnBind (); QuadShader.UnBind ();}[/source]

This probably wont help as much because you can't see the OpenGL, so I went inside each function and copied down the OpenGL calls so I could see more clearly the order the functions were being called. And got this.

Note: All OpenGL calls have a Debug error check, all calls are giving GL_NO_ERROR
[source lang="cpp"]glGenVertexArrays (1,&vao.ID);glGenBuffers (1,&vbo.ID);glBindBuffer (GL_ARRAY_BUFFER,vbo.ID);glBufferData (GL_ARRAY_BUFFER,static_cast <GLsizeiptr> (Size),nullptr, GL_DYNAMIC_DRAW);glBindBuffer (GL_ARRAY_BUFFER,0);glGenBuffers (1,&ibo.ID);glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);glBufferData (GL_ELEMENT_ARRAY_BUFFER,static_cast <GLsizeiptr> (Format.GetSize () * IndiceCount),nullptr, GL_DYNAMIC_DRAW);glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);CrappyVertex vertices [4] = {{1,1,0.5,0,0},{-1,1,0.5,1,0},{1,-1,0.5,0,1},{-1,-1,0.5,1,1}};glBindBuffer (GL_ARRAY_BUFFER,vbo.ID); glBufferSubData (GL_ARRAY_BUFFER, 0, 20*4, vertices);glBindBuffer (GL_ARRAY_BUFFER,0);unsigned short indices[6] = {0,1,2, 1,3,2};glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);glBufferSubData (GL_ELEMENT_ARRAY_BUFFER,static_cast <GLintptr> (offset * sizeof (unsigned short)),6 * sizeof (unsigned short), static_cast <void *> (indices));glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);glBindVertexArray (vao.ID);glBindBuffer (GL_ARRAY_BUFFER,vbo.ID);int index = 0;unsigned int Offset = 0;for (auto i = Members.begin (); i != Members.end (); ++i){ glEnableVertexAttribArray (index); glVertexAttribPointer (index,(*i).GetType ().GetComponentCount (), (*i).GetType ().GetGLFormat (),(*i).IsNormalized (),Size,reinterpret_cast <GLvoid *> (Offset)); Offset += (*i).Size(); ++index;} //Gets called with GL_FLOAT 3 components, 12 bytes and GL_FLOAT 2 components, 8 bytesglBindBuffer (GL_ARRAY_BUFFER,0);glBindVertexArray (0);QuadShader.ID = glCreateProgram ()vertcode.ID = glCreateShader(GL_VERTEX_SHADER)glShaderSource (vertcode.ID,1,&codecstr,nullptr);glCompileShader (vertcode.ID);fragcode.ID = glCreateShader(GL_FRAGMENT_SHADER)glShaderSource (fragcode.ID,1,&codecstr,nullptr);glCompileShader (fragcode.ID);glBindFragDataLocation (QuadShader.ID,0,"Color");glAttachShader (QuadShader.ID,vertid);glAttachShader (QuadShader.ID,fragid);glBindAttribLocation (QuadShader.ID,0,"InPosition");glBindAttribLocation (QuadShader.ID,1,"InTextureCoordinate");glLinkProgram (QuadShader.ID);////////////////////////////////////////////////////////DRAWglUseProgram (QuadShader.ID);glBindVertexArray (vao.ID);glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,ibo.ID);glDrawElements (GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, nullptr);glBindBuffer (GL_ELEMENT_ARRAY_BUFFER,0);glBindVertexArray (0);glUseProgram(0);[/source]
And in case the shader may be the problem here they are.
[source lang="cpp"]//Vert#version 130precision highp float;in vec3 InPosition;in vec2 InTextureCoordinate;out vec2 TextureCoordinate;void main(){ TextureCoordinate = InTextureCoordinate; gl_Position = vec4(InPosition.xy,0,1);} //Frag#version 130precision highp float;uniform sampler2D Texture;in vec2 TextureCoordinate;out vec4 Color;void main(){ //Color = texture2D(Texture,TextureCoordinate); Color = vec4(1,1,1,1);} [/source]
I'm hoping it's something simple I've overlooked and someone will be able to point it out fairly quickly. Any comments, insights, insults, or other thoughts are welcome.


EDIT: For a more complete view, I generated a log of the application startup through the first frame with gDEbugger.
[source lang="cpp"]glGetError()wglDeleteContext(0x00010000)wglMakeCurrent(0x6D012800, 0x00010001)glGetString(GL_SHADING_LANGUAGE_VERSION)glGetString(GL_VERSION)glViewport(0, 0, 800, 800)glGetError()glClearColor(0, 0, 0, 0)glGetError()glClearDepth(1000)glGetError()glDisable(GL_DEPTH_TEST)glGetError()glDisable(GL_BLEND)glGetError()glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)glGetError()glGenBuffers(1, 0x0018FC2C)glGetError()glBindBuffer(GL_ARRAY_BUFFER, 1)glGetError()glBufferData(GL_ARRAY_BUFFER, 80, 0x00000000, GL_DYNAMIC_DRAW)glGetError()glBindBuffer(GL_ARRAY_BUFFER, 0)glGetError()glGenBuffers(1, 0x0018FC34)glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)glGetError()glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12, 0x00000000, GL_DYNAMIC_DRAW)glGetError()glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)glGetError()glGenVertexArrays(1, 0x0018FC40)glCreateProgram() [Context 2 - program 1]glBindBuffer(GL_ARRAY_BUFFER, 1)glGetError()glBufferSubData(GL_ARRAY_BUFFER, 0, 80, 0x0018FAA0)glGetError()glBindBuffer(GL_ARRAY_BUFFER, 0)glGetError()glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)glGetError()glBindVertexArray(1)/////////////HERE! Is where the missing glBufferSubData () call should go.glGetError()glBindBuffer(GL_ARRAY_BUFFER, 1)glGetError()glEnableVertexAttribArray(0)glGetError()glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 20, 0x00000000)glGetError()glEnableVertexAttribArray(1)glGetError()glVertexAttribPointer(1, 2, GL_FLOAT, FALSE, 20, 0x0000000C)glGetError()glBindBuffer(GL_ARRAY_BUFFER, 0)glGetError()glBindVertexArray(0)glGetError()glCreateShader(GL_VERTEX_SHADER) [Context 2 - Shader 2: source code is not available]glGetError()glShaderSource(2, 1, 0x0018F5C4, 0x00000000) [Context 2 - shader 2]glGetError()glCompileShader(2) [Context 2 - shader 2]glGetError()glGetShaderiv(2, GL_COMPILE_STATUS, 0x0018F7E0) [Context 2 - shader 2]glGetError()glCreateShader(GL_FRAGMENT_SHADER) [Context 2 - Shader 3: source code is not available]glGetError()glShaderSource(3, 1, 0x0018F5C4, 0x00000000) [Context 2 - shader 3]glGetError()glCompileShader(3) [Context 2 - shader 3]glGetError()glGetShaderiv(3, GL_COMPILE_STATUS, 0x0018F7E0) [Context 2 - shader 3]glGetError()glBindFragDataLocation(1, 0, 0x0018F7DC)glGetError()glAttachShader(1, 2) [Context 2 - program 1][Context 2 - shader 2]glAttachShader(1, 3) [Context 2 - program 1: shader 2][Context 2 - shader 3]glBindAttribLocation(1, 0, InPosition) [Context 2 - program 1: shader 2, shader 3]glGetError()glBindAttribLocation(1, 1, InTextureCoordinate) [Context 2 - program 1: shader 2, shader 3]glGetError()glLinkProgram(1) [Context 2 - program 1: shader 2, shader 3]glGetObjectParameterivARB(1, GL_LINK_STATUS, 0x0018F7D0) [Context 2 - program 1: shader 2, shader 3]glGetError()glGetObjectParameterivARB(1, GL_VALIDATE_STATUS, 0x0018F7D0) [Context 2 - program 1: shader 2, shader 3]glGetError()glGetObjectParameterivARB(1, GL_ACTIVE_UNIFORMS, 0x0018F7C4) [Context 2 - program 1: shader 2, shader 3]glGetError()glGetProgramiv(1, GL_INFO_LOG_LENGTH, 0x0018F7C8) [Context 2 - program 1: shader 2, shader 3]glGetError()glGetProgramInfoLog(1, 1, 0, ) [Context 2 - program 1: shader 2, shader 3]glGetError()glGetFragDataLocation(1, 0x0018F7DC)glGetAttribLocation(1, InTextureCoordinate) [Context 2 - program 1: shader 2, shader 3]glGetAttribLocation(1, InPosition) [Context 2 - program 1: shader 2, shader 3]glDeleteShader(3) [Context 2 - shader 3]glGetError()glDeleteShader(2) [Context 2 - shader 2]glGetError()glGenTextures(1, {0})glBindTexture(GL_TEXTURE_2D, 1) [Context 2 - Texture 1: No preview available]glGetError()glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) [Context 2 - Texture 1: No preview available]glGetError()glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) [Context 2 - Texture 1: No preview available]glGetError()glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) [Context 2 - Texture 1: No preview available]glGetError()glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) [Context 2 - Texture 1: No preview available]glGetError()glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 100, 100, 0, GL_RED, GL_UNSIGNED_SHORT, 0x00000000) [Context 2 - Texture 1: No preview available]glGetError()glBindTexture(GL_TEXTURE_2D, 0)glClearColor(0.39215687, 0.58431375, 0.92941177, 1)glGetError()glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)glGetError()glUseProgram(1) [Context 2 - program 1: shader 2, shader 3]glGetError()glBindVertexArray(1)glGetError()glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 2)glGetError()glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0x00000000)glGetError()glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)glGetError()glBindVertexArray(0)glGetError()glUseProgram(0) [Context 2 - program 0]glGetError()wglSwapBuffers(0x6D012800) [/source]