working heightmap shader?
This commit is contained in:
parent
43e1fda736
commit
fe15d3e8ca
15 changed files with 331 additions and 76 deletions
83
MeshShaderHeightmapRGBA.glsl
Normal file
83
MeshShaderHeightmapRGBA.glsl
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#version 450
|
||||
#extension GL_EXT_mesh_shader : require
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 modelProjectionView;
|
||||
uint sizeX;
|
||||
uint sizeZ;
|
||||
float spacing;
|
||||
uint padding[13];
|
||||
} ubo;
|
||||
|
||||
struct VertexType
|
||||
{
|
||||
float height;
|
||||
float padding[3];
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
layout (binding = 1) buffer VERTEX
|
||||
{
|
||||
VertexType pos[];
|
||||
} vertex;
|
||||
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
layout(triangles, max_vertices = 256, max_primitives = 128) out;
|
||||
|
||||
layout (location = 0) out PerVertexData
|
||||
{
|
||||
vec4 color;
|
||||
} outVert[];
|
||||
|
||||
void main()
|
||||
{
|
||||
SetMeshOutputsEXT(256, 128);
|
||||
|
||||
uint linearID = gl_LocalInvocationID.x;
|
||||
uint quadX = linearID % ubo.sizeX;
|
||||
uint quadZ = linearID / ubo.sizeX;
|
||||
|
||||
VertexType vertex1 = vertex.pos[quadZ * ubo.sizeX + quadX];
|
||||
VertexType vertex2 = vertex.pos[quadZ * ubo.sizeX + quadX + 1];
|
||||
VertexType vertex3 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX];
|
||||
VertexType vertex4 = vertex.pos[(quadZ+1) * ubo.sizeX + quadX + 1];
|
||||
|
||||
uint vertexID = gl_LocalInvocationID.x*4;
|
||||
|
||||
gl_MeshVerticesEXT[vertexID].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX, 0, ubo.spacing*quadZ, 1); // Top-left
|
||||
gl_MeshVerticesEXT[vertexID + 1].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX+ubo.spacing, 0, ubo.spacing*quadZ, 1); // Top-right
|
||||
gl_MeshVerticesEXT[vertexID + 2].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX, 0, ubo.spacing*quadZ+ubo.spacing, 1); // Bottom-left
|
||||
gl_MeshVerticesEXT[vertexID + 3].gl_Position = ubo.modelProjectionView * vec4(ubo.spacing*quadX+ubo.spacing, 0, ubo.spacing*quadZ+ubo.spacing, 1); // Bottom-right
|
||||
|
||||
outVert[vertexID].color = vertex1.color;
|
||||
outVert[vertexID + 1].color = vertex2.color;
|
||||
outVert[vertexID+ 2].color = vertex3.color;
|
||||
outVert[vertexID + 3].color = vertex4.color;
|
||||
|
||||
uint triangleID = gl_LocalInvocationID.x*2;
|
||||
|
||||
gl_PrimitiveTriangleIndicesEXT[triangleID] = uvec3(vertexID, vertexID+1, vertexID+2);
|
||||
gl_PrimitiveTriangleIndicesEXT[triangleID + 1] = uvec3(vertexID+2, vertexID+1, vertexID+3);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue