Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float w = width / 2.f;
- float h = height / 2.f;
- // Right vertices with outwards normals
- X Y NorX NorY
- vertices.emplace_back(w, -h, 1.f, 0.f);
- vertices.emplace_back(w, h, 1.f, 0.f);
- // Bottom vertices with outwards normals
- vertices.emplace_back( w, h, 0.f, 1.f);
- vertices.emplace_back(-w, h, 0.f, 1.f);
- // Left vertices with outwards normals
- vertices.emplace_back(-w, h, -1.f, 0.f);
- vertices.emplace_back(-w, -h, -1.f, 0.f);
- // Top vertices with outwards normals
- vertices.emplace_back(-w, -h, 0.f, -1.f);
- vertices.emplace_back( w, -h, 0.f, -1.f);
- // Right vertices with inwards normals
- vertices.emplace_back(w, -h, -1.f, 0.f);
- vertices.emplace_back(w, h, -1.f, 0.f);
- // ** SNIP **
- // Here's the rest of "inverted normal" vertices
- // ** SNIP
- // Indices that make the triangles
- // Right
- indices.emplace_back(0);
- indices.emplace_back(1);
- indices.emplace_back(8);
- indices.emplace_back(8);
- indices.emplace_back(1);
- indices.emplace_back(9);
- // Down
- indices.emplace_back(2);
- indices.emplace_back(3);
- indices.emplace_back(10);
- indices.emplace_back(10);
- indices.emplace_back(3);
- indices.emplace_back(11);
- // ** SNIP ** And here's the rest of the indices ** SNIP **
- // Vertex attributes
- layout(location = 0) in vec3 in_position;
- layout(location = 3) in vec3 in_normal; // Y is always 0
- // Uniforms
- uniform mat4 u_world;
- uniform mat4 u_view;
- uniform mat4 u_projection;
- uniform vec2 u_lightPosition;
- void main() {
- // Get the world position of the vertex
- vec4 vPos = u_world * vec4(in_position, 1.0);
- // Flatten to XZ-plane
- vec2 xzPos = vec2(vPos.x, vPos.z);
- // Get the direction from the vertex to the light
- vec2 dir = normalize(xzPos - u_lightPosition);
- // If the normals point outwards, extrude them
- if(dot(dir, vec2(in_nor.x, in_nor.z)) < 0) {
- vPos.x += dir.x * 10000;
- vPos.z += dir.y * 10000;
- }
- // Apply the position
- gl_Position = u_projection * u_view * vPos;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement