Advertisement

with converting float to uint.

Started by September 25, 2020 09:39 PM
3 comments, last by fleabay 4Β years, 2Β 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

Where in the shader does this conversion occur?

Advertisement

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