Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sending the vertices to gpu:
- val a = Vec3(1,0.5f,1)
- val b = Vec3(-1,1,-2)
- var normal = calcNorm(a,b, cam.pos)
- // in shader: (a_position, a_normal, a_color)
- vertices.queueVertex(a, -normal, Color.BLUE)
- vertices.queueVertex(a, normal, Color.BLUE)
- vertices.queueVertex(b, -normal, Color.YELLOW)
- vertices.queueVertex(b, normal, Color.YELLOW)
- ...
- // calcNorm function:
- fun calcNorm(a: Vec3, b: Vec3, camPos: Vec3): Vec3 {
- return glm.glm.cross((a-b), (camPos-a)).normalize()
- }
- ...
- // shader for drawing the line:
- attribute vec3 a_position;
- attribute vec3 a_normal;
- attribute vec3 a_color;
- uniform mat4 model;
- uniform mat4 proj;
- uniform mat4 ortho;
- uniform mat4 view;
- uniform vec3 campos;
- varying vec4 v_pos;
- varying vec3 v_color;
- float linewidth = 0.04;
- void main() {
- vec4 pos = view * model * vec4((a_position), 1.0);
- float dist = length(vec4(campos, 0.0) - (model * vec4((a_position), 0.0)));
- vec4 delta = vec4((a_normal * (linewidth*dist)), 0.0);
- gl_Position = proj * (pos + delta);
- v_color = a_color;
- v_pos = pos;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement