def geom_shader(view: View, gl_in: Sequence[GlGsIn], vs_out: Sequence[VsOut]) -> Iterator[GsOut]: triangle = Array3[vec2] triangle[0] = viewport_to_screen_space(view.fb_size, gl_in[0].gl_position) triangle[1] = viewport_to_screen_space(view.fb_size, gl_in[1].gl_position) triangle[2] = viewport_to_screen_space(view.fb_size, gl_in[2].gl_position) altitudes = vec3(triangle_2d_altitudes(triangle)) yield GsOut(gl_position=gl_in[0].gl_position, altitudes=vec3(altitudes[0], 0, 0), normal=vs_out[0].normal, color=vs_out[0].color) yield GsOut(gl_position=gl_in[1].gl_position, altitudes=vec3(0, altitudes[1], 0), normal=vs_out[1].normal, color=vs_out[1].color) yield GsOut(gl_position=gl_in[2].gl_position, altitudes=vec3(0, 0, altitudes[2]), normal=vs_out[2].normal, color=vs_out[2].color) end_primitive()
def geom_shader(view: View, gl_in: Sequence[GlGsIn], vs_out: Sequence[VsOut]) -> Iterator[GsOut]: triangle = Array3[vec2] triangle[0] = viewport_to_screen_space(view.fb_size, gl_in[0].gl_position) triangle[1] = viewport_to_screen_space(view.fb_size, gl_in[1].gl_position) triangle[2] = viewport_to_screen_space(view.fb_size, gl_in[2].gl_position) altitudes = vec3(triangle_2d_altitudes(triangle)) yield GsOut(gl_position=gl_in[0].gl_position, altitudes=vec3(altitudes[0], 0, 0), normal=vs_out[0].normal, color=vs_out[0].color) yield GsOut(gl_position=gl_in[1].gl_position, altitudes=vec3(0, altitudes[1], 0), normal=vs_out[1].normal, color=vs_out[1].color) yield GsOut(gl_position=gl_in[2].gl_position, altitudes=vec3(0, 0, altitudes[2]), normal=vs_out[2].normal, color=vs_out[2].color) end_primitive()
def triangle_2d_altitudes(triangle: Array3[vec2]) -> vec3: ed0 = vec2(triangle[2] - triangle[1]) ed1 = vec2(triangle[2] - triangle[0]) ed2 = vec2(triangle[1] - triangle[0]) area = float(abs((ed1.x * ed2.y) - (ed1.y * ed2.x))) return vec3(area / length(ed0), area / length(ed1), area / length(ed2))
def triangle_2d_altitudes(triangle: Array3[vec2]) -> vec3: ed0 = vec2(triangle[2] - triangle[1]) ed1 = vec2(triangle[2] - triangle[0]) ed2 = vec2(triangle[1] - triangle[0]) area = float(abs((ed1.x * ed2.y) - (ed1.y * ed2.x))) return vec3(area / length(ed0), area / length(ed1), area / length(ed2))
class GsOut(ShaderInterface): gl_position = vec4() altitudes = vec3(noperspective) normal = vec3() color = vec4()
class VsOut(ShaderInterface): gl_position = vec4() normal = vec3() color = vec4()
class VertAttrs(AttributeBlock): vert_loc = vec3() vert_nor = vec3() vert_col = vec4()