SRGB Error

Started by
2 comments, last by Jman2 4 years, 7 months ago

Hello,

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:
Output.jpg.35a4b0a9ebe04b02793eb6799b2aff29.jpg

Notice close to black values are innacurate.

if i use a standard reciprical approximation i get:

Output.jpg.ac34eebffd919aea25ddcec8ded0cfe9.jpg

 

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

Does anyone know what the issue might be?

Thanks.

Advertisement

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 ...

 

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.

This topic is closed to new replies.

Advertisement