• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
polyfrag

GLSL double precision

7 posts in this topic

I want to simulate large scale areas, possibly more than 10x10 km and retain precision to within centimeters. How do I pass along doubles instead of floats to the shaders and specify vec3's/vec4's to be double-precision? Will this cause a significant slow-down?

0

Share this post


Link to post
Share on other sites

Just so you're not doing this for no reason: the 24 bits of precision in a standard float roughly corresponds to one centimeter at approximately 160 kilometers. If by "possibly" more than 10 kilometer you mean definitely less than 160 kilometers, then you already have enough precision in the standard float.

1

Share this post


Link to post
Share on other sites

To answer the second part of the question, it depends on the exact card. On many NVIDIA cards double precision will dramatically hurt performance. A lot of cards won't support it at all. Ideally you'll want to run a Quadro or FireGL GPU if you're doing doubles. It is not really a mass market possibility.

 

Will highp be 24-bit precision on all video cards?

highp is 32 bit precision on any hardware I've seen.

Edited by Promit
2

Share this post


Link to post
Share on other sites

If you want *double* precision, you have to use doubles inside GLSL, which is not available everywhere, and is far more slow than using single precision floats ... just to note, AMDs work also with doubles, but as NVidia, it will hurt performance. There are imho three main ways to get out of the "precision hell" with large scale worlds:

 

1.) Your world has to be divided in cells, you have each cell and items on it in relative coordinates to the cell (each cell originates at (0, 0, 0)). Your active cell (e.g. the one where camera is) is always at origin (0,0,0), once camera moves over the edge, you *move* all the cells and camera, so that new active cell is again at origin (0,0,0). This gives you good precision near camera (e.g. on current cell), and worse precision on very distant cells (which doesn't matter that much, as details should be lower there).

 

2.) Use higher precision. Okay but this isn't actually solution, it just moves your problem further. This one is in my opinion the worse way to walk.

 

3.) Use (i know you don't wanna hear it) fixed point numbers. But this shouldn't be used for graphics, as GPUs are faster for floating point computations. You should use fixed point for game logic and physics (if high precision or F.e. network communication is needed), but for graphics, I'd use solution 1 (which I'm using for large scale worlds right now).

1

Share this post


Link to post
Share on other sites

I thought float is 32 bit number with 32 bit precision, anyway the problem with floats is that if you have number 0.1456 (in double ) the float is 0.145612738912738914689461249641142e-40

 

anyway i think casting should do the trick



long double something;

float crap;

crap = (float)something;

Ah and if you manage to make "1" number as 1 meter you have 0.001 as one centimeter and 160000.0 as 160 km, not a big deal

 

since i have something like this in my code:

931322574615478515625.0f
0.000000000931322574615478515625f
const float imopi           = 0.017453292519943295769236907684886;
const float pi              = 3.1415926535897932384626433832795;
const float infinity		= 9999999999.90;
const float sinfinity		= 1000.0f; //1 kilometer (1000 meters)
const float pi2				= pi / 2.0f;
const float SQUARE_ROOT_2   = 1.4142135623730950488016887242097;

const float SPECIAL_FEAUTRE = 0.00000001;       //wtf ;u
const float epsilon			= 0.01;
const float epsilona		= 0.0001;    //movement epsilon close to zero when using rotations
const float EPSILON			= 0.000001;


etc....

Edited by ___
-3

Share this post


Link to post
Share on other sites

First, I have to pay tribute to Brother Bob, and to his endless patience in answering to some trivial questions. Although I'm also involved in teaching, I'm far less tolerant to something that have to be basic knowledge in computer science (like binary numbers representation - a secondary school knowledge). My respect!

Let's back to topic... The performance drop caused by double precision is overestimated in this thread. Generally speaking, it is always better to use SP instead of DP if it is possible, but the impact of DP calculation could be well masked by compiler's optimization. On the other hand, when we are talking about GPUs, we are talking about very massive parallelism using architecture with very deep pipeline. If there is no stalls, no dependencies and a compiler is perfectly done its job, the execution time is 1 clock for each instruction. Also, different GPUs have different architecture. For example, Fermi uses two SP units to perform DP operation, while Kepler has separate DP units (the number varies from series to series). So, it is very hard to predict performance.

The major problems with DP calculation are: they are not widely supported and transcendental functions are always calculated with SP. The second problem is very serious, since even on the mighty graphics cards GLSL cannot calculate trigonometry accurately. CUDA and OpenCL overcome the problem by software emulation and the price is longer execution time. HW implementation enables transcendental function execution in a single clock (but only in single precision).

It is worth to mention (since somebody asked if SP is guaranteed) that all new graphics cards should be fully IEEE754 complaint. I can firmly claim that for NV cards since G80 (which means in last 7 years). But older cards are not. So be careful if you have to deal with older cards.

SP is not adequate for many purposes (precision of just 6-7 decimal digits), but it is almost certainly enough for visualization. My recommendation is to perform all precision-critical calculation on CPU using DP, but downcast values to SP before sending to GPU. After tons of tricks and optimizations, I have succeeded to visualize Earth's surface with precision of 1e-6m with just SP calculation in GPU. It is a very precise scientific visualization using WGS84 ellipsoid. So, if it works for me for the terrain at least three orders of magnitude greater than yours, there is no doubt it can works for you too.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0