Skip to content

Instantly share code, notes, and snippets.

@groutoutlook
Created June 7, 2024 09:51
Show Gist options
  • Select an option

  • Save groutoutlook/e547448172373cd2bef01aee8445ee96 to your computer and use it in GitHub Desktop.

Select an option

Save groutoutlook/e547448172373cd2bef01aee8445ee96 to your computer and use it in GitHub Desktop.
#version 450
/* Copyright (c) 2019-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout(points) in;
layout(triangle_strip, max_vertices = 24) out;
layout (location = 0) in vec3 gColor;
layout (location = 1) in mat4 modelViewProjection;
layout (location = 0) out vec3 fColor;
float voxSize = 0.5;
void AddQuad(vec4 center, vec4 dy, vec4 dx) {
fColor = gColor;
gl_Position = center + (dx - dy);
EmitVertex();
fColor = gColor;
gl_Position = center + (-dx - dy);
EmitVertex();
fColor = gColor;
gl_Position = center + (dx + dy);
EmitVertex();
fColor = gColor;
gl_Position = center + (-dx + dy);
EmitVertex();
EndPrimitive();
}
/*
bool IsCulled(vec4 normal) {
return normal.z > 0;
}
*/
void main() {
vec4 center = gl_in[0].gl_Position;
vec4 dx = modelViewProjection[0] / 2.0f * voxSize;
vec4 dy = modelViewProjection[1] / 2.0f * voxSize;
vec4 dz = modelViewProjection[2] / 2.0f * voxSize;
AddQuad(center + dx, dy, dz);
AddQuad(center - dx, dz, dy);
AddQuad(center + dy, dz, dx);
AddQuad(center - dy, dx, dz);
AddQuad(center + dz, dx, dy);
AddQuad(center - dz, dy, dx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment