21 lines
884 B
Text
21 lines
884 B
Text
/*
|
|
contributors: Patricio Gonzalez Vivo
|
|
description: "Fix the aspect ratio of a space keeping things squared for you, \nin\
|
|
\ a similar way that aspect.msl does, but while scaling the \nspace to keep the\
|
|
\ entire 0.0,0.0 ~ 1.0,1.0 range visible\n"
|
|
use: <float2> ratio(<float2> st, <float2> st_size)
|
|
examples:
|
|
- https://raw.githubusercontent.com/patriciogonzalezvivo/lygia_examples/main/draw_shapes.frag
|
|
license:
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
|
|
*/
|
|
|
|
#ifndef FNC_RATIO
|
|
#define FNC_RATIO
|
|
float2 ratio(float2 v, float2 s) {
|
|
return mix( float2((v.x*s.x/s.y)-(s.x*.5-s.y*.5)/s.y,v.y),
|
|
float2(v.x,v.y*(s.y/s.x)-(s.y*.5-s.x*.5)/s.x),
|
|
step(s.x,s.y));
|
|
}
|
|
#endif
|