lainchan / λ

Sprite Distortion

Agent Jones · 2024-03-11 19:03
How can I achieve a similar effect with SDL or OpenGL? (It would be nice if I could do this only with SDL though) What's it even called? What are some resources for sprite distortion?
Koos van der Merwe · 2024-03-11 22:08
Mode 7 https://www.youtube.com/watch?v=3FVN_Ze7bzw https://www.youtube.com/watch?v=ybLZyY655iY https://www.youtube.com/watch?v=D0MPYZYe40E
McCarthy · 2024-03-12 05:28
>>38536 Dunno about SDL, but in OpenGL you can just treat the 2D textures as if they're located on a plane in 3D space and transform it to camera-space with an angled camera. If you want to keep it very simple and are willing to sacrifice some "3D" accuracy: just scale X coordinate up or down according to Y coordinate. Should work fine for small camera "angles"
Tyrell Wellick · 2024-03-12 14:47
distortion is just a projection function of f(x,y) -> x2,y2 from screenspace into texturespace Your goal is stretching x according to y as previous poster said. here's a quick example for doing it in opengl fragment shader, you can copypaste to shadertoy.com/new to see how it works: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 uv = fragCoord/iResolution.xy; //set screen coordinate space to -1,+1 on x,y axis uv=2.*uv-1.; //color output vec3 col = vec3(1.); //stretch function float stretchFactor=0.5; uv.x= uv.x+ stretchFactor*uv.x*sin(uv.y); //create black lines for visibility float x= mod(uv.x,0.05); if(x<0.025) col*=0.; // Output to screen fragColor = vec4(col,1.0); } This is dirty but also only 1 simple line to get the desired effect of your first image.(the stretch function line) 2nd image is you render a textured quad (2 triangles) and apply a transformation matrix that does rotation/scaling to it. Its about one page of code but nothing difficult, just a matter of initializing everything while the rendering itself is trivial again.