3d engine programming blog
#1
Posted 04 January 2009 - 03:22 PM
Everything is free for you to use
http://vp8671.blogspot.com/
Bye
http://www.binpress.com/browse/c
#2
Posted 05 January 2009 - 05:45 AM
I read a lot of the first page, and even though its just basic information, its actually refreshing to read the begginner level stuff every once in a while. Its like a good breather from the 300+ pages of code I'm usually swimming around in.
Well anyway, keep with interesting updates and you'll at least have one reader :)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!
#3
Posted 05 January 2009 - 11:57 AM
In few days i will post all my fastmath library for everyone to use.
Of course constructive critics are alwasy accepted
http://www.binpress.com/browse/c
#4
Posted 05 January 2009 - 12:24 PM
You're bound to spend a lot of time adding features that eventually won't be used. This makes the code bigger and harder to maintain. It starts with small things so you see no reason for concern, but before you know it they add up to something ugly and smelly. Also, I think it's pointless to be looking for optimizations at this extremely early point in development. Another concern is that this probably won't be tested thoroughly till it's actually used. So months or even years later some of these functions might finally find a use, assuming it works as expected without giving it any further thought, and wasting another day of debugging. It might not be so dramatic for these particular functions, but it will be if someone continues using this approach.
Some function specific advise:
- NextPowerOfTwo: Why does it only go to 65536? If the input value is higher, 0 is returned, which I highly doubt is what one expects and is bound to lead to trouble!
- IsPowerOf2: Is 0 a power of 2? This function returns non-zero while the result should be false. Is -2 a power of 2? This function returns zero while the result should be true. In fact, it doesn't work for any negative numbers. So use an unsigned argument to clarify this or first take the absolute value. The issue with 0 can be solved by using "(x & -x) == x" instead.
- IsOdd/IsEven: Note that this only works for numbers in 2's complement representation. It's probably safe for game development, but I wouldn't want this code in say automotive software. The right way to do this is to use "x % 2 == 0" (for even numbers). It's the compiler's job to optimize this with an AND instruction, so it's not likely to lose any performance. It might even have a better approach (not likely this one but in many other occasions the compiler can optimize things best if you avoid bit tricks and such).
- CeilPow2: Isn't this supposed to be the same thing as NextPowerOfTwo? Quite confusing. Also, for an input of 0 it returns 2, while clearly 1 is the right answer.
- IsNaN: This function also returns true for 0 / 0, which is not a NaN but an indeterminate form. You probably want to catch those too but just for clarity I'd advise to rename the function to IsNaNorIndeterminate or something like that.
- IFloor: Beware that this function relies on the IEEE 754 representation of floats. Again, fine for games but don't recycle the code in any other project. You could use preprocessor directives that test for certain CPU's that are guaranteed to use IEEE 754 and fall back to floor() otherwise. In fact I would always use floor() unless the fully completed project has been profiled and I found floor() to be a significant hotspot. Also, the latest x86 processors even include single instruction floor operations that are faster than this bit manipulating trick. So you should probably leave it to the compiler to optimize things unless you know for a fact that you can do better and it's necessary.
- FloatToInt: __asm is compiler-specific, and it's only available in 32-bit mode. While this only means it would have to be reimplemented on other platforms, the use of the frndint instruction is a bigger concern. Its actual rounding operation depends on a CPU control word. So while at one point it might be doing a floor operation the next time it could be a ceil or round to nearest! For example the DirectX libraries are known to modify the rounding control.
- RoundFloatToInt/FloatToIntRet: Same remarks as FloatToInt. And having three variants of a function is definitely going to lead to confusion.
- FloatToByte: This trick also relies on IEEE 754. Furthermore, the return value for input out of range can be quite unexpected. So I would comment that thoroughly or just not use this function unless I absolutely have to at the very end of the project.
- log2: It's faster to multiply with the reciprocal of log(2).
- FastSin/FastCos/FastSinCos: Let the compiler handle these. In fact Visual C++ will call a function which is faster than the FPU assembly instruction on Pentium 4 and up.
- FastDotProduct: This was clearly written in the time of the original Pentium. Instruction latencies and scheduling rules are quite different now. So unless you're an assembly pro and you know exactly what it does, keep away from other people's assembly snippets. Simply writing "x*x+y*y+z*z" is very likely to be faster nowadays, and if dot products are really holding performance down you should look at SSE instead when you're done implementing all functionality.
My advice is to just throw ALL of it away. Seriously. Implement only what is needed and in the most straightforward way. Don't waste time trying to optimize anything before the fully functional code has been thoroughly profiled. One day of optimizing the actual hotspots is worth a whole month of needlessly optimizing what one might blindly assume needs optimizing (not counting the frustration caused by bloating the code and debugging malfunctions).
Instead, I would advise to concentrate on how to get things functional. Not just anything, only the things that are truely needed. Therefore, it is of primary importance to have very clear design goals and to not slip away from them. I would even present a time schedule and stick to it as close as possible. Else you might just spend months coding and not achieve much and eventually get demotivated. By sticking to a plan you'll be able to get amazing results in minimal time.
Good luck! :yes:
#5
Posted 05 January 2009 - 12:49 PM
#6
Posted 05 January 2009 - 01:15 PM
kusma said:
#7
Posted 05 January 2009 - 01:40 PM
#8
Posted 05 January 2009 - 02:41 PM
http://www.binpress.com/browse/c
#9
Posted 05 January 2009 - 04:52 PM
In other news; I'm a long time viewer, first time poster ;)
#10
Posted 05 January 2009 - 06:42 PM
http://www.binpress.com/browse/c
#11
Posted 05 January 2009 - 09:11 PM
Another thing, always write up UNIT TESTS, even if it is the smallest tiniest detail there is. Unit tests will help you, and they will provide you with a basis to know that things are still working over time, or they aren't working. It's easy to run through a load of unit tests then it is to write up a new test every single time and try to remember what you might have affected in your modifications.
And my final recommendations, WRITE GAMES with your engine. They will help you learn the engine better, what works and what doesn't, and they are another basis on top of the unit tests that you can use to see what has changed over time, and what needs to be fixed, etc.
Well, that's all I've got for now. I hope that helps, and overall just have fun! Which it already appears that you are. :D
#12
Posted 05 January 2009 - 09:47 PM
#13
Posted 05 January 2009 - 11:08 PM
"My advise is to just throw ALL of it away..."
Man,that made me laugh like 30 seconds straight...thanks ;-)
http://www.binpress.com/browse/c
#14
Posted 06 January 2009 - 02:02 AM
#15
Posted 06 January 2009 - 10:39 AM
TheNut said:
#16
Posted 06 January 2009 - 12:05 PM
v71 said:
JakkoL said:
This is why we have prototypes. If you have no idea how something performs, write a minimal implementation that will allow you to evaluate the algorithm. It doesn't have to be fine-tuned at all. If during profiling you discover that a floor() function takes half of the execution time, leave it. The important thing is the algorithmic complexity and to have an estimate of how it will perform in the final product. Of course the latter requires some experience and might need some additional experimenting on its own, but that still doesn't fall into the category of premature optimization. Prototypes should be thrown away; failure to do so commonly results in the lava flow anti-pattern.
TheNut said:
#17
Posted 06 January 2009 - 01:33 PM
Nick said:
Even though algorithmic complexity has its value, it's often overstated and preached by fresh university graduates. There can be dominating performance bottlenecks in code which has nothing to do with algorithmic complexity.
But in the end you have to know where to put your optimization efforts and how early in the project. I'm just saying that it's totally wrong ideology to delay all optimizations to the late stage of development: "Premature optimization is the root of all evil", but also "Belated pessimization is the leaf of no good". Unfortunately mr. Knuth's words have been taken out of the context and people never talk about the "We should forget about small efficiencies, say about 97% of the time" part, and he wasn't exactly working on games where you have to work with content people which twist these numbers a bit (:
#18
Posted 06 January 2009 - 04:30 PM
Nick said:
And for the smart-asses: no, 1 + pi∙(ln 2)-1∙i is not a natural number
Quote
-
Currently working on: the 3D engine for Tomb Raider.
#19
Posted 06 January 2009 - 04:48 PM
JarkkoL said:
Note that I'm not saying optimization should be deferred to the very last day of development. But it's just pointless and a waste of time when doing it blindly like in the blog. A third of those functions are just bloat that will never be used, another third is mathematically wrong and will lead to bugs, and the last third is slower than a straighforward or standard implementation. Sorry v71, nothing personal, but I would throw it all away till you have at least a functional module that is fully tested and profiled before you start with low-level optimizations.
Quote
#20
Posted 06 January 2009 - 06:04 PM
Nick said:
Nick said:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












