Guy Named Zach

  • Content count

  • Joined

  • Last visited

Community Reputation

126 Neutral

About Guy Named Zach

  • Rank
  1. OpenGL Trouble with uniform matrices

    I've just come to the realization that I am an idiot and shouldn't be writing shaders. This is a very profound feeling.   My Vertex Shader was fine. My client code was fine. My fragment shader was varying the intensity of colors by the dot product of their normal and the forward vector, setting alpha to 0.   Thank you gentlemen for your help.
  2. OpenGL Trouble with uniform matrices

    I *think* my glUniformMatrix4fv calls are correct. My program has a class called 'ShaderProgram' which I use to spin up shaders, bind attributes, and get uniform locations. The object itself queries each uniform location ONCE and stores it in its own lookup table. It has a helper function that lets me update my matrix uniforms, referencing them by name.   I've stumbled upon some extra wierdness fiddling with this thing. In transitioning to the 2-matrix scheme I have set uProjection to the Identity matrix and uModelView to (Frustum x Translate x Rotate x Translate), and I set the vertex shader to set gl_Position = uProjection x uModelView x v_in. This works, but if I switch the values of uModelView and uProjection, only some faces show. This is extreemly odd since one matrix is just an Identity matrix and shouldn't really affect the output. (in other words, for Matrices M and I, I expect to see MxI=IxM, but that is not the case for some reason).     ----------------------Shader Initialization Snippet:-------------------------- GL20.glAttachShader(program_id, vertex_shader_id); GL20.glAttachShader(program_id, fragment_shader_id); GL20.glLinkProgram(program_id);   // Delete Shader objects GL20.glDeleteShader(vertex_shader_id); GL20.glDeleteShader(fragment_shader_id); // Get Uniform Locations if (uniforms != null) {//Check if uniform locations are needed Uniform_Location.clear();//Clear old uniform locations. needed if program is being recreated for (int i = 0; i < uniforms.length; i++) {// For each uniform name get its location and store it in a lookup table. Uniform_Location.put(uniforms[i], GL20.glGetUniformLocation(program_id, uniforms[i])); } }   --------------glUniformMatrix4f usage-------------------------------   ByteBuffer matrix_buffer = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()); //JAVA DIRECT NIO BUFFER, for use with LWJGL   public void UniformMatrix(String name, float[] m) { Integer location = Uniform_Location.get(name);//Lookup uniform location from table if (location != null) { matrix_buffer.clear();//Restart write at beginning of buffer matrix_buffer.asFloatBuffer().put(m).flip(); //Write to buffer and set its capacity GL20.glUniformMatrix4f(location, 1, false, matrix_buffer);//Send the matrix data to opengl } return; }
  3. I've begun creating my own matrix stack to get away from legacy opengl. I'm having some difficulty with setting up a GLSL vertex shader to take two uniform matrices.  I currently have a working shader that takes a single uniform matrix (a full ModelViewProjection matrix) and renders my object correctly. When I attempt to split out  that matrix into its Projection and ModelView Matrices and pass them in, the scene does not render. -------------------------------------------------------------------- #version 330    uniform mat4 uProjection; uniform mat4 uModelView;     in vec3 v; in vec3 vt; in vec3 vn;   smooth out vec3 out_vn; smooth out vec3 out_vt; smooth out float depth;   void main(){ gl_Position = uProjection * uModelView * vec4(v,1); out_vn = (uModelView * vec4(vn,0)).xyz; out_vt = vt; depth = gl_Position.z; } ---------------------------------------------------------------------- uProjection is calculated just before glUniformMatrix is called (the projection is equivalent to glFrustum). uModelview is  the product of three matrices:  Translation(0,0,-8) * Rotation(r,1,1,0) * Rotation(-.5f,-.5f,-.5f);   Is there anything special about using more than one uniform matrix input?
  4. After reading the article "Simplex Noise Demystified" I thought I had a decent grasp of the topic and tried to create a noise generator for the terrain in my minecraft clone. The output is decent but it has some really hard edges that show up in the output. Does anyone have an Idea what may cause this?
  5. Within the past year I've taken up graphics programming with OpenGL and have made Blender my preferred tool for creating obj models to load. Right now I need a cube and I thought I could use Blender's default cube. This may sound nitpicky, but my output OBJ contains seven normals instead of six, and a corner is off slightly (off by 1.0e-5 units). Blender says my corners are correct though. Can I avoid this error somehow? Having axis aligned normals is something I want right now.