Jump to content
• Advertisement  # Weton

Member

13

453 Neutral

## About Weton

• Rank
Member
1. It took me much longer than I'd like to admit, but I solved it. I thought that lightDir was simply lightPos - fragmentPos, but in fact it was normalized. So calculating depth from a normlaized vector won't work. Now it works as expected :)
2. Hi,   I try to do omnidirectional shadows, but I have problems comparing the depth values stored in the cube map with the frament positions.   To fill the cube map with the depth values I render my scene in each face with the differend view matrices (in world space) and use the hardware depth buffer. I checked the resultig cube map and it seems to have the right values stored in it. Then I render my scene and look up the depth values in the cube map and try to compare them to the depth value of the projected fragment position. The depth from the cube map is in the [0,1] range as expected, but my calcualted fragment deph (depth_from_pos(lookup)) returns values in the range [-1,0] and if I render them, they don't look quite right. uniform samplerCube texShadow; float depth_from_pos(vec3 pos) { // near and far used by the projection matrix for the cube map faces float n = 1.0; float f = 100.0; //// calculate the major depth axis -> max(abs(pos)) vec3 abs_pos = abs(pos); float z = max(abs_pos.x, max(abs_pos.y, abs_pos.z)); //// project pos to get the z and depth value // p_light = [[n,0,0,0], [0,n,0,0], [0,0,-(f+n)/(f-n),-2*f*n*(f-n)], [0,0,-1,0]] // right = top = 1 // clip = p_light * vec(0,0,-z,1.0) // depth = (clip.z / clip.w) * 0.5 + 0.5 // divide by w and transform ndc [-1,1] to [0,1] float depth = -f*n/(z*(f-n)) + f/(f-n); return depth; } ... // transform light direction from view space to world space // as the cube map faces are in world coordinates vec3 lookup = mat3(view_inv) * vec3(lightDir); float shadow_depth = texture(texShadow, normalize(lookup)).r // get depth of pixel position from the light source float frag_shadow_depth = depth_from_pos(lookup); float visibility = 1.0; if (shadow_depth < frag_shadow_depth) { visibility = 0.0; } ... This is the rendered frag_shadow_depth+1 of a scene with a plane with some cubes seen from above. The light is a bit over the plane in the center of the image. [attachment=30131:bad depth.png] I would have suspected something which is dark in the center and gets brighter to the edges without this 'x'.   I suspect the error in the depth_from_pos function, but I don't know what I'm doing wrong. Does anybody have some ideas?   Thanks in advance
3. Yes, I'd calculate the matrices in advance, but I couldn't find my mistake for so long, so I just left it in there ;)   I took the functions from a library. So when you asked me for the code I looked it up and noticed that it didn't work as expected.   So I used this perspective matrix and everything works : let p = Mat4::new( near/right, 0. , 0. , 0. , 0. , near/left, 0. , 0. , 0. , 0. , -(far+near)/(far-near), -2.*far*near/(far-near), 0. , 0. , -1. , 0. , ); Thank you a lot for asking the right question
4. Hi there, I try to make a deferred renderer, but it seems like my normals don't face the direction I expcted. I successfully created a framebuffer with 3 targets color, normal and depth/stencil to wich I can draw and read from in my shaders. I calculate the view (looking at negative z, up is positive y) and projection matrices wich results in these values: v:{ m11: -1, m21: 0, m31: 0, m41: 0, m12: 0, m22: 1, m32: 0, m42: 0, m13: 0, m23: 0, m33: -1, m43: 0, m14: 0, m24: 0, m34: 0, m44: 1 } p:{ m11: -1.2990379, m21: 0, m31: 0, m41: 0, m12: 0, m22: 1.7320507, m32: 0, m42: 0, m13: 0, m23: 0, m33: 1.020202, m43: 1, m14: 0, m24: 0, m34: -2.020202, m44: 0 } stored in column major order: m11,m21,m31,m41,m12,... In the fist pass I render all my ojects to the framebuffer using the following shader: #version 420 #extension GL_ARB_explicit_attrib_location : require #extension GL_ARB_explicit_uniform_location : enable //CAMERA layout(binding=1) uniform CameraBlock { mat4 v; mat4 p; mat4 p_v; //P*V //... }; //... //MESH layout(binding=3, std140) uniform MeshBlock { mat4 m; }; //VERTEX_SHADER layout(location=0) in vec3 inPos; layout(location=1) in vec2 inTexCoord; layout(location=2) in vec3 inNormal; out vec2 texCoord; out vec3 normal; void main() { gl_Position = p_v*m * vec4(inPos, 1.0); texCoord = inTexCoord; normal = normalize(transpose(inverse(mat3(v*m))) * inNormal.xyz); } Using the view and perspective matrix from above the normals point in the wrong (?) direction. But when I only use 'm' instead of 'v*m' I get the result I expected. [attachment=29360:normals.png] Are my matrices wrong or didn't I calculate the normals correctly? I am surprised, that the view matrix isn't an identity matrix. Thank you in advance for your help
5. Thanks to both of you. Sure ;) But it could cancel the operation when I call SwapBuffers And yes, I bound a sampler when I bound the texture. But why is it important to know the min and mag filters when I write to a texture?
6. After I added an object, that is using the texture it seems to work. Is it possible, that opengl noticed that I was never reading data from the framebuffer and skipped rendering?
7. Yes, the viewport is set to the same width and height as the textures. (I updated the source)
8. Hi,   I'm trying to clear/draw to a framebuffer but I don't get the expected result. Instead of the clear color/expected object the framebuffer stays black with some white pixels. After running the application multiple times the white pixel pattern changes slightly (=> due to uninitialized memory?). glGetError returns NO_ERROR and glCheckFramebufferStatus returns FRAMEBUFFER_COMPLETE. Does anybody know what's going wrong?   This is the content of the framebuffer taken from apitrace after the glClear Color0: [attachment=23132:Color0.png] Depth: [attachment=23133:Depth.png] Stencil: [attachment=23134:Stencil.png]   This are the opengl calls duped by apitrace glGenVertexArrays(n = 1, arrays = &1) glGenFramebuffers(n = 1, framebuffers = &1) glGenTextures(n = 1, textures = &1) glBindTexture(target = GL_TEXTURE_2D, texture = 1) glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_RGBA16F, width = 640, height = 480) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1) glGenTextures(n = 1, textures = &2) glBindTexture(target = GL_TEXTURE_2D, texture = 2) glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_RGBA16F, width = 640, height = 480) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1) glGenTextures(n = 1, textures = &3) glBindTexture(target = GL_TEXTURE_2D, texture = 3) glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_DEPTH24_STENCIL8, width = 640, height = 480) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1) glGenTextures(n = 1, textures = &4) glBindTexture(target = GL_TEXTURE_2D, texture = 4) glTexStorage2D(target = GL_TEXTURE_2D, levels = 1, internalformat = GL_DEPTH24_STENCIL8, width = 640, height = 480) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_BASE_LEVEL, param = 0) glTexParameteri(target = GL_TEXTURE_2D, pname = GL_TEXTURE_MAX_LEVEL, param = 1) //compiling shders genBuffers... no framebuffer operations glViewport(x = 0, y = 0, width = 640, height = 480) glBindFramebuffer(target = GL_DRAW_FRAMEBUFFER, framebuffer = 1) glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_COLOR_ATTACHMENT0, texture = 1, level = 0) glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_COLOR_ATTACHMENT1, texture = 2, level = 0) glFramebufferTexture(target = GL_DRAW_FRAMEBUFFER, attachment = GL_DEPTH_STENCIL_ATTACHMENT, texture = 3, level = 0) glClearColor(red = 0.3, green = 0.3, blue = 0.3, alpha = 1) glDepthMask(flag = GL_TRUE) glClearDepth(depth = 1) glClear(mask = GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) Thank you for your help!
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!