Skip to main content
GameDev.net gamedev.net
🔒 Locked

with converting float to uint.

Started by iuryboy2 Sep 25, 2020 at 9:39 PM 3 replies 5.5k views
Original Post
iuryboy2
iuryboy2

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

taby
taby

Where in the shader does this conversion occur?

fleabay
fleabay

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

Test

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

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.