๐ŸŽ‰ Celebrating 25 Years of GameDev.net! ๐ŸŽ‰

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

with converting float to uint.

Started by
3 comments, last by fleabay 3ย years, 8ย months ago

there is an example in shadertoy where a float number representing vertices has been converted to uint.

example of the first 4 vertices:
float -> 1.220701, 1.541015, -0.435112, 1.115182
uint equivalent
uint -> 315732U, 759517524U, 732299537U, 759517524U

how do I do this conversion from float to uint?

link shadertoy -> https://www.shadertoy.com/view/tdsyR2

Advertisement

Where in the shader does this conversion occur?

At the bottom of the common tab there is this code.

vec3 getVertex( uint id )
{
	uint d = vertices[id];
	vec3 v = vec3(ivec3(d >> 20, d >> 10, d)&1023) / 1023.0;
	return v * vec3(0.337168395519, 0.915008187294, 1.95409280062) + vec3(0.0, -0.500852227211, -0.908407986164);
}

There is some bit shifting going on with each uint holding a vec3. To me, it looks like convoluted math after the shifting is done. I believe something simpler could be implemented with just division by a float.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

Test

<snip>

Sorry, I tried to hide this after test but the %$#@! forum wouldn't let me.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

This topic is closed to new replies.

Advertisement