Josh Posted June 4, 2022 Share Posted June 4, 2022 Not tested much, just an experiment. Can be slightly faster (25%) than rand() or mt19937: float random(const float x, const float y) { const float m = sin(x * 12.9898f + y * 78.233f) * 43758.5453f; return m - floor(m); } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Genebris Posted June 4, 2022 Share Posted June 4, 2022 I don't get it, it returns the same value for the same input? Quote Link to comment Share on other sites More sharing options...
Josh Posted June 4, 2022 Author Share Posted June 4, 2022 Yeah, that's the seed. It's from GLSL, something I was just messing around with, and I wanted to save the code somewhere. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted June 4, 2022 Share Posted June 4, 2022 That's cool. It didn't like "float m" as a constant for some reason idk. Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 7, 2022 Share Posted June 7, 2022 Just a side node: On intel integrated gfx card this glsl code is producing horrible noise. But you can overcome this issue by significantly lowering the 43758.5453f On 6/4/2022 at 12:44 PM, havenphillip said: That's cool. It didn't like "float m" as a constant for some reason idk. I think Josh's code is a conversion to c++ code. Yours is correct for glsl. Edited: As a side node, this should always replaced with a noise texture lookup in glsl when possible. While it is faster in c++ than traditional random generators it will slow down glsl shaders when it is used to much. A simple texture lookup is much faster. (one way is to pregenerate a texture with this function and later use this texture to lookup the random number. 2 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.