본문 바로가기
College Study/GLSL

[GLSL] Random

by 2den 2022. 1. 6.
728x90

 


Let's write the function 'random' that returns randomed-float data.
origin
 
pow2
root

 

float random(float st);
float random(vec2 st);
float random(vec3 st);
 
float random(float f){
    float y = fract(sin(f*100.)*100.);
    return y;
}

 

The function 'dot' downgrades vec2 data to float data.

float random(vec2 st){
    float c = fract(sin(dot(st*25., vec2(17.34,50.13)))*84242.235);
    return c;
}

 

#ifdef GL_ES
precision mediump float;
#endif

#define ROOT2 1.414

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

float random(float f);
float random(vec2 f);
float random(vec3 f);

void main(){
	vec2 coord = gl_FragCoord.xy/u_resolution;
    coord.x *= u_resolution.x/u_resolution.y;

	coord *= 10.;
    vec2 coint = floor(coord);
    
    vec3 col = vec3(random(coint));
    gl_FragColor = vec4(col, 1.);
}

float random(float f){
    float y = fract(sin(f*100.)*100.);
    return y;
}

float random(vec2 f){
    float c = fract(sin(dot(f*25., vec2(17.34,50.13)))*84242.235);
    return c;
}

728x90

'College Study > GLSL' 카테고리의 다른 글

[GLSL] Float-float Noise  (0) 2022.01.06
[GLSL] Maze and Glitch  (0) 2022.01.06
[GLSL] Patterns  (0) 2022.01.06
[GLSL] Rotate and Scale  (0) 2022.01.06
[GLSL] Translate  (0) 2022.01.06

댓글