mrdoob / glsl-sandbox

Shader editor and gallery.
https://glslsandbox.com/
MIT License
1.55k stars 260 forks source link

Default template code has bad coordinate generation #16

Open WAHa06x36 opened 11 years ago

WAHa06x36 commented 11 years ago

The default code that gets loaded when a new effect is created has some pretty bad code for generating the coordinates. It generates coordinates in the range 0..1 on both axes, no matter the size of the window. This causes effects to be stretched in one direction or another under most circumstances.

As this is rarely if ever desired, it should be replaced with a better line, saving people the work of replacing it themselves when they notice their effects look wrong in another browser window.

I suggest the following:

vec2 position=(2.0 * gl_FragCoord.xy - resolution) / max(resolution.x,resolution.y);

This generates coordinates in the range -1..1 on the larger axis, and less on the other. If you want a 0..1 range on the larger axis, this should work, but this is less useful as it is hard to center anything:

vec2 position=gl_FragCoord.xy / max(resolution.x,resolution.y);