Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/cubyz/shaders/bloom/color_extractor_downsample.vert
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ layout(location = 0) uniform mat4 invViewMatrix;
layout(location = 1) uniform vec2 tanXY;

void main() {
vec2 position = inTexCoords*2 - vec2(1, 1);
vec2 position = inTexCoords*2+vec2(-1, -1);
direction = (invViewMatrix * vec4(position.x*tanXY.x, 1, position.y*tanXY.y, 0)).xyz;
normalizedTexCoords = inTexCoords;
texCoords = inTexCoords*textureSize(color, 0) - 0.25;
Expand Down
6 changes: 5 additions & 1 deletion assets/cubyz/shaders/bloom/first_pass.vert
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ layout(location = 0) in vec2 inTexCoords;
layout(location = 0) out vec2 texCoords;

void main() {
#ifdef OPEN_GL
texCoords = vec2(inTexCoords.x, 1 - inTexCoords.y);
#else
texCoords = inTexCoords;
gl_Position = vec4(inTexCoords*2 - vec2(1, 1), 0, 1);
#endif
gl_Position = vec4(inTexCoords*2 + vec2(-1, -1), 0, 1);
}
7 changes: 5 additions & 2 deletions assets/cubyz/shaders/deferred_render_pass.vert
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ void main() {
directions[1] = (invViewMatrix * vec4(1*tanXY.x, 1, -1*tanXY.y, 0)).xyz;
directions[2] = (invViewMatrix * vec4(-1*tanXY.x, 1, 1*tanXY.y, 0)).xyz;
directions[3] = (invViewMatrix * vec4(-1*tanXY.x, 1, -1*tanXY.y, 0)).xyz;
#ifdef OPEN_GL
texCoords = vec2(inTexCoords.x, 1 - inTexCoords.y);
#else
texCoords = inTexCoords;
vec2 position = inTexCoords*2 - vec2(1, 1);
gl_Position = vec4(position, 0, 1);
#endif
gl_Position = vec4(inTexCoords*2 + vec2(-1, -1), 0, 1);
}
9 changes: 7 additions & 2 deletions assets/cubyz/shaders/fake_reflection.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ layout(location = 0) out vec3 coords;
layout(location = 0) uniform float reflectionMapSize;

void main() {
coords = vec3((inTexCoords*2 - vec2(1, 1))*(reflectionMapSize + 1)/reflectionMapSize, 1);
gl_Position = vec4(inTexCoords*2 - vec2(1, 1), 0, 1);
#ifdef OPEN_GL
vec2 texCoords = vec2(inTexCoords.x, 1 - inTexCoords.y);
coords = vec3((texCoords*2 + vec2(-1, -1))*(reflectionMapSize + 1)/reflectionMapSize, 1);
#else
coords = vec3((inTexCoords*2 + vec2(-1, -1))*(reflectionMapSize + 1)/reflectionMapSize, 1);
#endif
gl_Position = vec4(inTexCoords*2 + vec2(-1, -1), 0, 1);
}
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/Image.vert
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vec2(vertex_pos.x*size.x, size.y - vertex_pos.y*size.y))/screen;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/Line.vert
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vertex_pos*direction)/screen;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/Rect.vert
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vertex_pos*size)/screen;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/RectBorder.vert
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vertex_pos.xy*size + vertex_pos.zw*lineWidth)/screen;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/Text.vert
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ void main() {
vertex_pos.x += vertex_pos.y/textureRect.z;
}

// convert glyph coords to opengl coords
vec4 rect = vec4(position_percentage, size_percentage);

vec2 position = vec2(rect.x+vertex_pos.x*rect.z, -rect.y+vertex_pos.y*rect.w)*2+vec2(-1, 1);
vec2 position = vec2(rect.x+vertex_pos.x*rect.z, rect.y-vertex_pos.y*rect.w)*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);
frag_face_pos = face_pos;
Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/graphics/graph.vert
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ layout(std430, binding = 5) buffer _data
void main() {
float x = gl_VertexIndex;
float y = -data[(gl_VertexIndex + offset)%points];
// Convert to opengl coordinates:
vec2 position_percentage = (start + dimension*vec2(x/points, y))/screen;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2 + vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);
}
8 changes: 7 additions & 1 deletion assets/cubyz/shaders/item_texture_post.vert
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ layout(location = 0) in vec2 inTexCoords;
layout(location = 0) out vec2 texCoords;

void main() {

#ifdef OPEN_GL
texCoords = vec2(inTexCoords.x, 1 - inTexCoords.y);
#else
texCoords = inTexCoords;
gl_Position = vec4(inTexCoords*2 - vec2(1, 1), 0, 1);
#endif

gl_Position = vec4(inTexCoords*2 + vec2(-1, -1), 0, 1);
}
7 changes: 6 additions & 1 deletion assets/cubyz/shaders/ui/button.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#version 460

#ifdef OPEN_GL
layout(origin_upper_left) in vec4 gl_FragCoord;
#endif

layout(location = 0) out vec4 frag_color;

layout(location = 0) in vec2 startCoord;
Expand All @@ -20,6 +24,7 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
frag_color = texture(image, (gl_FragCoord.xy - startCoord)/(2*scale)/textureSize(image, 0));
vec2 textureCoords = (gl_FragCoord.xy - startCoord)/(2*scale)/textureSize(image, 0);
frag_color = texture(image, vec2(textureCoords.x, -textureCoords.y));
frag_color *= fColor;
}
6 changes: 2 additions & 4 deletions assets/cubyz/shaders/ui/button.vert
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vertex_pos*size)/screen;
startCoord.x = start.x;
startCoord.y = screen.y - start.y;
startCoord = start;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
3 changes: 1 addition & 2 deletions assets/cubyz/shaders/ui/window_border.vert
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ layout(push_constant, std430) uniform _ {
#endif

void main() {
// Convert to opengl coordinates:
vec2 position_percentage = (start + vertex_pos*size)/screen;
startCoord.x = start.x;
startCoord.y = screen.y - start.y - size.y;
endCoord.x = start.x + size.x;
endCoord.y = screen.y - start.y;

vec2 position = vec2(position_percentage.x, -position_percentage.y)*2+vec2(-1, 1);
vec2 position = position_percentage*2+vec2(-1, -1);

gl_Position = vec4(position, 0, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub const draw = struct { // MARK: draw
c.glGetIntegerv(c.GL_VIEWPORT, &viewport);
var newClip = Vec4i{
std.math.lossyCast(i32, translation[0]),
viewport[3] - std.math.lossyCast(i32, translation[1] + clipRect[1]*scale),
std.math.lossyCast(i32, translation[1]),
std.math.lossyCast(i32, clipRect[0]*scale),
std.math.lossyCast(i32, clipRect[1]*scale),
};
Expand Down
1 change: 1 addition & 0 deletions src/graphics/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ pub fn init() void { // MARK: init()
if (c.gladLoadGL(c.glfwGetProcAddress) == 0) {
@panic("Failed to load OpenGL functions from GLAD");
}
c.glClipControl(c.GL_UPPER_LEFT, c.GL_NEGATIVE_ONE_TO_ONE);
reloadSettings();

c.glEnable(c.GL_DEBUG_OUTPUT);
Expand Down
10 changes: 7 additions & 3 deletions src/graphics/pipelines.zig
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,11 @@ pub const Pipeline = struct { // MARK: Pipeline
self.shader.bind();
if (scissor) |s| {
c.glEnable(c.GL_SCISSOR_TEST);
c.glScissor(s.offset.x, s.offset.y, @intCast(s.extent.width), @intCast(s.extent.height));
var viewport: [4]c_int = undefined;
c.glGetIntegerv(c.GL_VIEWPORT, &viewport);
const width: c_int = @intCast(s.extent.width);
const height: c_int = @intCast(s.extent.height);
c.glScissor(s.offset.x, viewport[1] + viewport[3] - (s.offset.y + height), width, height);
} else {
c.glDisable(c.GL_SCISSOR_TEST);
}
Expand All @@ -845,8 +849,8 @@ pub const Pipeline = struct { // MARK: Pipeline
c.glDisable(c.GL_CULL_FACE);
}
c.glFrontFace(switch (self.rasterState.frontFace) {
.counterClockwise => c.GL_CCW,
.clockwise => c.GL_CW,
.counterClockwise => c.GL_CW,
.clockwise => c.GL_CCW,
});
if (self.rasterState.depthBias) |depthBias| {
c.glEnable(c.GL_POLYGON_OFFSET_FILL);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, skyColor: Vec3f, playerPo
c.glUniformMatrix4fv(deferredUniforms.invViewMatrix, 1, c.GL_TRUE, @ptrCast(&game.camera.viewMatrix.transpose()));
c.glUniform1f(deferredUniforms.zNear, zNear);
c.glUniform1f(deferredUniforms.zFar, zFar);
c.glUniform2f(deferredUniforms.tanXY, 1.0/game.projectionMatrix.rows[0][0], 1.0/game.projectionMatrix.rows[1][2]);
c.glUniform2f(deferredUniforms.tanXY, 1.0/game.projectionMatrix.rows[0][0], -1.0/game.projectionMatrix.rows[1][2]);

c.glBindFramebuffer(c.GL_FRAMEBUFFER, activeFrameBuffer);

Expand Down
2 changes: 1 addition & 1 deletion src/systems/modelRenderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const client = struct { // MARK: client
const projectedPos = Mat4f.fromGl(main.graphics.frame_uniforms.frameData().projectionMatrix).mulVec(rotatedPos);
if (projectedPos[2] < 0) continue;
const xCenter = (1 + projectedPos[0]/projectedPos[3])*@as(f32, @floatFromInt(main.Window.width/2));
const yCenter = (1 - projectedPos[1]/projectedPos[3])*@as(f32, @floatFromInt(main.Window.height/2));
const yCenter = (1 + projectedPos[1]/projectedPos[3])*@as(f32, @floatFromInt(main.Window.height/2));

const transparency = 38.0*std.math.log10(vec.lengthSquare(pos3d) + 1) - 80.0;
const alpha: u32 = @trunc(std.math.clamp(0xff - transparency, 0, 0xff));
Expand Down
4 changes: 2 additions & 2 deletions src/vec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ pub const Mat4f = struct { // MARK: Mat4f
return Mat4f{
.rows = [4]Vec4f{
Vec4f{1/tanX, 0, 0, 0},
Vec4f{0, 0, 1/tanY, 0},
Vec4f{0, -(far + near)/(near - far), 0, 2*near*far/(near - far)},
Vec4f{0, 0, -1/tanY, 0},
Vec4f{0, (far + near)/(far - near), 0, 2*near*far/(near - far)},
Vec4f{0, 1, 0, 0},
},
};
Expand Down
Loading