Skip to content

Commit

Permalink
struct vert
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Apr 17, 2024
1 parent 6c3f4a4 commit 3d8a6b5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,13 @@ int upload(Scene scene, SceneTilePaint tile, int tileZ, int tileX, int tileY, Gp
final int lz3 = lz + Perspective.LOCAL_TILE_SIZE;
final int hsl3 = nwColor;

if (stream)
{
vertexBuffer.put((float) lx2, ly2, lz2, hsl2);
vertexBuffer.put((float) lx3, ly3, lz3, hsl3);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);

vertexBuffer.put((float) lx0, ly0, lz0, hsl0);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);
vertexBuffer.put((float) lx3, ly3, lz3, hsl3);
}
else
{
vertexBuffer.put(lx2, ly2, lz2, hsl2);
vertexBuffer.put(lx3, ly3, lz3, hsl3);
vertexBuffer.put(lx1, ly1, lz1, hsl1);
vertexBuffer.put((float) lx2, ly2, lz2, hsl2);
vertexBuffer.put((float) lx3, ly3, lz3, hsl3);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);

vertexBuffer.put(lx0, ly0, lz0, hsl0);
vertexBuffer.put(lx1, ly1, lz1, hsl1);
vertexBuffer.put(lx3, ly3, lz3, hsl3);
}
vertexBuffer.put((float) lx0, ly0, lz0, hsl0);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);
vertexBuffer.put((float) lx3, ly3, lz3, hsl3);

if (stream || tile.getTexture() != -1)
{
Expand Down Expand Up @@ -375,18 +362,9 @@ int upload(SceneTileModel sceneTileModel, int lx, int lz,
int ly2 = vertexY[vertex2];
int lz2 = vertexZ[vertex2] - lz;

if (stream)
{
vertexBuffer.put((float) lx0, ly0, lz0, hsl0);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);
vertexBuffer.put((float) lx2, ly2, lz2, hsl2);
}
else
{
vertexBuffer.put(lx0, ly0, lz0, hsl0);
vertexBuffer.put(lx1, ly1, lz1, hsl1);
vertexBuffer.put(lx2, ly2, lz2, hsl2);
}
vertexBuffer.put((float) lx0, ly0, lz0, hsl0);
vertexBuffer.put((float) lx1, ly1, lz1, hsl1);
vertexBuffer.put((float) lx2, ly2, lz2, hsl2);

if (stream || triangleTextures != null)
{
Expand Down Expand Up @@ -530,9 +508,9 @@ else if (color3 == -2)
int triangleB = indices2[face];
int triangleC = indices3[face];

vertexBuffer.put(vertexX[triangleA], vertexY[triangleA], vertexZ[triangleA], packAlphaPriority | color1);
vertexBuffer.put(vertexX[triangleB], vertexY[triangleB], vertexZ[triangleB], packAlphaPriority | color2);
vertexBuffer.put(vertexX[triangleC], vertexY[triangleC], vertexZ[triangleC], packAlphaPriority | color3);
vertexBuffer.put((float) vertexX[triangleA], vertexY[triangleA], vertexZ[triangleA], packAlphaPriority | color1);
vertexBuffer.put((float) vertexX[triangleB], vertexY[triangleB], vertexZ[triangleB], packAlphaPriority | color2);
vertexBuffer.put((float) vertexX[triangleC], vertexY[triangleC], vertexZ[triangleC], packAlphaPriority | color3);

if (faceTextures != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public int compile(Template template) throws ShaderException
{
String err = GL43C.glGetShaderInfoLog(shader);
GL43C.glDeleteShader(shader);
System.out.println(source);
throw new ShaderException(err);
}
GL43C.glAttachShader(program, shader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ shared int renderPris[THREAD_COUNT * FACES_PER_THREAD]; // priority for face dr

layout(local_size_x = THREAD_COUNT) in;

struct face
{
vec3 pos;
int ahsl;
};

#include "common.glsl"
#include "priority_render.glsl"

Expand All @@ -67,9 +61,9 @@ void main() {

int prio[FACES_PER_THREAD];
int dis[FACES_PER_THREAD];
face vA[FACES_PER_THREAD];
face vB[FACES_PER_THREAD];
face vC[FACES_PER_THREAD];
vert vA[FACES_PER_THREAD];
vert vB[FACES_PER_THREAD];
vert vC[FACES_PER_THREAD];

for (int i = 0; i < FACES_PER_THREAD; i++) {
get_face(localId + i, minfo, cameraYaw, cameraPitch, prio[i], dis[i], vA[i], vB[i], vC[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,26 @@ struct modelinfo {
int z; // scene position z
};

struct vert
{
vec3 pos;
int ahsl;
};

layout(std430, binding = 0) readonly buffer modelbuffer_in {
modelinfo ol[];
};

layout(std430, binding = 1) readonly buffer vertexbuffer_in {
ivec4 vb[];
vert vb[];
};

layout(std430, binding = 2) readonly buffer tempvertexbuffer_in {
ivec4 tempvb[];
vert tempvb[];
};

layout(std430, binding = 3) writeonly buffer vertex_out {
ivec4 vout[];
vert vout[];
};

layout(std430, binding = 4) writeonly buffer uv_out {
Expand All @@ -76,6 +82,6 @@ layout(std430, binding = 6) readonly buffer temptexturebuffer_in {
vec4 temptexb[];
};

ivec4 pack_vert(vec3 pos, int ahsl) {
return ivec4(floatBitsToInt(pos), ahsl);
vert pack_vert(vec3 pos, int ahsl) {
return vert(pos, ahsl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
}

uint ssboOffset = localId;
ivec4 thisA, thisB, thisC;
vert thisA, thisB, thisC;

// Grab triangle vertices from the correct buffer
if (flags < 0) {
Expand All @@ -62,14 +62,14 @@ void main() {
ivec3 pos = ivec3(minfo.x, minfo.y, minfo.z);
ivec4 texPos = ivec4(0, pos);

vec3 vertA = thisA.xyz + pos;
vec3 vertB = thisB.xyz + pos;
vec3 vertC = thisC.xyz + pos;
vec3 vertA = thisA.pos + pos;
vec3 vertB = thisB.pos + pos;
vec3 vertC = thisC.pos + pos;

// position vertices in scene and write to out buffer
vout[outOffset + myOffset * 3] = pack_vert(vertA, thisA.w);
vout[outOffset + myOffset * 3 + 1] = pack_vert(vertB, thisB.w);
vout[outOffset + myOffset * 3 + 2] = pack_vert(vertC, thisC.w);
vout[outOffset + myOffset * 3] = pack_vert(vertA, thisA.ahsl);
vout[outOffset + myOffset * 3 + 1] = pack_vert(vertB, thisB.ahsl);
vout[outOffset + myOffset * 3 + 2] = pack_vert(vertC, thisC.ahsl);

if (toffset < 0) {
uvout[outOffset + myOffset * 3] = vec4(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int count_prio_offset(int priority) {
return total;
}

void get_face(uint localId, modelinfo minfo, float cameraYaw, float cameraPitch, out int prio, out int dis, out face o1, out face o2, out face o3) {
void get_face(uint localId, modelinfo minfo, float cameraYaw, float cameraPitch, out int prio, out int dis, out vert o1, out vert o2, out vert o3) {
int size = minfo.size;
int offset = minfo.offset;
int flags = minfo.flags;
Expand All @@ -103,9 +103,9 @@ void get_face(uint localId, modelinfo minfo, float cameraYaw, float cameraPitch,
ssboOffset = 0;
}

ivec4 thisA;
ivec4 thisB;
ivec4 thisC;
vert thisA;
vert thisB;
vert thisC;

// Grab triangle vertices from the correct buffer
if (flags < 0) {
Expand All @@ -122,22 +122,22 @@ void get_face(uint localId, modelinfo minfo, float cameraYaw, float cameraPitch,
int orientation = flags & 0x7ff;

// rotate for model orientation
vec4 thisrvA = rotatef(thisA, orientation);
vec4 thisrvB = rotatef(thisB, orientation);
vec4 thisrvC = rotatef(thisC, orientation);
vec4 thisrvA = rotatef(vec4(thisA.pos, 0), orientation);
vec4 thisrvB = rotatef(vec4(thisB.pos, 0), orientation);
vec4 thisrvC = rotatef(vec4(thisC.pos, 0), orientation);

// calculate distance to face
int thisPriority = (thisA.w >> 16) & 0xff; // all vertices on the face have the same priority
int thisPriority = (thisA.ahsl >> 16) & 0xff; // all vertices on the face have the same priority
int thisDistance = face_distance(thisrvA, thisrvB, thisrvC, cameraYaw, cameraPitch);

o1.pos = thisrvA.xyz;
o1.ahsl = thisA.w;
o1.ahsl = thisA.ahsl;

o2.pos = thisrvB.xyz;
o2.ahsl = thisB.w;
o2.ahsl = thisB.ahsl;

o3.pos = thisrvC.xyz;
o3.ahsl = thisC.w;
o3.ahsl = thisC.ahsl;

prio = thisPriority;
dis = thisDistance;
Expand All @@ -156,7 +156,7 @@ void get_face(uint localId, modelinfo minfo, float cameraYaw, float cameraPitch,
}
}

void add_face_prio_distance(uint localId, modelinfo minfo, face thisrvA, face thisrvB, face thisrvC, int thisPriority, int thisDistance, ivec4 pos) {
void add_face_prio_distance(uint localId, modelinfo minfo, vert thisrvA, vert thisrvB, vert thisrvC, int thisPriority, int thisDistance, ivec4 pos) {
if (localId < minfo.size) {
// if the face is not culled, it is calculated into priority distance averages
if (face_visible(thisrvA.pos, thisrvB.pos, thisrvC.pos, pos)) {
Expand Down Expand Up @@ -237,7 +237,7 @@ vec4 hillskew_vertexf(vec4 v, int hillskew, int y, int plane) {
}
}

void sort_and_insert(uint localId, modelinfo minfo, int thisPriority, int thisDistance, face faceA, face faceB, face faceC) {
void sort_and_insert(uint localId, modelinfo minfo, int thisPriority, int thisDistance, vert faceA, vert faceB, vert faceC) {
int size = minfo.size;

if (localId < size) {
Expand Down

0 comments on commit 3d8a6b5

Please sign in to comment.