Skip to content

Instantly share code, notes, and snippets.

@valkum
Last active May 19, 2019 18:31
Show Gist options
  • Save valkum/846f2448046b52a6a1a1cf02aa10d1c2 to your computer and use it in GitHub Desktop.
Save valkum/846f2448046b52a6a1a1cf02aa10d1c2 to your computer and use it in GitHub Desktop.
Working version is using
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 7
; Bound: 197
; Schema: 0
OpCapability Shader
%2 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %gl_VertexIndex %vertex %color_a %color_b %position_a %position_b %__0
%1 = OpString "shaders/vertex/debug_lines.vert"
OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed entry-point main
#line 1
#version 450
layout(std140, set = 0, binding = 0) uniform ViewArgs {
uniform mat4 proj;
uniform mat4 view;
};
layout(std140, set = 1, binding = 0) uniform DebugLinesArgs {
uniform vec2 screen_space_thickness;
};
layout(location = 0) in vec3 position_a;
layout(location = 1) in vec4 color_a;
layout(location = 2) in vec3 position_b;
layout(location = 3) in vec4 color_b;
const mat2 dir_mats[2] = mat2[](
mat2(0.0, 1.0, -1.0, 0.0),
mat2(0.0, -1.0, 1.0, 0.0)
);
layout(location = 0) out VertexData {
vec4 color;
} vertex;
void main() {
float factor = float((gl_VertexIndex & 2) >> 1);
vertex.color = mix(color_a, color_b, factor);
mat4 proj_view = proj * view;
vec4 projected_a = proj_view * vec4(position_a, 1.0);
vec4 projected_b = proj_view * vec4(position_b, 1.0);
vec4 proj_current = mix(projected_a, projected_b, factor);
if (proj_current.w < 0) {
// vertex behind camera clip plane
vec4 proj_next = mix(projected_b, projected_a, factor);
vec3 clip_space_dir = normalize(proj_current.xyw - proj_next.xyw);
float coef = -proj_current.w / clip_space_dir.z;
vec3 intersect_pos = proj_current.xyw + (clip_space_dir * coef);
gl_Position = vec4(intersect_pos.x, intersect_pos.y, 0, intersect_pos.z);
} else {
vec2 screen_a = projected_a.xy / projected_a.w;
vec2 screen_b = projected_b.xy / projected_b.w;
vec2 dir = normalize(screen_b - screen_a);
vec2 normal;
if ((gl_VertexIndex & 1) == 0) {
normal = dir * dir_mats[1];
}else {
normal = dir * dir_mats[0];
}
// int index = int(gl_VertexIndex & 1);
// vec2 normal = dir * dir_mats[index];
// vec2 normal = vec2(1.0 ,0.0);
normal *= proj_current.w * screen_space_thickness;
gl_Position = proj_current + vec4(normal, 0.0, 0.0);
}
}
"
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %gl_VertexIndex "gl_VertexIndex"
OpName %VertexData "VertexData"
OpMemberName %VertexData 0 "color"
OpName %vertex "vertex"
OpName %color_a "color_a"
OpName %color_b "color_b"
OpName %ViewArgs "ViewArgs"
OpMemberName %ViewArgs 0 "proj"
OpMemberName %ViewArgs 1 "view"
OpName %_ ""
OpName %position_a "position_a"
OpName %position_b "position_b"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %__0 ""
OpName %DebugLinesArgs "DebugLinesArgs"
OpMemberName %DebugLinesArgs 0 "screen_space_thickness"
OpName %__1 ""
OpDecorate %gl_VertexIndex BuiltIn VertexIndex
OpDecorate %VertexData Block
OpDecorate %vertex Location 0
OpDecorate %color_a Location 1
OpDecorate %color_b Location 3
OpMemberDecorate %ViewArgs 0 ColMajor
OpMemberDecorate %ViewArgs 0 Offset 0
OpMemberDecorate %ViewArgs 0 MatrixStride 16
OpMemberDecorate %ViewArgs 1 ColMajor
OpMemberDecorate %ViewArgs 1 Offset 64
OpMemberDecorate %ViewArgs 1 MatrixStride 16
OpDecorate %ViewArgs Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
OpDecorate %position_a Location 0
OpDecorate %position_b Location 2
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpMemberDecorate %DebugLinesArgs 0 Offset 0
OpDecorate %DebugLinesArgs Block
OpDecorate %__1 DescriptorSet 1
OpDecorate %__1 Binding 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_VertexIndex = OpVariable %_ptr_Input_int Input
%int_2 = OpConstant %int 2
%int_1 = OpConstant %int 1
%v4float = OpTypeVector %float 4
%VertexData = OpTypeStruct %v4float
%_ptr_Output_VertexData = OpTypePointer Output %VertexData
%vertex = OpVariable %_ptr_Output_VertexData Output
%int_0 = OpConstant %int 0
%_ptr_Input_v4float = OpTypePointer Input %v4float
%color_a = OpVariable %_ptr_Input_v4float Input
%color_b = OpVariable %_ptr_Input_v4float Input
%_ptr_Output_v4float = OpTypePointer Output %v4float
%mat4v4float = OpTypeMatrix %v4float 4
%ViewArgs = OpTypeStruct %mat4v4float %mat4v4float
%_ptr_Uniform_ViewArgs = OpTypePointer Uniform %ViewArgs
%_ = OpVariable %_ptr_Uniform_ViewArgs Uniform
%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
%v3float = OpTypeVector %float 3
%_ptr_Input_v3float = OpTypePointer Input %v3float
%position_a = OpVariable %_ptr_Input_v3float Input
%float_1 = OpConstant %float 1
%position_b = OpVariable %_ptr_Input_v3float Input
%uint = OpTypeInt 32 0
%float_0 = OpConstant %float 0
%bool = OpTypeBool
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
%__0 = OpVariable %_ptr_Output_gl_PerVertex Output
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%float_n1 = OpConstant %float -1
%157 = OpConstantComposite %v2float %float_0 %float_n1
%158 = OpConstantComposite %v2float %float_1 %float_0
%159 = OpConstantComposite %mat2v2float %157 %158
%163 = OpConstantComposite %v2float %float_0 %float_1
%164 = OpConstantComposite %v2float %float_n1 %float_0
%165 = OpConstantComposite %mat2v2float %163 %164
%DebugLinesArgs = OpTypeStruct %v2float
%_ptr_Uniform_DebugLinesArgs = OpTypePointer Uniform %DebugLinesArgs
%__1 = OpVariable %_ptr_Uniform_DebugLinesArgs Uniform
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
%main = OpFunction %void None %4
%6 = OpLabel
OpLine %1 27 0
%13 = OpLoad %int %gl_VertexIndex
%15 = OpBitwiseAnd %int %13 %int_2
%17 = OpShiftRightArithmetic %int %15 %int_1
%18 = OpConvertSToF %float %17
OpLine %1 28 0
%26 = OpLoad %v4float %color_a
%28 = OpLoad %v4float %color_b
%30 = OpCompositeConstruct %v4float %18 %18 %18 %18
%31 = OpExtInst %v4float %2 FMix %26 %28 %30
%33 = OpAccessChain %_ptr_Output_v4float %vertex %int_0
OpStore %33 %31
OpLine %1 30 0
%41 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_0
%42 = OpLoad %mat4v4float %41
%43 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_1
%44 = OpLoad %mat4v4float %43
%45 = OpMatrixTimesMatrix %mat4v4float %42 %44
%52 = OpLoad %v3float %position_a
%54 = OpCompositeExtract %float %52 0
%55 = OpCompositeExtract %float %52 1
%56 = OpCompositeExtract %float %52 2
%57 = OpCompositeConstruct %v4float %54 %55 %56 %float_1
%58 = OpMatrixTimesVector %v4float %45 %57
%62 = OpLoad %v3float %position_b
%63 = OpCompositeExtract %float %62 0
%64 = OpCompositeExtract %float %62 1
%65 = OpCompositeExtract %float %62 2
%66 = OpCompositeConstruct %v4float %63 %64 %65 %float_1
%67 = OpMatrixTimesVector %v4float %45 %66
%73 = OpExtInst %v4float %2 FMix %58 %67 %30
%77 = OpCompositeExtract %float %73 3
%80 = OpFOrdLessThan %bool %77 %float_0
OpSelectionMerge %82 None
OpBranchConditional %80 %81 %126
%81 = OpLabel
%88 = OpExtInst %v4float %2 FMix %67 %58 %30
%92 = OpVectorShuffle %v3float %73 %73 0 1 3
%94 = OpVectorShuffle %v3float %88 %88 0 1 3
%95 = OpFSub %v3float %92 %94
%96 = OpExtInst %v3float %2 Normalize %95
%100 = OpFNegate %float %77
%103 = OpCompositeExtract %float %96 2
%104 = OpFDiv %float %100 %103
%110 = OpVectorTimesScalar %v3float %96 %104
%111 = OpFAdd %v3float %92 %110
%119 = OpCompositeExtract %float %111 0
%121 = OpCompositeExtract %float %111 1
%123 = OpCompositeExtract %float %111 2
%124 = OpCompositeConstruct %v4float %119 %121 %float_0 %123
%125 = OpAccessChain %_ptr_Output_v4float %__0 %int_0
OpStore %125 %124
OpBranch %82
%126 = OpLabel
%131 = OpVectorShuffle %v2float %58 %58 0 1
%133 = OpCompositeExtract %float %58 3
%134 = OpCompositeConstruct %v2float %133 %133
%135 = OpFDiv %v2float %131 %134
%138 = OpVectorShuffle %v2float %67 %67 0 1
%140 = OpCompositeExtract %float %67 3
%141 = OpCompositeConstruct %v2float %140 %140
%142 = OpFDiv %v2float %138 %141
%146 = OpFSub %v2float %142 %135
%147 = OpExtInst %v2float %2 Normalize %146
%149 = OpBitwiseAnd %int %13 %int_1
%150 = OpIEqual %bool %149 %int_0
OpSelectionMerge %152 None
OpBranchConditional %150 %151 %161
%151 = OpLabel
%160 = OpVectorTimesMatrix %v2float %147 %159
OpBranch %152
%161 = OpLabel
%166 = OpVectorTimesMatrix %v2float %147 %165
OpBranch %152
%152 = OpLabel
%196 = OpPhi %v2float %160 %151 %166 %161
%173 = OpAccessChain %_ptr_Uniform_v2float %__1 %int_0
%174 = OpLoad %v2float %173
%175 = OpVectorTimesScalar %v2float %174 %77
%177 = OpFMul %v2float %196 %175
%180 = OpCompositeExtract %float %177 0
%181 = OpCompositeExtract %float %177 1
%182 = OpCompositeConstruct %v4float %180 %181 %float_0 %float_0
%183 = OpFAdd %v4float %73 %182
%184 = OpAccessChain %_ptr_Output_v4float %__0 %int_0
OpStore %184 %183
OpBranch %82
%82 = OpLabel
OpReturn
OpFunctionEnd
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 7
; Bound: 186
; Schema: 0
OpCapability Shader
%2 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %gl_VertexIndex %vertex %color_a %color_b %position_a %position_b %__0
%1 = OpString "shaders/vertex/debug_lines.vert"
OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed entry-point main
#line 1
#version 450
layout(std140, set = 0, binding = 0) uniform ViewArgs {
uniform mat4 proj;
uniform mat4 view;
};
layout(std140, set = 1, binding = 0) uniform DebugLinesArgs {
uniform vec2 screen_space_thickness;
};
layout(location = 0) in vec3 position_a;
layout(location = 1) in vec4 color_a;
layout(location = 2) in vec3 position_b;
layout(location = 3) in vec4 color_b;
const mat2 dir_mats[2] = mat2[](
mat2(0.0, 1.0, -1.0, 0.0),
mat2(0.0, -1.0, 1.0, 0.0)
);
layout(location = 0) out VertexData {
vec4 color;
} vertex;
void main() {
float factor = float((gl_VertexIndex & 2) >> 1);
vertex.color = mix(color_a, color_b, factor);
mat4 proj_view = proj * view;
vec4 projected_a = proj_view * vec4(position_a, 1.0);
vec4 projected_b = proj_view * vec4(position_b, 1.0);
vec4 proj_current = mix(projected_a, projected_b, factor);
if (proj_current.w < 0) {
// vertex behind camera clip plane
vec4 proj_next = mix(projected_b, projected_a, factor);
vec3 clip_space_dir = normalize(proj_current.xyw - proj_next.xyw);
float coef = -proj_current.w / clip_space_dir.z;
vec3 intersect_pos = proj_current.xyw + (clip_space_dir * coef);
gl_Position = vec4(intersect_pos.x, intersect_pos.y, 0, intersect_pos.z);
} else {
vec2 screen_a = projected_a.xy / projected_a.w;
vec2 screen_b = projected_b.xy / projected_b.w;
vec2 dir = normalize(screen_b - screen_a);
vec2 normal = dir * dir_mats[gl_VertexIndex & 1];
// vec2 normal = vec2(1.0 ,0.0);
normal *= proj_current.w * screen_space_thickness;
gl_Position = proj_current + vec4(normal, 0.0, 0.0);
}
}
"
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %gl_VertexIndex "gl_VertexIndex"
OpName %VertexData "VertexData"
OpMemberName %VertexData 0 "color"
OpName %vertex "vertex"
OpName %color_a "color_a"
OpName %color_b "color_b"
OpName %ViewArgs "ViewArgs"
OpMemberName %ViewArgs 0 "proj"
OpMemberName %ViewArgs 1 "view"
OpName %_ ""
OpName %position_a "position_a"
OpName %position_b "position_b"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %__0 ""
OpName %indexable "indexable"
OpName %DebugLinesArgs "DebugLinesArgs"
OpMemberName %DebugLinesArgs 0 "screen_space_thickness"
OpName %__1 ""
OpDecorate %gl_VertexIndex BuiltIn VertexIndex
OpDecorate %VertexData Block
OpDecorate %vertex Location 0
OpDecorate %color_a Location 1
OpDecorate %color_b Location 3
OpMemberDecorate %ViewArgs 0 ColMajor
OpMemberDecorate %ViewArgs 0 Offset 0
OpMemberDecorate %ViewArgs 0 MatrixStride 16
OpMemberDecorate %ViewArgs 1 ColMajor
OpMemberDecorate %ViewArgs 1 Offset 64
OpMemberDecorate %ViewArgs 1 MatrixStride 16
OpDecorate %ViewArgs Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
OpDecorate %position_a Location 0
OpDecorate %position_b Location 2
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpMemberDecorate %DebugLinesArgs 0 Offset 0
OpDecorate %DebugLinesArgs Block
OpDecorate %__1 DescriptorSet 1
OpDecorate %__1 Binding 0
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_VertexIndex = OpVariable %_ptr_Input_int Input
%int_2 = OpConstant %int 2
%int_1 = OpConstant %int 1
%v4float = OpTypeVector %float 4
%VertexData = OpTypeStruct %v4float
%_ptr_Output_VertexData = OpTypePointer Output %VertexData
%vertex = OpVariable %_ptr_Output_VertexData Output
%int_0 = OpConstant %int 0
%_ptr_Input_v4float = OpTypePointer Input %v4float
%color_a = OpVariable %_ptr_Input_v4float Input
%color_b = OpVariable %_ptr_Input_v4float Input
%_ptr_Output_v4float = OpTypePointer Output %v4float
%mat4v4float = OpTypeMatrix %v4float 4
%ViewArgs = OpTypeStruct %mat4v4float %mat4v4float
%_ptr_Uniform_ViewArgs = OpTypePointer Uniform %ViewArgs
%_ = OpVariable %_ptr_Uniform_ViewArgs Uniform
%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
%v3float = OpTypeVector %float 3
%_ptr_Input_v3float = OpTypePointer Input %v3float
%position_a = OpVariable %_ptr_Input_v3float Input
%float_1 = OpConstant %float 1
%position_b = OpVariable %_ptr_Input_v3float Input
%uint = OpTypeInt 32 0
%float_0 = OpConstant %float 0
%bool = OpTypeBool
%uint_2 = OpConstant %uint 2
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
%__0 = OpVariable %_ptr_Output_gl_PerVertex Output
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_arr_mat2v2float_uint_2 = OpTypeArray %mat2v2float %uint_2
%152 = OpConstantComposite %v2float %float_0 %float_1
%float_n1 = OpConstant %float -1
%154 = OpConstantComposite %v2float %float_n1 %float_0
%155 = OpConstantComposite %mat2v2float %152 %154
%156 = OpConstantComposite %v2float %float_0 %float_n1
%157 = OpConstantComposite %v2float %float_1 %float_0
%158 = OpConstantComposite %mat2v2float %156 %157
%159 = OpConstantComposite %_arr_mat2v2float_uint_2 %155 %158
%_ptr_Function__arr_mat2v2float_uint_2 = OpTypePointer Function %_arr_mat2v2float_uint_2
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
%DebugLinesArgs = OpTypeStruct %v2float
%_ptr_Uniform_DebugLinesArgs = OpTypePointer Uniform %DebugLinesArgs
%__1 = OpVariable %_ptr_Uniform_DebugLinesArgs Uniform
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
%main = OpFunction %void None %4
%6 = OpLabel
%indexable = OpVariable %_ptr_Function__arr_mat2v2float_uint_2 Function
OpLine %1 27 0
%13 = OpLoad %int %gl_VertexIndex
%15 = OpBitwiseAnd %int %13 %int_2
%17 = OpShiftRightArithmetic %int %15 %int_1
%18 = OpConvertSToF %float %17
OpLine %1 28 0
%26 = OpLoad %v4float %color_a
%28 = OpLoad %v4float %color_b
%30 = OpCompositeConstruct %v4float %18 %18 %18 %18
%31 = OpExtInst %v4float %2 FMix %26 %28 %30
%33 = OpAccessChain %_ptr_Output_v4float %vertex %int_0
OpStore %33 %31
OpLine %1 30 0
%41 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_0
%42 = OpLoad %mat4v4float %41
%43 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_1
%44 = OpLoad %mat4v4float %43
%45 = OpMatrixTimesMatrix %mat4v4float %42 %44
%52 = OpLoad %v3float %position_a
%54 = OpCompositeExtract %float %52 0
%55 = OpCompositeExtract %float %52 1
%56 = OpCompositeExtract %float %52 2
%57 = OpCompositeConstruct %v4float %54 %55 %56 %float_1
%58 = OpMatrixTimesVector %v4float %45 %57
%62 = OpLoad %v3float %position_b
%63 = OpCompositeExtract %float %62 0
%64 = OpCompositeExtract %float %62 1
%65 = OpCompositeExtract %float %62 2
%66 = OpCompositeConstruct %v4float %63 %64 %65 %float_1
%67 = OpMatrixTimesVector %v4float %45 %66
%73 = OpExtInst %v4float %2 FMix %58 %67 %30
%77 = OpCompositeExtract %float %73 3
%80 = OpFOrdLessThan %bool %77 %float_0
OpSelectionMerge %82 None
OpBranchConditional %80 %81 %126
%81 = OpLabel
%88 = OpExtInst %v4float %2 FMix %67 %58 %30
%92 = OpVectorShuffle %v3float %73 %73 0 1 3
%94 = OpVectorShuffle %v3float %88 %88 0 1 3
%95 = OpFSub %v3float %92 %94
%96 = OpExtInst %v3float %2 Normalize %95
%100 = OpFNegate %float %77
%103 = OpCompositeExtract %float %96 2
%104 = OpFDiv %float %100 %103
%110 = OpVectorTimesScalar %v3float %96 %104
%111 = OpFAdd %v3float %92 %110
%119 = OpCompositeExtract %float %111 0
%121 = OpCompositeExtract %float %111 1
%123 = OpCompositeExtract %float %111 2
%124 = OpCompositeConstruct %v4float %119 %121 %float_0 %123
%125 = OpAccessChain %_ptr_Output_v4float %__0 %int_0
OpStore %125 %124
OpBranch %82
%126 = OpLabel
%131 = OpVectorShuffle %v2float %58 %58 0 1
%133 = OpCompositeExtract %float %58 3
%134 = OpCompositeConstruct %v2float %133 %133
%135 = OpFDiv %v2float %131 %134
%138 = OpVectorShuffle %v2float %67 %67 0 1
%140 = OpCompositeExtract %float %67 3
%141 = OpCompositeConstruct %v2float %140 %140
%142 = OpFDiv %v2float %138 %141
%146 = OpFSub %v2float %142 %135
%147 = OpExtInst %v2float %2 Normalize %146
%161 = OpBitwiseAnd %int %13 %int_1
OpStore %indexable %159
%165 = OpAccessChain %_ptr_Function_mat2v2float %indexable %161
%166 = OpLoad %mat2v2float %165
%167 = OpVectorTimesMatrix %v2float %147 %166
%174 = OpAccessChain %_ptr_Uniform_v2float %__1 %int_0
%175 = OpLoad %v2float %174
%176 = OpVectorTimesScalar %v2float %175 %77
%178 = OpFMul %v2float %167 %176
%181 = OpCompositeExtract %float %178 0
%182 = OpCompositeExtract %float %178 1
%183 = OpCompositeConstruct %v4float %181 %182 %float_0 %float_0
%184 = OpFAdd %v4float %73 %183
%185 = OpAccessChain %_ptr_Output_v4float %__0 %int_0
OpStore %185 %184
OpBranch %82
%82 = OpLabel
OpReturn
OpFunctionEnd

Working version is using

if ((gl_VertexIndex & 1) == 0) {
  normal = dir * dir_mats[1];
}else {
  normal = dir * dir_mats[0];
}

Crashing version is using

vec2 normal = dir * dir_mats[gl_VertexIndex & 1];

Original

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment