Created
March 4, 2024 07:25
-
-
Save manthrax/df155eb9a63c84413f165582cc80bddf to your computer and use it in GitHub Desktop.
Warp 3d plane to 2d screen space GLSL:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniform sampler2D uTexture; | |
uniform float uAspect; //Aspect ratio of the screen | |
uniform float uProgress; | |
... | |
at the end of the vertex shader: | |
vec4 worldPosition = projectionMatrix * modelViewMatrix * vec4(pos, 1.); | |
vec4 screenPosition = vec4((uv-.5)*2.,0.,1.); | |
ivec2 texDim = textureSize(uTexture,0); | |
float imageAspect = float(texDim.x) / float(texDim.y); | |
if(imageAspect > uAspect) | |
screenPosition.y = screenPosition.y * uAspect / imageAspect; | |
else | |
screenPosition.x = screenPosition.x / uAspect * imageAspect; | |
gl_Position = mix(worldPosition,screenPosition, uProgress); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codesandbox.io/p/sandbox/shader-forked-xp469x