Last active
April 2, 2022 00:27
-
-
Save slembcke/6684bb3bbc94f1d33fdb6e247dd00a9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Appologies for the messy code. | |
// It was run through SPIRV-Cross | |
// I cleaned it up and renamed the variables by hand. | |
#version 330 | |
layout(std140) uniform Locals | |
{ | |
mat2x4 LightMatrix; | |
float LightRadius; | |
} _68; | |
layout(std140) uniform DriftGlobals | |
{ | |
mat2x4 DRIFT_MATRIX_V; | |
mat2x4 DRIFT_MATRIX_P; | |
mat2x4 DRIFT_MATRIX_VP; | |
mat2x4 DRIFT_MATRIX_VP_INV; | |
mat2x4 DRIFT_MATRIX_REPROJ; | |
vec2 DRIFT_PIXEL_EXTENTS; | |
vec2 DRIFT_SCREEN_EXTENTS; | |
vec2 DRIFT_BUFFER_EXTENTS; | |
float DRIFT_ATLAS_SIZE; | |
} _155; | |
layout(location = 0) in vec2 IN_occluder_coord; | |
layout(location = 1) in vec4 IN_endpoints; | |
out float FRAG_opacity; | |
out vec4 FRAG_penumbras; | |
out vec3 FRAG_edges; | |
out vec4 FRAG_light_position; | |
out vec4 FRAG_endpoints; | |
vec3 _719; | |
void main() | |
{ | |
vec2 light_pos = vec3(0.0, 0.0, 1.0) * mat2x3(_68.LightMatrix[0].xyz, _68.LightMatrix[1].xyz); | |
vec2 occluder_coord_x = vec2(IN_occluder_coord.x); | |
vec2 endpoint = mix(IN_endpoints.zw, IN_endpoints.xy, occluder_coord_x); | |
vec2 delta_a = IN_endpoints.zw - light_pos; | |
vec2 delta_b = IN_endpoints.xy - light_pos; | |
vec2 delta = endpoint - light_pos; | |
float neg_LightRadius = -_68.LightRadius; | |
vec2 offset_a = (vec2(neg_LightRadius, _68.LightRadius) * 1.0) * normalize(delta_a).yx; | |
vec2 offset_b = (vec2(_68.LightRadius, neg_LightRadius) * 1.0) * normalize(delta_b).yx; | |
vec2 offset = mix(offset_a, offset_b, occluder_coord_x); | |
vec2 swept_edge = delta - offset; | |
vec2 w = vec2(IN_occluder_coord.y); | |
vec2 proj_pos_xy = mix(swept_edge, endpoint, w); | |
float proj_pos_x = proj_pos_xy.x; | |
vec2 neg_delta_a = -delta_a; | |
vec2 neg_offset_b = -offset_b; | |
vec2 seg_delta = IN_endpoints.xy - IN_endpoints.zw; | |
float one_minus_w = 1.0 - IN_occluder_coord.y; | |
vec2 delta_sum = delta_a + delta_b; | |
vec2 edges_xy = -((delta - (offset * one_minus_w)) * mat2(vec2(delta_sum.y, -delta_sum.x), vec2(-seg_delta.y, seg_delta.x))); | |
vec3 edges = vec3(edges_xy.x, 2*edges_xy.y, 0); | |
edges.z = dot(seg_delta.yx * vec2(-1.0, 1.0), swept_edge) * one_minus_w; | |
gl_Position = vec4(vec3(proj_pos_x, proj_pos_xy.y, IN_occluder_coord.y) * mat2x3(_155.DRIFT_MATRIX_VP[0].xyz, _155.DRIFT_MATRIX_VP[1].xyz), 0.0, IN_occluder_coord.y); | |
FRAG_opacity = 1.0; | |
FRAG_edges = edges; | |
FRAG_light_position = vec4(proj_pos_x, proj_pos_xy.y, 0.0, IN_occluder_coord.y * 16.0); | |
FRAG_endpoints = vec4(IN_endpoints.zwxy) * vec4(0.0625); | |
// If I write garbage to one of the components first, then I can succussfully write the other components. | |
// Neither the conditional nor garbage value written seems to matter as long as it's not optimized out. | |
// If I skip the conditional or overwrite it with a the real value, then I get garbage in the frag shader. | |
FRAG_penumbras.w = delta.x > delta.x ? 0 : 0; | |
FRAG_penumbras.x = dot(delta - mix(offset, delta_a, w), vec2(neg_delta_a.y, -neg_delta_a.x)); | |
FRAG_penumbras.y = dot(delta - mix(offset, delta_a, w), vec2(-offset_a.y, offset_a.x)); | |
FRAG_penumbras.z = dot(delta - mix(offset, delta_b, w), vec2(delta_b.y, -delta_b.x)); | |
// FRAG_penumbras.w = dot(delta - mix(offset, delta_b, w), vec2(-neg_offset_b.y, neg_offset_b.x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment