Jump to content
  • Advertisement
Sign in to follow this  

SRGB Error

Recommended Posts


Decided to give Ray trace in a weekend a go, my Color class has a fast srgb method i picked up from nvidia.

inline float ToSrgbFast(float f)
	//Close Approximation to SRGB
	f = Mathf::Clamp01(f);
	float s1 = Mathf::Sqrt(f);
	float s2 = Mathf::Sqrt(s1);
	float s3 = Mathf::Sqrt(s2);
	return 0.662002687 * s1 + 0.684122060 * s2 - 0.323583601 * s3 - 0.0225411470 * f;

Problem is, it is innacurate for small values giving a result such as:

Notice close to black values are innacurate.

if i use a standard reciprical approximation i get:



Also here is an article about how the fast method was derived: Fast SRGB Approximation

Does anyone know what the issue might be?


Edited by Jman2

Share this post

Link to post
Share on other sites

I found that tutorial extremely thrilling and a lot of fun ! I couldn't get away from the PC until i had it running 🙂

But the conversion looks like a very slow thing to me. We're talking about the CPU here, but one day one might want to write the data to a framebuffer instead and then the srgb conversion (from linear to srgb color space) is an automagic thing, a glEnable(), a sampler switch or the respective equivalent in another api ...

Apart from that, the return values can become negative for small f's. Also, maybe check for implicit conversions ...


Edited by Green_Baron

Share this post

Link to post
Share on other sites

Alot of the issue was to do with an innacurate xorwow shift Peusdo random number generator, still get the odd red pixel but like you say the inevitable projection of a project like this is to get it running on GPU and display via a graphics API so its not a big issue.

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  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!