making directx using fdouble instead of float

Started by
4 comments, last by McEck 22 years, 1 month ago
i''m wondering if it is possible to force directx use double instead of float. or perhaps at least using double for vertex-transformations. anyone knows if it is possible/how? i would give it a try in the case anyone has an idea. why i want to use double? hm, i''m currently working on a game, playing in space. now i want to use a real bis universe but i don''t want to lose precision. let''s say i want a spaceship flying with 10 times lightspeed (for example) and you have to fly more than an hour to reach the "end" of space. but, i also want, that i can move (walk, fly, whatever) in verl small steps. so, i need very large values that may increase in very small steps. i''m not that familiar with floating-point data-types, but i don''t think float is capable of that. correct me if i''m wrong. but that''s why i''m wondering if directx/direct3d could use double instead of float. feel free to post what you''re thinking about this... greetz
Advertisement
This is a tricky one.


1. If you''re using doubles anywhere in your code, you should be setting the D3DCREATE_FPU_PRESERVE flag when you call CreateDevice(). This flag doesn''t tell D3D to use doubles - all it does is makes sure it doesn''t disable them in your code.

2. All consumer level 3D hardware that I know of is only capable of accepting 32bit single precision floats in vertices, matrices etc. Also structures such as D3DMATRIX only have forms which use single precision. So its bad news I''m afraid: you can''t use doubles to pass data to D3D.

3. Even if you could use doubles, you''d have to set your far Z clipping plane to a stupidly high value so you''d get massive Z buffering artifacts - not nice!.

4. The usual solution in this case is to partition your space into cubes of say 1000 metres each, then keep some sort of higher level record of which 1000 metre block the player and camera are inside. Each new cube of space you start the coordinates back at 0. So the coordinates you pass to D3D are say only ever in the range 0-1000 (or -500 to 500). If you need to draw the contents of two neighbouring cubes, you render twice, changing the projection/camera as you go.
In a way the work behind this is similar to what you''d have to do with a world partitioned with an Octree, except the coordinates of vertices covered by each node would have an origin in the centre of the node.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

If you are going to measures the distance of the earh to the moon, then you are not going to use centimeters!!!

If your ship moved at 10x lightspeed, then trhe maximum resolution you need is 3000000 KM, so instead of measuring it in KM, scale it and make everything measured in 1000 km or whatever
I had this problem with my world wich is big
only going to 100''000 cordinaate for example was sufficient
to make the world shaking a bit when using rotation matrix
(translation worked well)

I found a solution on the net: it was to keep the camera at 0,0,0
and moving the world around. after all, all the visible object aren''t usually far than 6''000 to 10''000 (far plane)

As read on internet "it isn''t so terrible as it seem"
and I implemented this in two day transforming my project
(18''000 line width for now)

I kept only a double coordinate and a float for each object that move in the world. Usually as the camera move (camera have also a double "virtual" pos in world) When the object come in view (fast test on double first to sea if near camera) I start each frame to convert from world coordinate in camera coordinate and all work Ok now.

All effect (explosion particle etc etc) doesn''t need double coordinate while they always appear near the camera

but it''s really "not as terrible as it seem" and the only simple solution I found. just a litle math as the object come close
otherwise an object pos from camera can be found
by object''s double - camera''s double

Hope it''s clear my english is bad. if interested I can post some code.

Dan
Combat Sail Simulator
Css''s forum, Screenshot

You really shouldn''t mix and match doubles and floats. The FPU takes a little time to switch states between double and single presicion, which begins to add up over a few hundred or thousand calls a frame...

Steve
I wonder if we can do something that isn''t bad for game programming.
"not less than nn poly per call,not too much,no vertex buffer and texture switching, no texture... it''s bad, not this , not that " and now no double.

We will finaly end with a flat cube turning on screen but then the player will start to rant.

I think there is a limit to optimisation. if it work ? do it.

For me it work and the FPS is good even on a ati rage pro p400
(the last commercial game I bought don''t even run on this config)
I didn''t saw any performance hit since I implemented this (appart that now it don''t shake anymore)and there is a a whole world displayed with model.

Dan

This topic is closed to new replies.

Advertisement