Jump to content
  • Advertisement

mobeen

Member
  • Content Count

    74
  • Joined

  • Last visited

Community Reputation

127 Neutral

About mobeen

  • Rank
    Member
  1. It often helps to render particle sprites as sphere. One it helps to reduces the polygonization which would otherwise be needed and second it too simple to achieve. So without any delay lets see how to put it up in OpenGL3.3. Geometry setup: We store positions of 9 vertices in the global scope as follows. const int TOTAL= 9; GLfloat positions[3*TOTAL]={-1,0,-1, 0,0,-1, 1,0,-1, -1,0, 0, 0,0, 0, 1,0, 0, -1,0, 1, 0,0, 1, 1,0,1}; Next, we setup a vertex array object (VAO) and a vertex buffer object (VBO) for holding the point positions. //Create vao and vbo stuff glGenVertexArrays(1, &vaoID); glGenBuffers (1, &vboID); glBindVertexArray(vaoID); glBindBuffer (GL_ARRAY_BUFFER, vboID); glBufferData (GL_ARRAY_BUFFER, sizeof(positions), &positions[0], GL_STATIC_DRAW); glEnableVertexAttribArray(shader["vVertex"]); glVertexAttribPointer (shader["vVertex"], 3, GL_FLOAT, GL_FALSE,stride,0);glBindVertexArray(0); [size="2"]The shader is handled by using a custom GLSLShader class. Once the vao setup is complete, we proceed with the rendering. //draw the points shader.Use(); glUniformMatrix4fv(shader("MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glBindVertexArray(vaoID); glDrawArrays(GL_POINTS, 0, TOTAL); glBindVertexArray(0); shader.UnUse(); Shaders The vertex shader is a simple passthrough shader computing the clip space position of the points. #version 330 in vec3 vVertex; uniform mat4 MVP; void main() { gl_Position = MVP*vec4(vVertex,1); } The fragment shader calculates the normal from the texture coordinates and then calculates the diffuse contribution. The texture coordinates in case of point sprites are available in the gl_PointCoord variable. #version 330 out vec4 vFragColor; uniform vec3 Color; uniform vec3 lightDir; void main() { // calculate normal from texture coordinates vec3 N; N.xy = gl_PointCoord* 2.0 - vec2(1.0); float mag = dot(N.xy, N.xy); if(mag > 1.0) discard; // kill pixels outside circle N.z = sqrt(1.0-mag); // calculate lighting float diffuse = max(0.0, dot(lightDir, N)); vFragColor = vec4(Color,1) * diffuse; } That's it. Running the code gives the following output.
  2. Hi, Just a quick look at your shader reveals that there is plenty of room for optimization. For e.g instead of cascading the if else loops for determining the step direction u could use the hlsl sign function (http://msdn.microsoft.com/en-us/library/bb509649(v=VS.85).aspx) like so (this is valid in glsl i dont know if HLSL has some similar type). int3 step = sign(eyeRay.dir); For ur (and others) help, i am attaching a complete glsl uniform grid volume raycaster in a GLSL fragment shader that i implemented based on the paper link u gave. U can convert it comfortably to HLSL. Hope this helps. Regards, Mobeen //Assumptions //DIMS -> dim of your dataset //initialization vec3 u = eyeRay.o + t*eyeRay.d; vec3 uVS = (u*0.5+0.5); //from (-1 1) to (0 1) vec3 uVS2 = uVS* DIMS; //convert ot voxel space coords //X,Y,Z are initialized to the starting voxel coords int X = uVS2.x; int Y = uVS2.y; int Z = uVS2.z; int3 step= sign(eyeRay.d); //determine the values of tMaxX, tMaxY and tMaxZ vec3 tMax=vec3(tnear+ 1.0/DIMS); float t2 = mini(tMax); //disard the current fragment if(t2<tnear || t2 > tfar) discard; vec3 tDelta = abs(t2/eyeRay.d) ; bool inside = true; for(int i=0;i<maxSteps;i++) { if(! inside) break; if(tMax.x < tMax.y) { if(tMax.x < tMax.z) { X= X + step.x; if(X >= DIMS.x) inside = false; /* outside grid */ tMax.x = tMax.x + tDelta.x; } else { Z= Z + step.z; if(Z >= DIMS.y) /* outside grid */ inside = false; tMax.z= tMax.z + tDelta.z; } } else { if(tMax.y < tMax.z) { Y= Y + step.y; if(Y >= DIMS.y) /* outside grid */ inside = false; tMax.y= tMax.y + tDelta.y; } else { Z= Z + step.z; if(Z >= DIMS.z) /* outside grid */ inside = false; tMax.z= tMax.z + tDelta.z; } } //Do your stuff here like compositing/triangle intersection etc. vec3 pos = vec3(X,Y,Z)/DIMS; half sample = texture3D(data, pos); //This is just a smple iso-surface ray caster if ( sample>0.1 && (sample -isoValue) < 0 ) { vec3 N = GetGradient(pos); vec3 V = -eyeRay.d; vec3 L = V; fragColor = PhongLighting(L,N,V,250, pos); inside=false; break; } } and here is the rendered output
  3. Quote:Original post by zedz >>I want to render back faces in attchmt0 and front faces in attchmt1. glDepthFunc(); saiz whether or not the depth test fragment passses what u want is either glFrontFace( GL_CCW ) glFrontFace( GL_CW ) or glCullFace( GL_BACK ); glCullFace( GL_FRONT ); Thanks for the reply yeah I have done this already. I wanted to know how I could render on two depth buffers at the same time. Can I do it with a single FBO and two depth attachments or do i need two FBOs each with a single depth attachment?
  4. Hi all, I have an FBO with two textures attached to colorAttchmt0 and 1; I want to render back faces in attchmt0 and front faces in attchmt1. I am doing it as follows AttachFBO(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //render back faces in the attachment 0 glActiveTexture(GL_TEXTURE0_ARB); glDrawBuffers(GL_COLOR_ATTACHMENT0); glDepthFunc(GL_GREATER); glClearDepth(0); RenderStuff(); //render front faces in the attachment 1 glActiveTexture(GL_TEXTURE1_ARB); glDrawBuffer(GL_COLOR_ATTACHMENT1); glDepthFunc(GL_LESS); glClearDepth(1); RenderStuff(); DetachFBO(); Now I only see one rendering result the first render. THe second call is not doign anything. Am i doing anything wrong. Is it possible to swicth the depth test while the rendering is being done on the fbo or do i need 2 fbos for this? Any help would be appreciated. Just one more thing, I can use front and back face culling and it gives correct results. Now I wanted to use depth buffer. But i dont know why it doesnot work? It seems that the FBO always uses the last depth test for all the attachments? Anybody has anythign to add to this? Thanks, Mobeen
  5. Thanks for the reply. Yeah i saw this function but it works for the basic image types like bmp, jpg etc. Actually i managed to make it work. The solution is to use the D3DXFillVolumeTexture giving it the callback function to fill the custom data. This enables me to not only load the data in a file but i could also load procedural data using it. Thanks for the help. Regards, Mobeen
  6. Hi all, This should be quite straightforward but for some reason i m not able to do it. I want to load a 3d texture from a raw binary file. I load the file contents into an array. Then I call D3DXCreateVolumeTexture with the datasets dimensions. I want to know how i may be able to copy the volume file contents into the d3d volume texture. I have been trying to find info on this but its not available. Any pointers to relevant tutorials or text would be appreciated. Thanks, Mobeen [Edited by - mobeen on October 10, 2009 2:24:46 AM]
  7. mobeen

    OpenGL can't make the light right

    HI, I think the shininess value is what is causing problem. Change it to something like 120.
  8. mobeen

    OpenGL Texture problems

    In that case, I would recheck the tga image loading code. Recheck the image loaded to make sure that the texture formats and other flags for glTexParam... are correct. Maybe just disable the targa loading code and replace it with a simple in memory texture like a checker pattern using something like this and see if this works alright. GLubyte pixels[16]={0}; int count=0; for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { if( (i<2 && j<2) || (i>=2 && j>=2)) pixels[count] = 255; count++; } } glGenTextures(1,&textureID); glBindTexture(GL_TEXTURE_2D, textureID); // set the texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,GL_INTENSITY,4,4,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pixels);
  9. mobeen

    OpenGL Texture problems

    Hi, Are you enabling the texture2d target using glEnable(GL_TEXTURE_2D); before u bind the texture to the texture2d target? See this See if this helps, Mobeen
  10. mobeen

    How to do a correct raycast pick?

    Quote:Original post by LorinAtzberger Hi. I've done a raycast picking system and it work but only if the object is not rotated. If it's rotated it tests as if it wasn't I think I have to rotate my ray somehow using the objects rotation and the distance between it and the object. I tried to do this but it doesn't really work. I tried looking around for tutorials but they always focus on how to get a ray out of the camera position. I've done that but now that I must check if they interesect I can't get any info on that. I've tried to do something like this: *** Source Snippet Removed *** p1 and p2 are the the vectors of ray generated from the camera Any suggestions? Hi, I remember facing something similar when I used ray aabb intersection for detection of intersection. The reason for this is when the object rotates, the aabb is invalid and you need to recalculate it for the rotated object. See if this sorts out the problem. Thanks, Mobeen
  11. Hi yalewhd, Quote:Original post by yalewhd I was trying to display two animated scene in one window. in order to get the scene smooth, I used double buffer and the code below: glViewport(0,0,w,h); glLoadIdentity(); gluLookAt(....); displayFunction(); glutSwapBuffers(); glViewport(w,h,2*w,2*h); glLoadIdentity(); gluLookAt(....); displayFunction(); glutSwapBuffers(); when I run the program, I could create two scenes in one window correctly, but the scene is not at all smooth, it's like the effect using single buffer for one scene. How to solve the problem? is there a way to do this using glut? Try removing the first glutSwapBuffers() call like this glViewport(0,0,w,h); glLoadIdentity(); gluLookAt(....); displayFunction(); //glutSwapBuffers(); //remove this call glViewport(w,h,2*w,2*h); glLoadIdentity(); gluLookAt(....); displayFunction(); glutSwapBuffers(); and see if there is any difference?
  12. hi all, Currently, I have managed to calculate the Laplacian by using the slice by slice approach i mentioned in my last post. Now I want to store this Laplacian 2D texture into a 3D texture. Currently, I use FBO to calculate the Laplacian in the fragment shader and show the output on screen. How do i read back from a bound FBO. I know about glReadPixels and glGetTexImage. glReadPixels works but its very very slow, while I m unable to make glGetTexImage work. I always get error 1280 I have tried all the formats. Do i need to detach the FBO and then read ? Currently, I need to store the Laplacian into another 3D texture, is there a way that i can transfer my data directly (after modifying in the fragment shader) to the 3d texture or do i need to read slice by slice and copy to 3D texture myself? This is how my flow is AttachFBO(); SetLaplacianShader(); DrawFullScreenQuad(); //I tried glReadPixels but its very slow don;t know if it works or not //but the opengl error bit is not set glGetTexImage(..); //doesnot work at all i tried all the formats i get error ??? DetachFBO(); Any help will b appreciated. Mobeen [Edited by - mobeen on March 17, 2009 9:21:39 AM]
  13. Hi HHKUPM, Quote:Original post by HHKUPM I did the rendering and but the 3d shape was not complete. Could u please elaborate this? I don't understand what u mean by '3d shape was not complete'? Quote:Original post by HHKUPM I mean it was like slices of x and y separated by z. The tree which i want to render was like separated slices. From this I believe you have a data file containing XY images stacked in the Z axis. Is that what u mean? Quote:Original post by HHKUPM Could u please help me with my problem if possible since ur good in opengl programming? Sure, can u please identify the part that is bothering you perhaps posting the source snippets where applicable? I am not that good at it but atleast I can try to help. Thanks, Mobeen
  14. Hi all, I am developing an application to detect scale space extrema quite similar to how its done in SIFT (scale invariant feature transform). To begin with, i need the Gaussian pyramid. I already have the Gaussian pyramid using the mipmaps. Now i need the Laplacian pyramid that is obtained by subtracting each adjacent Gaussian pyramid image. The thing I want to ask here is what would be the best way of doing this calculation. What I was thinking was to use a fragment shader to find the Laplacian but I dont know how i would store the resulting image. Should i use glReadPixels or would it be too slow. Any ideas? Roughly speaking this is how i m thinking at the moment any input will be greatly apprecited. AttachFBO SetShader3DTextureParam(myGaussianPyramidID); BindFragmentShader(myLaplacianShader); DrawFullScreenQuad(); //Should i use glReadPixels or any other thing??? to get the laplacian image? DetachFBO Thanks, Mobeen
  15. Hi all, I have enabled mipmapping on 3D textures for a simple texture slicer. I have the mipmapping working alright. What i want to do is view all the mipmap levels. I have a small quad rendered on screen that shows the current slice from the 3d texture. I use keyboard to move across the 3d stack. This is working fine. What i want to do now is to cycle through the mipmap levels? how can i do that? I have used gDebugger and it shows all of my mipmap levels along with the data contained in them. I want to do the same but how can i do that? I have one more question about mipmapping currently i have set the min and max filter params to be glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); If i set the max param to anything other than GL_LINEAR, the state machine reports an error. I want to know why i get this behaviour. [EDIT: I managed to do it. For anyone else who might face this, here is how you can change the current mip map level. glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, mipLevel); I would still want to know why i cant set anything else for the magnification param? Thanks, Mobeen [Edited by - mobeen on March 16, 2009 5:55:02 AM]
  • 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!