Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Shader to render floors/ceilings.
- //Currently always uses the same texture, will allow lookups in version 2
- varying vec2 v_vTexcoord;
- varying vec4 v_vColour;
- uniform float u_floorProps[6*512]; //Big ole array
- uniform float u_height;
- uniform float u_width;
- uniform float u_playerX;
- uniform float u_playerY;
- uniform float u_distPlayer;
- uniform sampler2D s_floorTex;
- void main()
- {
- //Okay, so we currently have two texture coords that are between 0 and 1.
- //from that we need to know what the screen coords were, so we can look shit up
- float X = floor(v_vTexcoord.x * u_width);
- float Y = floor(v_vTexcoord.y * u_height);
- int arrayStart = int(X * 6.0);
- float floorScreenY = u_floorProps[arrayStart];
- float distWall = u_floorProps[arrayStart + 3];
- float floorXWall = u_floorProps[arrayStart + 1];
- float floorYWall = u_floorProps[arrayStart + 2];
- //Set alpha to 0 if this pixel is out of range, otherwise set to 1
- if (Y < floorScreenY)
- {
- discard;
- }
- //Determine the texture co-ords for this fragment
- float currentDist = u_height / (2.0 * floorScreenY - u_height); //you could make a small lookup table for this instead
- float weight = (currentDist - u_distPlayer) / (distWall - u_distPlayer);
- float currentFloorX = weight * floorXWall + (1.0 - weight) * u_playerX;
- float currentFloorY = weight * floorYWall + (1.0 - weight) * u_playerY;
- float floorTexWidth = u_floorProps[arrayStart + 4];
- float floorTexHeight = u_floorProps[arrayStart + 5];
- //okay, this bit is different since we just want UVs, not the exact texture coords
- //that looks dumb as shit, but I think it's correct
- float floorTexX = mod(floor(currentFloorX * floorTexWidth),floorTexWidth);
- float floorTexY = mod(floor(currentFloorY * floorTexHeight),floorTexHeight);
- vec2 floorUV = vec2(floorTexX,floorTexY);
- gl_FragColor = v_vColour * texture2D( s_floorTex, floorUV);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement