Member

64

237 Neutral

• Rank
Member
1. ## Depth of Field Aperture Help

Hi I have written a simple CPU raytracer which just generated this image: I just realized that I am calculating the secondary rays origin incorrectly. I was simply adding a random number to the x and y of the origin point. This is fine when my lookat point is at the same height at my camera position but if it is higher or lower, my square aperture will be tilted. How do I find a random point in the aperture rectangle around my camera? Some code: //primary ray Ray newRay = camera.GetRay(x, y, HEIGHT, WIDTH, antiX, antiY); //convergent point on focal plane Vec3 focalPoint = newRay.calculate(camera.focalLength); double origX = randOrigin(generator); double origY = randOrigin(generator); Vec3 randomOrigin(newRay.origin.x + origX, newRay.origin.y + origY, newRay.origin.z); //direction to focal plane Vec3 focalDir(focalPoint - randomOrigin); focalDir = focalDir.normalized(); newRay = Ray(randomOrigin, focalDir); Thanks
2. ## Spheres not round in every aspect ratio

Thanks guys. I am using C++ with no libraries.  My camera class: Camera::Camera(const Vec3 & p, const Vec3 & l, double fov, double aspect) { position = p; lookAt = l; this->fov = fov; aspectRatio = aspect;   Vec3 tempUp(0, 1, 0);   forward = (lookAt - position).normalized(); right = cross(forward, tempUp).normalized(); up = cross(right, forward);   HEIGHT = tan(fov); WIDTH = HEIGHT * aspectRatio; }   Ray Camera::GetRay(unsigned x, unsigned y, unsigned H, unsigned W, double antiOffsetX, double antiOffsetY) {   double X, Y; X = (2.0*(double)x) / (double)W - 1.0 + antiOffsetX; Y = (-2.0*(double)y) / (double)H + 1.0 - antiOffsetY;   Vec3 direction = forward + X * WIDTH * right + Y * HEIGHT * up;   return Ray(position, direction.normalized()); }   I was about to post this but checked the code in main where I make the camera:   Camera camera(Vec3(0.0, 1.0, 10.0), Vec3(0.0, 1.0, 0.0), PI / 4.0,WIDTH / HEIGHT);   And sure enough, WIDTH and HEIGHT were unsigned ints lol so aspectRatio was always one. God damn :P I must have been tired last night lol.   THANKS!   16:9
3. ## Spheres not round in every aspect ratio

Thanks MissionCtrl I triple checked all my castings etc. I cant see anything wrong. 800x347 - AR = 2.3   It seems to be just that specific aspect ratio. 16:9
4. ## Spheres not round in every aspect ratio

Hi all   I have made a simple ray tracer and all was well until i tried to render a background image for my laptop with a resolution of 1366x768.   When rendering to this aspect ratio of 1.78 my spheres become ovals. In almost every other resolution this doesnt happen. Is there something wrong with my raster space -> camera space code? Or is this some kind of perspective or aspect ratio problem? Thanks 500x500 - AR = 1   800x400 - AR = 2   800x260 - AR = 3 ' 800x450 - AR = 1.78
5. ## Program works in debug but not release

Thanks   The problem was that the dubugger was initializing an array with all zeros but the release version wasnt. Forgot the debugger helped you out a bit :P   Thanks
6. ## Program works in debug but not release

Hi   I have made a real time raytracer that renders a plane, a bouncing sphere and allows motion of the camera via mouse and keys.   I am using visual studio 2015. When i click the green debug play button, everything works fine.   When i build a release or debug version, i double click the exe file, my window opens, the sky and plane renders but the ball is nowhere to be seen and the camera controls dont work.   I am using opengl to render a texture to a quad, opencl for the actual raytracers and sdl2 for inut and window. And using C   Thanks for any tips
7. ## Making realtime raytracer interactive?

Thanks guys.   For the simple task of updating position data, i do only need the write. Before i used interop, i needed to read the image buffer in order to output it to the window. Even so, the write still does a considerable slow down.   Anyway, i think it might just be the case that my old laptop cant handle it and i will probably see much better perfomance on a better machine to the point it will be useable. Time for a new computer :P
8. ## Making realtime raytracer interactive?

cl_gl interop just means that in the above example, i am using an opengl texture, using opencl to change the texture and giving it back to opengl to render it to a quad that covers the screen. No user input, no gpu->cpu reading or writing, it is all done on the gpu and is super fast. The position data is stored in global gpu memory and is updated each frame by a kernel.   If i want to update the position via keyboard i have to send the data to the kernel each frame from the host .         Correct.    clEnqueueWriteBuffer and clEnqueReadBuffer.   These two commands have a lot of overhead and there isnt anyway around them.
9. ## Making realtime raytracer interactive?

I dont see how it can be done any faster. I did a simple experiment where I ray traced one sphere, no reflections, no shading, no lighting, no antialiasing. Just a ray sphere intersection for each pixel per frame. Doing one readbuffer and one writebuffer each frame in opencl did this simple image at 100fps. By eliminating the read and write and using gl_cl interop, it did 1200fps.   Rendering one sphere and one plane with antialiasing and reflections drops it down to 30fps. Doing it with one read and one write takes it below 1fps. This i thought was good considering the same image took over 2 minutes to render one frame 10 years ago. Obviously realtime raytracing is future technology and computers need to improve a fair bit to have a full rt raytracer with a million triangles and radiosity and the rest but in the mean time, this little test shows that the gpu has no problem rendering. The real problem is moving memory between global and host space as far as this little example is concerned. I understand when the scene gets more complex then the update between host and gpu will become less significant, but it is the most significant factor when it comes to moving this particular camera around the above red sphere.
10. ## Making realtime raytracer interactive?

Hi   For the past few days I have been writing a realtime raytracer. I get 150fps with blinn-phong shading, one reflection ray and a gradient sky. It drops to about 30fps with 9 times anti aliasing which is to be expected and i am on a really crappy laptop.     Anyway, it has made me want to turn it into a simple ray traced game. Rendering the frames is the easy part, but making it interactive slows it way down. It is fast because of opencl/opengl interop by sharing a texture between the two eliminating the reading and writing from cpu to gpu each frame. As there is no way to update the position of the camera or objects via user input without sending info from the host without slowing it down, i am at a loss.   Is this the bottleneck everyone faces? Are there any workarounds? Do other platforms do things differently/better?   Curious to see what other people have done in this area. Thanks
11. ## How much money can I make with my game for facebook?

You need money to make money.   Without at least a million dollars for marketing, it is unlikely to make more than a few hundred.
12. ## Need an SDL guru

Tried this too, still no luck: SDL_SysWMinfo sysWindow;  SDL_VERSION(&sysWindow.version); SDL_bool f = SDL_GetWindowWMInfo(gWindow, &sysWindow); printf("SDL_Init failed: %s\n", SDL_GetError()); hDC = sysWindow.info.win.hdc; hGLRC = sysWindow.info.win.window;
13. ## Need an SDL guru

Hi all   I am using SDL2 and I need to get the current window and context to pass to opencl.   I tried:   //get the GL rendering context HGLRC hGLRC = wglGetCurrentContext(); //get the device context HDC hDC = wglGetCurrentDC();   Doesnt work, visual studio says cant read memory.   I then tried:   gContext = SDL_GL_GetCurrentContext(); gWindow = SDL_GL_GetCurrentWindow();   Causes opencl to bug out.   Any help with this would be greatly appreciated. Thanks
14. ## OpenCL not working on every pixel

Thanks Joe.   My original problem was that my image was 600x600 and it needed to be a multiple of 256.   I changed it to 512x512 and the full image gets rendered. What I dont understand is that every realtime raytracer that i have looked at sets up NDRange like I have. Another thing i dont understand is that i run the same program using the cpu and i get 1 frame per second and i gett 30 fps out of the gpu using NULL as local size. If the cpu has a faster clock speed and setting local size to null makes the gpu run one kernel at a time, how come the gpu is 30 times faster?   Thanks again   edit: Never mind, i just read the following in the opencl spec:
15. ## Simple opencl question

Thanks again guys, got it working. Changed this line: clEnqueueUnmapMemObject(queue, &center, CENTERptr, 0, 0, 0); I put the center vector in instead of the buffer :P   She works.   I knew it was going to be faster but not this fast. Its like watching an opengl raster sphere floating around only raytraced.   Insane.