Skip to content

Instantly share code, notes, and snippets.

@Samsy
Created February 7, 2019 13:59
Show Gist options
  • Save Samsy/89984a5f5e1a43c121b8ed20d1caa13a to your computer and use it in GitHub Desktop.
Save Samsy/89984a5f5e1a43c121b8ed20d1caa13a to your computer and use it in GitHub Desktop.
common.glsl
float when_fgt(float x, float y) {
return max(sign(x - y), 0.0);
}
vec2 correctRatio(vec2 inUv, float baseratio, float asp){
return mix(
vec2(
inUv.x,
inUv.y * baseratio / asp + .5 * ( 1. - baseratio / asp )
),
vec2(
inUv.x * asp / baseratio + .5 * ( 1. - asp / baseratio),
inUv.y
)
,when_fgt(baseratio, asp)
);
}
vec2 screenspacefrompos(vec4 sspPos){
vec4 tempssp = sspPos;
tempssp.xyz /= tempssp.w;
tempssp.xy = (0.5)+(tempssp.xy)*0.5;
return tempssp.xy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment