# junkyska

Members

20

143 Neutral

• Rank
Member
1. ## Problem reconstruction position form depth

Thanks for you response, but yestarday I finally solve it!! (The algorithm I posted here it's not right, i use another one from dark photon). Here there is the resolution: [url="http://www.opengl.org/discussion_boards/showthread.php/179823-Help-reconstructing-pixel-position-from-depth"]http://www.opengl.or...995#post1244995[/url] Thank's for the link I get it before while searching on google.
2. ## Problem reconstruction position form depth

Hi everyone, I'm trying for a few days removing my position texture from my deferred system. To achive this I have to reconstruct pixel position from depth value. I spend some days now (many houres) tring to solve the problem without luck, so I'm somehow frustated. Let's see if someone with better math can help me [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] First how i fill my old position texture (geometry pass). [With this texture the lighting works fine.] [CODE] Geometry pass - Vertex: vsPosition = ( ModelViewMatrix * vec4(in_Position, 1.0) ).xyz; Geometry pass - Fragment: fsPosition = vsPosition [/CODE] Where ModelViewMatrix is ViewMatrix * ModelMatrix. From here all work, and accessing pixel position in the light pass is trivial.The problem occurs when I try to compute pixel position with depth value. I tried many things (many...), and what I have at the moment is: [CODE] vec2 calcTexCoord() { return gl_FragCoord.xy / ScreenSize; } [/CODE] [CODE] vec3 positionFromDepth() { vec2 sp = calcTexCoord(); float depth = texture2D(Texture4, sp).x * 2.0 - 1.0; vec4 pos = InvProjectionMatrix * vec4( sp*2.0-1.0, depth, 1.0); return pos.xyz/pos.w; } [/CODE] Where InvProjectionMatrix is the inverse of the projection matrix, and Texture4 is depth texture. The strange thing is that if I output the absolute diference from both (using texture and using depth), i see black output (no diferences). Following code outputs black screen: (Texture0 is position texture) [CODE] vec3 pos1 = positionFromDepth(); vec3 pos2 = texture2D(Texture0, calcTexCoord()).xyz; fragColor = vec4(abs(pos2.x-pos1.x), abs(pos2.y-pos1.y), abs(pos2.z-pos1.z), 1.); [/CODE] Here is my point light calculation: (With pixel position from depth doesn't work) [CODE] uniform struct { vec3 diffuse; vec3 specular; vec3 ambient; float constantAtt; float linearAtt; float quadraticAtt; float spotInnerCutOff; float spotOuterCutOff; float spotFallOff; vec3 position; // For Point light. Computed as ViewMatrix * light_position vec3 direction; // For Spot and Directional lights int type; // 0-> Point, 1-> Spot, 2-> Directional } Light; ... vec3 computePhongPointLight() { vec3 color = vec3(0.0); vec2 texCoord = calcTexCoord(); //vec3 position = texture2D( Texture0, texCoord ).xyz; vec3 position = positionFromDepth(); vec3 difColor = texture2D( Texture1, texCoord ).xyz; vec3 specColor = texture2D( Texture2, texCoord ).xyz; vec3 normColor = texture2D( Texture3, texCoord ).xyz; vec3 lightDir = Light.position.xyz - position; vec3 lightDirNorm = normalize( lightDir ); float sDotN = max( dot(lightDirNorm, normColor), 0.0); float att = 1.0; float distSqr = dot(lightDir, lightDir); float invAtt = (Light.constantAtt + (Light.linearAtt*sqrt(distSqr)) + (Light.quadraticAtt*distSqr)); att = 0.0; if (invAtt != 0.0) att = 1.0/invAtt; vec3 diffuse = difColor.rgb * Light.diffuse * sDotN; vec3 ambient = difColor.rgb * Light.ambient; // Cheat here vec3 vertexToEye = -normalize(position); vec3 r = normalize(reflect(lightDirNorm, normColor)); // SpecularPower vec3 specular = vec3(0.0); if ( sDotN > 0.0 ) { specular = Light.specular.rgb * specColor * pow( max( dot(vertexToEye, r), 0.0), 60.0 ); // Change specular here!!!! value 60 must be an uniform } return (diffuse + specular + ambient)*att; } [/CODE] I will apraciate any help, so feel free to answer [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] Sorry for my bad English and thanks in advance.
3. ## matematics library

Chek http://glm.g-truc.net/. It's a really nice library with tones of util functions, and ofcorse vectors, matrix, quaternions... It has nearly the same sintax as GLSL and you don't need to link with your project, just include it.
4. ## GLSL spotlight+scale problem

I think it's well calculated normal matrix. I don't know where is the bug, I can't find it. Here is my normal matrix calculation: [CODE] _currentRenderableInfo.renderablePos = actor->getDerivedPosition(); _currentRenderableInfo.renderableRot = actor->getDerivedRotation(); _currentRenderableInfo.renderableScale = actor->getDerivedScale(); _currentRenderableInfo.modelMatrix = actor->getFullTransform(); _currentRenderableInfo.modelViewMatrix = _currentViewInfo.viewMatrix * _currentRenderableInfo.modelMatrix; _currentRenderableInfo.mvpMatrix = _currentViewInfo.projectionMatrix * _currentRenderableInfo.modelViewMatrix; _currentRenderableInfo.normalMatrix = Core::transpose(Core::inverse(Core::mat3(_currentRenderableInfo.modelViewMatrix))); [/CODE]
5. ## OpenGL So I started writing Example Programs

Very good examples, good job! Japro it's really nice!! I like it! [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]
6. ## OpenGL Rendering text using OpenGL

Check glPixelStorei( GL_PACK_ALIGNMENT, 1 ) and glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ).

9. ## OpenGL OpenGL 4 ray test problem

You help me alot! Thanks for sharing your knowlage and for your time.
10. ## OpenGL OpenGL 4 ray test problem

Wow thanks for all that information! I really appreciated it! I will follow your advice and go for a kd-tree for the static meshes. I will study MathGeoLib to undestand his implementation. Just another question, how you deal with transformations (scale, rotation, translation) and kd-tree? You transform the ray to local coordinates before the ray query?
11. ## OpenGL OpenGL 4 ray test problem

Another question, I can't find much information about [url="http://clb.demon.fi/MathGeoLib/"]MathGeoLib[/url]. I see in the source codes that they implement QuadTree and Kd-Tree. You have some examples or something that i can learn about?
12. ## OpenGL OpenGL 4 ray test problem

Wow so much information!! Ok I will go for a CPU aproch. Tha bad new for me is that I have to touch some classes structures and implement a few thinks (actauly more than a few thinks... hehe). I know about kd-tree, what I don't undestand is for animated meshes. Becouse the bones, I will have to move the triangles before performing a ray cast and I don't know any tree structure to do this fast... For AABB check I currently have a Fixed Size Loose Octree Space Partition implementation (currently used for frustum culling). I never see MathGeoLib, I'm currently using GLM, but GLM doesn't have kd-trees and this kind of thinks. I think I can integrate MathGeoLib for ray casting objects and kd-tree the static mesh. I will read information about this library. Thanks a lot.
13. ## OpenGL OpenGL 4 ray test problem

HI everyone, I'm currently implementing a 3d game engine. It's done with c++ and opengl 4. I want to do ray test against meshes. Meshes data reside only in the gpu, not in the cpu. I want to trace a ray against meshes (for example for a gun shoot) and retrive this information: Hit mesh, hit point, hit normal. The ray test hasn't to be a bottleneck, so it has to be fast. What I'm thinking is: First cpu work: Check ray against my loose octree space partition implementation (ray against AABB) to discard meshes. Second gpu work: Here is where i dont know exacly what to do, and I can't find many useful information. What I was thinking is: Create a texture render target with two textures, one RGB (that acts like color attachment) and i will store depth distance, and one RGB32F that it will store point normal. The textures will be 1x1 pixels. Then i can make an orthogonal view matrix with near distance = Ray.start and far distance = Ray.end and this matrix pointing to Ray.Dir. To check each mesh, i will 1- bind the texture render target, 2- bind orthogonal view matrix 3- For each mesh: ---- 4- bind model matrix ---- 5- clear render target, ---- 6- Draw mesh with custom shader (that will draw into this two textures) ---- 7- Retrive textures information ---- 8- Hit point = Ray.start + (Normal(Ray.dir) * toFloat(texture1.rgb)) ---- 9- Normal point = texture2.rgb32f ---- 10- Hit mesh = current mesh I never did this before, so i'm thinking that is not correct. I'm really lost and i can find any useful information. Can someone help me please? I will apreciate any information. Sorry for my bad English. Thanks to all.
14. ## How to draw single pixel in GL 3+ (without fixed pipeline)?

First of all thanks to answer. I'm integrating Gwen ([url="http://code.google.com/p/gwen/"]http://code.google.com/p/gwen/[/url]) a gui library. To achive this, I have to implement my custom UI render. This is mostly done. Gwen define his own render interface, so I have to implement this interface. One of this functions is draw colored rectangle. This function works well. Another function is draw a single pixel. To achive this I call the function that draws a colored rectangle but with the rectangle bounds like that: rect.x = pixel.x, rect.y = pixel.y, rect.heigh = 1, rect.width = 1. The problem comes when the Gui system tries to perform many draw pixel operations. This drops down the frame rate. I attach an image showing that problem (Color pick up), the frame rates drops down to 10 fps. [attachment=7013:draw_pixel_problem.jpg]
15. ## How to draw single pixel in GL 3+ (without fixed pipeline)?

Hi everyone, I'm integrating Gwen (Gui system) in my engine. I'm using Open GL 3+ (without fixed pipeline, all in the shaders). I have a problem drawing a single pixel because it's really SLOW. What I'm doing now is drawing a rectangle with startX = endX and startY = endY, but when the Gui have to render many single pixels (ex: Color pick up box) the frame rate drops down. Is there any efficent way of doing this? Sorry for my English, it's not very good. Thanks.