
Advertisement
bladerunner627
Member
Content count
150 
Joined

Last visited
Community Reputation
291 NeutralAbout bladerunner627

Rank
Member

Raytracing  Primitive Shape Distortions
bladerunner627 replied to bladerunner627's topic in Graphics and GPU Programming
Thank you :) I better read up in one of my computer graphic books I believe the math is in there. I'll let you know how it works out, won't have anything for a few weeks due to finals. Thanks again! 
Inverse of 4x4 matrix
bladerunner627 replied to SteveDeFacto's topic in General and Gameplay Programming
I'll admit I've never implemented the routine you've mentioned but for the very same reason you make your suggestion over cofactors, it seems more difficult to implement. Here's my implementation, I've never thoroughly benchmarked but it's sufficient for my needs. i, j, k, and l are the matrix row vectors. Vec4<T> i, j, k, l; T Determinant() { T x = l.x*(i.y*(j.z*k.wj.w*k.z)  i.z*(j.y*k.wj.w*k.y) + i.w*(j.y*k.zj.z*k.y)); T y = l.y*(i.x*(j.z*k.wj.w*k.z)  i.z*(j.x*k.wj.w*k.x) + i.w*(j.x*k.zj.z*k.x)); T z = l.z*(i.x*(j.y*k.wj.w*k.y)  i.y*(j.x*k.wj.w*k.x) + i.w*(j.x*k.yj.y*k.x)); T w = l.w*(i.x*(j.y*k.zj.z*k.y)  i.y*(j.x*k.zj.z*k.x) + i.z*(j.x*k.yj.y*k.x)); return (x + y + z + w); } Mat4x4<T> Adjoint() { Mat4x4<T> adj; // Transposed matrix of cofactors // First row adj.i.x = (j.y*(k.z*l.wk.w*l.z)  j.z*(k.y*l.wk.w*l.y) + j.w*(k.y*l.zk.z*l.y)); adj.i.y = (i.y*(k.z*l.wk.w*l.z)  i.z*(k.y*l.wk.w*l.y) + i.w*(k.y*l.zk.z*l.y)); adj.i.z = (i.y*(j.z*l.wj.w*l.z)  i.z*(j.y*l.wj.w*l.y) + i.w*(j.y*l.zj.z*l.y)); adj.i.w = (i.y*(j.z*k.wj.w*k.z)  i.z*(j.y*k.wj.w*k.y) + i.w*(j.y*k.zj.z*k.y)); // Second row adj.j.x = (j.x*(k.x*l.wk.w*l.z)  j.z*(k.x*l.wk.w*l.x) + j.w*(k.x*l.zk.z*l.x)); adj.j.y = (i.x*(k.z*l.wk.w*l.z)  i.z*(k.x*l.wk.w*l.w) + i.w*(k.x*l.zk.z*l.x)); adj.j.z = (i.x*(j.z*l.wj.w*l.z)  i.z*(j.x*l.wj.w*l.x) + i.w*(j.x*l.zj.z*l.x)); adj.j.w = (i.x*(j.z*k.wj.w*k.z)  i.z*(j.x*k.wj.w*k.x) + i.w*(j.x*k.zj.z*k.x)); // Third row adj.k.x = (j.x*(k.y*l.wk.w*l.y)  j.y*(k.x*l.wk.w*l.x) + j.w*(k.x*l.yk.y*l.x)); adj.k.y = (i.x*(k.y*l.wk.w*l.y)  i.y*(k.x*l.wk.w*l.x) + i.w*(k.x*l.yk.y*l.x)); adj.k.z = (i.x*(j.y*l.wj.w*l.y)  i.y*(j.x*l.wj.w*l.x) + i.w*(j.x*l.yj.y*l.x)); adj.k.w = (i.x*(j.y*k.wj.w*k.y)  i.y*(j.x*k.wj.w*k.x) + i.w*(j.x*k.yj.y*k.x)); // Fourth Row adj.l.x = (j.x*(k.y*l.zk.z*l.y)  j.y*(k.x*l.zk.z*l.x) + j.z*(k.x*l.yk.y*l.x)); adj.l.y = (i.x*(k.y*l.zk.z*l.y)  i.y*(k.x*l.zk.z*l.x) + i.z*(k.x*l.yk.y*l.x)); adj.l.z = (i.x*(j.y*l.zj.z*l.y)  i.y*(j.x*l.zj.z*l.x) + i.z*(j.x*l.yj.y*l.x)); adj.l.w = (i.x*(j.y*k.zj.z*k.y)  i.y*(j.x*k.zj.z*k.x) + i.z*(j.x*k.yj.y*k.x)); return adj; } // Inverse using Kramer's rule. Mat4x4<T> Invert() { Mat4x4<T> adj = Adjoint(); T invdet = 1; // If the determinant is 0 there is no inverse. // 1/0 == undefined. if(Determinant() != 0) invdet = 1/T(Determinant()); Mat4x4<T> inv; inv.i = adj.i * invdet; inv.j = adj.j * invdet; inv.k = adj.k * invdet; inv.l = adj.l * invdet; return inv; } There's a lot of room for optimization. If the OP is going for speed/efficiency I'd recommend the looking into LU decomposition. 
Inverse of 4x4 matrix
bladerunner627 replied to SteveDeFacto's topic in General and Gameplay Programming
Quote:Original post by sooner123 Solving by using the cofactors is actually much harder and laborious than solving it directly. Inverting a square matrix is the same as solving a system of four equations. This can be easily done by appending the identity matrix and converting the left half to reduced row echelon form. The op didn't really specify whether this was for implementation or if he was to do it by hand. If doing by hand using an augmented matrix as you've shown is the easiest but trying to do the same with code isn't very practical. Since this is under General Programming I'd assume he wants a method ideal for implementation. 
Inverse of 4x4 matrix
bladerunner627 replied to SteveDeFacto's topic in General and Gameplay Programming
mathworld has a really good article on this http://mathworld.wolfram.com/MatrixInverse.html This can be easily solved using Cramer's rule. Find the determinant of the matrix and invert the result then multiply that by the transposed matrix of cofactors. Another relevant article: http://en.wikipedia.org/wiki/Cramer's_rule Hope that helps! 
Raytracing  Primitive Shape Distortions
bladerunner627 replied to bladerunner627's topic in Graphics and GPU Programming
Quote:Original post by _Sauce_The field of view is defined by the distance between the image plane and your camera origin. You may find it easier to specify the FOV directly in your calculations. Oh..oh...doooh! Well that would probably be it then. How would I calculate the appropriate distance for a given FOV? 
Raytracing  Primitive Shape Distortions
bladerunner627 replied to bladerunner627's topic in Graphics and GPU Programming
Gere's a before and after. The first is before translation, the second is the sphere translated to units two the right. The third one is down one unit, left one unit. Looks like some really funky FOV. [Edited by  bladerunner627 on December 5, 2010 8:50:31 PM] 
Raytracing  Primitive Shape Distortions
bladerunner627 replied to bladerunner627's topic in Graphics and GPU Programming
I should've mentioned that the w values for the Vec4 aren't being used here. I do need to go back and change that, anyways that's not the culprit with the bug. 
Quote:Original post by Sirisian I've never installed any. I still find it odd how java asks if you want to install the yahoo one or something. So old school. *cough* I always loved this image: [snip] o_O I hope that's running on some sort of virtual machine, haha.

Raytracing  Primitive Shape Distortions
bladerunner627 replied to bladerunner627's topic in Graphics and GPU Programming
I thought it might be helpful to show you the ray normals that are being generated Red color values for x, G for y. 
Raytracing  Primitive Shape Distortions
bladerunner627 posted a topic in Graphics and GPU Programming
I started writing a simple raytracer on Friday night but I've hit a snag. My shortterm goal was to create a 100% reflective sphere more or less in the center of the scene and a "full bright" opaque colored plane below it to demonstrate the sphere reflecting the rays. For my test case at the moment I am only rendering an opaque sphere. Unfortunately, for some reason whenever I change the sphere's origin in the scene instead of simply translating to that position it seems to stretch across whatever axis I'm moving it on. At first I pondered whether my ray normals weren't being generated right but it looks correct to me. void generateRays() { // Generate rays for(uint32 i(0); i < width; ++i) { for(uint32 j(0); j < height; ++j) { Vec4<float> p((float)i, (float)j, 0.0f); Vec4<float> d = p  origin; pRays[j].setDone(false); d.Normalize(); pRays[j].setOrigin(origin); pRays[j].setDirection(d); } } } My next thought was maybe it's the sphereray intersection... again I poured over this for several hours but nothing sticks out. bool testRay(jb_ray* ray) { Vec4<float> dir = ray>getDirection(); Vec4<float> org = ray>getOrigin(); // quadratic equation. float a = dir * dir; dir *= 2; Vec4<float> omo = org  origin; float b = dir * omo; float c = omo*omo  radius*radius; float quad = b*b4*a*c; float time0 = 1.0f; float time1 = 1.0f; if(quad > 0) { time0 = (b + sqrt(quad)) / (2*a); time1 = (b  sqrt(quad)) / (2*a); } else if(quad == 0) time0 = (b / (2*a)); else { return false; } Vec4<float> t0Origin ( (ray>getOrigin().x + ray>getDirection().x) * time0, (ray>getOrigin().y + ray>getDirection().y) * time0, (ray>getOrigin().z + ray>getDirection().z) * time0 ); ray>setOrigin(t0Origin); // Calculate new ray normal. Vec4<float> t0Normal(t0Origin); t0Normal = origin; float invRadius = 1.0f/radius; t0Normal *= invRadius; t0Normal.Normalize(); ray>setDirection(t0Normal); ray>setColor(diffuse); ray>incReflections(); // Lets ignore secondary intersections... for now.. // In this case it would be the point the // ray leaves the sphere. /* Vec4<float> t1Normal (ray>getOrigin().x + ray>getDirection().x, ray>getOrigin().y + ray>getDirection().y, ray>getOrigin().z + ray>getDirection().z); t1Normal *= t1; t1Normal  origin; t1Normal *= iRad; t1Normal.Normalize(); */ return true; } My render routine is pretty straight forward (though inefficient), generate the rays, and trace them by checking if there's an intersection between every object in the scene and set the pixel color to corresponding the ray's resulting color. void traceRays() { for(uint32 i(0); i < width; ++i) { for(uint32 j(0); j < height; ++j) { jb_ray* ray = &pRays[j]; bool intersected = true; while(intersected) { if(ray>isDone()) break; if(ray>numReflections() > MAX_RAY_REFLECTIONS) break; if(shapes.size() == 0) break; for(uint32 k(0); k < shapes.size(); ++k) { intersected = shapes[k]>testRay(ray); if(intersected) if(shapes[k]>isOpaque()) break; } } } } } void Render() { glClear(GL_COLOR_BUFFER_BIT  GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); // We'll just ignore resizing for now... glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); rayGen.generateRays(); rayGen.traceRays(); for(uint32 i(0); i < SCREEN_WIDTH; ++i) { for(uint32 j(0); j < SCREEN_HEIGHT; ++j) { jb_ray* ray = rayGen.getRay(i, j); pixels[j*SCREEN_WIDTH + i] = ray>getColor(); } } glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glutSwapBuffers(); } Any help would be greatly appreciated :) Thank you! 
Yeah, I'm still alive. Schools wrapping up, got finals starting next week so hopefully I'll be getting more done on Quadrion Engine after that. Speaking of Quadrion Engine, it's a large endeavor that Shawn Simonson, Renato Ciuffo, Kieran Culliton, and I have been working on for a few years granted my input has been a bit variable. Lately we've been making immense amount of progress as Shawn has implemented a dynamic lighting system which uses a defered approach. What follows is a video showing off the SSAO and dynamic lighting working simultaneously. On my 'acceptable' GeForce 9500M (mobile) 512MB I get about 45fps on average which is damn good considering you could conceivably have an unlimited amount of dynamic lights on the screen and not have much of a performance hit (if at all) though I'm not sure about overdraw. Anyways, enough of that here's the video WATCH IN HD, it's set to Synchronicity 2 by The Police =D. CLICK HERE FOR VIDEO ;) Also, don't forget to check out Moogen Studios which is our development blog. I believe Shawn's going to be make some video blogs in the very near future, so those that are interested in some technical details and theory you'll soon find yourself indulged; he's a great speaker. Peace

I finally convinced my close friend Shawn Simonson to create a blog for his work on Quadrion Engine and other miscellaneous technical endeavors. He has a way with words; I'm sure that anyone who even bothers to peek at my blog will find themselves quite a bit more indulged with what he has to say. I might start mirroring the posts from there due to my sheer lack of content. Check it out http://quadrionengine.blogspot.com/ :)

So with the little time I have to code, I've managed to get a little bit done on the engine. One thing that's always bugged me when creating game/render windows is picking the 'right' resolution by default for the user. To combat this issue I wrote a window creation function that does just that. int OpenQuickWindow(bool fullscreen) is the prototype for it. Basically, when the method is called it grabs a list of available video modes and removes the video modes with the lowest RGB bit values. If true is passed to it then we assume the user wants the highest resolution videomode available from the list for fullscreen, otherwise we pick a lower resolution mode (but not the lowest) that way windowed mode isn't taking up his/her entire screen. It's probably not the best routine but it works. My only concern is when you're dealing with weird aspect ratios, like mine for example (16:9) which has 1366 x 768 AND 1365 x 768. Right now it's picking 800x600 for windowed mode on my system which is perfect, I need to test it on other systems before I get too excited.

Microsoft's STL implementation slow?
bladerunner627 commented on bladerunner627's blog entry in Odorless Entertainment
Those tests were done in Release mode. 
Microsoft's STL implementation slow?  2
bladerunner627 posted a blog entry in Odorless Entertainment
Thanks everyone, I've received a lot of helpful comments and I was able to solve the problem. Apparently, regardless of whether you're in release mode or not, Microsoft's vectors do some 'other' stuff in the background. So, in order to fix this issue you have to use these preprocessor definitions: #define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #define _SECURE_SCL 0 #define _HAS_ITERATOR_DEBUGGING 0 I still think it's a bit silly that they assume you want iterator checking, etc on but w/e.

Advertisement