• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

131 Neutral

About Murloc992

  • Rank
  1. Hello,   recently I was trying to implement a Hamilton path function to generate/fill a grid of points with a snake-like path.   Generally the code I have now miss-performs in the beginning and near the last steps, between those (80% of the generation) everything seems extremely fine. I really cannot find what would be the issue. Seems like my nodes just snap and another, related node gets placed in a completely random spot. Maybe somebody could point out where I did a mistake?   Here is my Pastebin code:   http://pastebin.com/j5RUfXTH   I am using GLM for vec2 class, but a simple struct with int x and y would do.    Thanks in advance!
  2. Was a little bit off from it, but now as I am back, have played a bit with the shader variables, tried multiple things with positions (first thought it was some wrong spaces, apparently not), but I think it's the 4 squares of positions what messes up the look of it. I yet have no idea why final render is split into four parts tho. Could anybody put me on the right track?
  3. Still struggling. Not really sure where I am lost right now. The 4 times split screen looks like it's a position issue, but I am not sure. Maybe my settings are bad or something.. Trying to fix but no avail.
  4. Thank you for your responses. I have fixed my normals and positions calculations accordingly and now, I presume, they are both in ModelView space, which is required for the implementation of this SSAO approach. This is how my buffers and SSAO look now:     I had to convert the SSAO code from what I think is DirectX shading language to GLSL, so there might be some mistakes by me. What I could be doing wrong, to get such distorted 4-piece screen results? This is my SSAO conversion:   Vertex Shader #version 330 layout (location=0) in vec3 pos; layout (location=1) in vec2 tex; out vec4 _pos; out vec2 _uv; void main(void) { _pos = vec4(pos,1); _uv = tex; gl_Position = vec4(pos,1); } Fragment shader #version 330 uniform sampler2D g_buffer_diff; uniform sampler2D g_buffer_norm; uniform sampler2D g_buffer_pos; uniform sampler2D g_random; uniform sampler2D g_depth; const float g_screen_size=1280*768; const float random_size=64*64; const float g_sample_rad=0.006; const float g_intensity=1.38; const float g_scale=0.000002; const float g_bias=0.07; in vec4 _pos; in vec2 _uv; out vec4 fragColor; vec3 getPosition(vec2 uv) { return texture2D(g_buffer_pos,uv).xyz; } vec3 getNormal(vec2 uv) { return normalize(texture2D(g_buffer_norm, uv).xyz * 2.0f - 1.0f); } vec2 getRandom(vec2 uv) { return normalize(texture2D(g_random, g_screen_size * uv / random_size).xy * 2.0f - 1.0f); } float doAmbientOcclusion(vec2 tcoord,in vec2 uv, in vec3 p, in vec3 cnorm) { vec3 diff = getPosition(tcoord + uv) - p; vec3 v = normalize(diff); float d = length(diff)*g_scale; return max(0.0, dot(cnorm,v)-g_bias)*(1.0/(1.0+d))*g_intensity; } void main() { vec2 vecs[4]; vecs[0]= vec2(1,0); vecs[1]= vec2(-1,0); vecs[2]= vec2(0,1); vecs[3]= vec2(0,-1); vec3 p = getPosition(_uv); vec3 n = getNormal(_uv); vec2 rand = getRandom(_uv); float ao = 0.0f; float rad = g_sample_rad/p.z; //**SSAO Calculation**// int iterations = 4; for (int j = 0; j < iterations; ++j) { vec2 coord1 = reflect(vecs[j],rand)*rad; vec2 coord2 = vec2(coord1.x*0.707 - coord1.y*0.707, coord1.x*0.707 + coord1.y*0.707); ao += doAmbientOcclusion(_uv,coord1*0.25, p, n); ao += doAmbientOcclusion(_uv,coord2*0.5, p, n); ao += doAmbientOcclusion(_uv,coord1*0.75, p, n); ao += doAmbientOcclusion(_uv,coord2, p, n); } ao/=iterations*4.0; //**END**// //Do stuff here with your occlusion value âaoâ: modulate ambient lighting, write it to a buffer for later //use, etc. fragColor=vec4(1-ao); } I am lost now.
  5. Wow, that was fast. :) Thank you very much for getting me on track and clarifying!   (Also, saw a very neat trick for alpha you got there! Will definitely try it. :) )   Thanks! Will see how it goes, if I struggle anymore or not.
  6. Hello,   I have currently got into shaders again. Now, I want some clarification.   As I have been googling, reading and all I have come to conclusion about spaces:   Origin is just something you define, like (0,1,0), it's a position from the Model's center or OpenGL coordinate center. Model transform(M) is the so told model center's transform regarding the OpenGL coordinate center. (M*vec) View transform(V) is the Model's transform according to camera, as the camera doesn't move and is at the (0,0,0). (V*M*vec) Projection(P) is what projects the View to Screen. (P*V*M*vec) (Please correct me if I am wrong.)   So now to the problem:   I am trying to implement a Deferred Rendering G-Buffer. I have got a FBO with all the required textures: Diffuse, Depth, Normals, Position, UV(I am not using UVs in my particular sample). The main issue starts here. I know that Diffuse and Depth are okay Out of the Box. I need Normals and Positions in View-Space, for my SSAO implementation. I get that by multiplying normals I have calculated in my Geometry shader by Transpose Inverse View*Model matrix and packing them.   But how do I need to calculate Positions texture? Also, are there any clarifications what exactly are: Model-Space, View-Space, Camera-Space? Are they exactly as I told?   This is my G-Buffer Shader Set:   Vertex: #version 330 // THE FOOD CHAIN GOES LIKE THIS // Vert // Geom // Frag   layout (location=0) in vec3 pos; layout (location=6) in vec4 col;   uniform mat4 M; uniform mat4 V; uniform mat4 P;   out vData {     vec4 color; vec4 pos; }vertex;   void main() { vec4 _col=vec4(col.x/255,col.y/255,col.z/255,col.w/255); mat4 MVP = P*V*M; vertex.color=_col; vertex.pos=vec4(pos,1.0); gl_Position = MVP * vec4(pos,1); }   Geometry #version 330 // THE FOOD CHAIN GOES LIKE THIS // Vert // Geom // Frag   layout (triangles) in; layout (triangle_strip, max_vertices=3) out;   uniform mat3 normMatrix; uniform mat4 M; uniform mat4 V; uniform mat4 P;     in vData {     vec4 color; vec4 pos; }vertex[];   out vec3 normal; out vec4 color; out vec4 position;   void main() { vec3 calcNorm=normalize(normMatrix*cross(vertex[1].pos.xyz - vertex[0].pos.xyz, vertex[2].pos.xyz - vertex[0].pos.xyz))*0.5+0.5; normal = calcNorm; color = vertex[0].color; position = M*vertex[0].pos;     gl_Position = gl_in[0].gl_Position;     EmitVertex(); normal = calcNorm; color = vertex[1].color; position = M*vertex[1].pos;     gl_Position = gl_in[1].gl_Position;     EmitVertex(); normal = calcNorm; color = vertex[2].color; position = M*vertex[2].pos;     gl_Position = gl_in[2].gl_Position;     EmitVertex();     EndPrimitive(); }   Fragment #version 330 // THE FOOD CHAIN GOES LIKE THIS // Vert // Geom // Frag   in vec4 position; in vec3 normal; in vec4 color;   layout (location = 0) out vec3 Gdiffuse; layout (location = 1) out vec3 Gnormal; layout (location = 2) out vec3 Gposition; layout (location = 3) out vec3 Gtexcoord;   void main(){   Gdiffuse = color.rgb; Gnormal = normal; Gposition = position.rgb; Gtexcoord = vec3(0); }   This is how it looks: (Upper left - diffuse, Lower left - random normals for SSAO, Right - Depth, Normal, Position, UV)   ( Yeah, it's a voxel engine, generic. But it's really fun learning to optimize and all.  Nothing more satisfying than to see it be faster and more memory efficient. )  
  7. Thanks for an answer. I know how to stream the buffers with the bind. My question is about how to avoid the bind, or it is unavoidable. :?
  8. Hello, I am writing here with a question which was haunting me lately. I want to draw some dynamic data using a VAO, but I am not pretty sure how to do it. Doing it the regular dynamic/stream VBO way it works, but when I do it with a VAO I need to bind the buffer I want to change and while using gDebugger I found out that those binds in dynamic/stream functions are pretty expensive and gDebugger doesn't recommend using those, so I want to know how should I draw a dynamic VBOs in a VAO? Thanks in advance! Andrew.
  9. I think I have managed to pretty much fix it by converting light's position to eyespace(?) by multiplying modelView matrix by light position in the vertex shader and then outputting it to fragment shader. Now it looks properly, like it's supposed to, but I still want some clarification why is it so. Here's the output now: [img]http://imageshack.us/a/img838/9857/behind.png[/img] (The light's behind.) [img]http://imageshack.us/a/img838/7428/infront.png[/img] (The light's in front.)
  10. Hello, I would like to find a solution for the problem which is haunting me lately. I am starting to use OpenGL3.3+ and shaders(I've been using immediate mode for 2D rendering most of the time, and Irrlicht 3D rendering engine.), so I am practically new at those. After some time fiddling with the new syntax and shaders, I've finally came to the lighting stage and tried to implement phong lighting, everything seemed okay at first, but then I realised it's screwed. After a day and a half of trying to fix it, intense googling for the same problem, I couldn't find a solution. My problem is simple: Light is orientating with camera even if it's in a static place(like 0,0,100) so if it's lighting the back of the model, the front is lit, and even more strangely, when I go away from the dark side, it lights up.. Here's a screenshot: [img]http://imageshack.us/a/img43/6166/lightz.png[/img] (Light is in front of the model, while the back is being lit brightly as I am far away.) Here's my phong shader, I've taken it from Anton's OpenGL4 wiki and added texturing support: phong.fs [CODE]#version 400 in vec4 vpeye; // fragment position in eye coords in vec4 vneye; // surface normal in eye coords in vec2 UV; // UV coordinates uniform vec4 lightPosition; // light position in eye coords uniform vec4 Ka; // ambient coefficient uniform vec4 Kd; // diffuse coefficient uniform vec4 Ks; // specular coefficient uniform float Ns; // specular exponent uniform vec4 Ld; // diffuse light colour // Values that stay constant for the whole mesh. uniform sampler2D myTextureSampler; layout (location = 0) out vec4 fragmentColour; void main() { vec4 n_eye = normalize(vneye); // normalise just to be on the safe side vec4 s_eye = normalize(lightPosition - vpeye); // get direction from surface fragment to light vec4 v_eye = normalize(-vpeye); // get direction from surface fragment to camera vec4 h_eye = normalize(v_eye + s_eye); // Blinn's half-way vector //vec4 r_eye = reflect(-s_eye, vneye); // Phong's full reflection (could use instead of h) vec4 Ia = vec4(0.1,0.1,0.1,1) * Ka; // ambient light has a hard-coded colour here, but we could load an La value vec4 Id = Ld * Kd * max(dot(s_eye, n_eye), 0.0); // max() is a safety catch to make sure we never get negative colours vec4 Is = vec4(1,1,1,1) * Ks * pow(max(dot(h_eye, v_eye), 0), Ns); // my ambient light colour is hard coded white, but could load Ls fragmentColour = texture( myTextureSampler, UV ).rgba *(Ia + Id + Is); }[/CODE] phong.vs [CODE]#version 400 layout (location = 0) in vec3 vertexPosition; layout(location = 1) in vec2 vertexUV; layout (location = 2) in vec3 vertexNormal; uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform mat3 normalMatrix; // Output data ; will be interpolated for each fragment. out vec2 UV; out vec4 vpeye; out vec4 vneye; void main() { vpeye = modelViewMatrix * vec4(vertexPosition, 1.0); vneye = vec4(normalMatrix * vertexNormal, 0); UV = vertexUV; gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1.0); }[/CODE] Also, I think this might be related to my matrices. I load the model with assimp so the normals are correct. The other matrices are set like this: The ModelView matrix: [CODE]glm::mat4 ModelView=cam->getView()*Model; glUniformMatrix4fv(MVMat,1,GL_FALSE,&ModelView[0][0]);[/CODE] The NormalMatrix: [CODE]//The "normal matrix" is an inverse*transpose of the model*view matrix glm::mat4 normat=glm::inverse(glm::transpose(ModelView)); glUniformMatrix3fv(NMat,1,GL_FALSE,&glm::mat3(normat)[0][0]);[/CODE] How I calculate the view matrix: [CODE]// Camera matrix _view = glm::lookAt( _pos, // Camera is here _pos+direction, // and looks here : at the same position, plus "direction" up // Head is up (set to 0,-1,0 to look upside-down) );[/CODE] Hope you can help a poor noobley out and explain some things. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  • Advertisement