diff --git a/assets/cubyz/shaders/background/fragment.fs b/assets/cubyz/shaders/background/fragment.fs index 7db92396..12923805 100644 --- a/assets/cubyz/shaders/background/fragment.fs +++ b/assets/cubyz/shaders/background/fragment.fs @@ -4,7 +4,7 @@ layout(location = 0) out vec4 fragColor; layout(location = 0) in vec2 outTexCoords; -uniform sampler2D image; +layout(binding = 0) uniform sampler2D image; void main() { fragColor = texture(image, outTexCoords); diff --git a/assets/cubyz/shaders/bloom/color_extractor_downsample.fs b/assets/cubyz/shaders/bloom/color_extractor_downsample.fs index 938a9f62..01f11b6e 100644 --- a/assets/cubyz/shaders/bloom/color_extractor_downsample.fs +++ b/assets/cubyz/shaders/bloom/color_extractor_downsample.fs @@ -7,8 +7,8 @@ layout(location = 1) in vec2 normalizedTexCoords; layout(location = 2) in vec3 direction; layout(binding = 3) uniform sampler2D color; +layout(binding = 4) uniform sampler2D depthTexture; -uniform sampler2D depthTexture; uniform float zNear; uniform float zFar; uniform vec2 tanXY; diff --git a/assets/cubyz/shaders/chunks/chunk_fragment.fs b/assets/cubyz/shaders/chunks/chunk_fragment.fs index e1139cea..7d3eaa0f 100644 --- a/assets/cubyz/shaders/chunks/chunk_fragment.fs +++ b/assets/cubyz/shaders/chunks/chunk_fragment.fs @@ -11,10 +11,11 @@ layout(location = 7) flat in int ditherSeed; layout(location = 8) flat in float distanceForLodCheck; layout(location = 9) flat in int opaqueInLod; -uniform sampler2DArray texture_sampler; -uniform sampler2DArray emissionSampler; -uniform sampler2DArray reflectivityAndAbsorptionSampler; -uniform samplerCube reflectionMap; +layout(binding = 0) uniform sampler2DArray textureSampler; +layout(binding = 1) uniform sampler2DArray emissionSampler; +layout(binding = 2) uniform sampler2DArray reflectivityAndAbsorptionSampler; +layout(binding = 4) uniform samplerCube reflectionMap; + uniform float reflectionMapSize; uniform float contrast; uniform float lodDistance; @@ -79,7 +80,7 @@ void main() { reflectivity = reflectivity*(1 - fresnelReflection) + fresnelReflection; vec3 pixelLight = max(light*normalVariation, texture(emissionSampler, textureCoords).r*4); - fragColor = texture(texture_sampler, textureCoords)*vec4(pixelLight, 1); + fragColor = texture(textureSampler, textureCoords)*vec4(pixelLight, 1); fragColor.rgb += reflectivity*pixelLight; if(!passDitherTest(fragColor.a)) discard; diff --git a/assets/cubyz/shaders/chunks/transparent_fragment.fs b/assets/cubyz/shaders/chunks/transparent_fragment.fs index b36438ff..54203e42 100644 --- a/assets/cubyz/shaders/chunks/transparent_fragment.fs +++ b/assets/cubyz/shaders/chunks/transparent_fragment.fs @@ -11,17 +11,18 @@ layout(location = 7) flat in int ditherSeed; layout(location = 8) flat in float distanceForLodCheck; layout(location = 9) flat in int opaqueInLod; -uniform sampler2DArray texture_sampler; -uniform sampler2DArray emissionSampler; -uniform sampler2DArray reflectivityAndAbsorptionSampler; -uniform samplerCube reflectionMap; +layout(binding = 0) uniform sampler2DArray textureSampler; +layout(binding = 1) uniform sampler2DArray emissionSampler; +layout(binding = 2) uniform sampler2DArray reflectivityAndAbsorptionSampler; +layout(binding = 4) uniform samplerCube reflectionMap; +layout(binding = 5) uniform sampler2D depthTexture; + uniform float reflectionMapSize; uniform float contrast; uniform ivec3 playerPositionInteger; uniform vec3 playerPositionFraction; -layout(binding = 5) uniform sampler2D depthTexture; layout(location = 0, index = 0) out vec4 fragColor; layout(location = 0, index = 1) out vec4 blendColor; @@ -141,7 +142,7 @@ void main() { float airFogDistance = calculateFogDistance(dist, densityAdjustment, playerPositionFraction.z, normalize(direction).z, fog.density, fog.fogLower - playerPositionInteger.z, fog.fogHigher - playerPositionInteger.z); vec3 fogColor = unpackColor(fogData[int(animatedTextureIndex)].fogColor); vec3 pixelLight = max(light*normalVariation, texture(emissionSampler, textureCoords).r*4); - vec4 textureColor = texture(texture_sampler, textureCoords)*vec4(pixelLight, 1); + vec4 textureColor = texture(textureSampler, textureCoords)*vec4(pixelLight, 1); float reflectivity = texture(reflectivityAndAbsorptionSampler, textureCoords).a; float fresnelReflection = (1 + dot(normalize(direction), normal)); diff --git a/assets/cubyz/shaders/deferred_render_pass.fs b/assets/cubyz/shaders/deferred_render_pass.fs index 01bd9766..91606887 100644 --- a/assets/cubyz/shaders/deferred_render_pass.fs +++ b/assets/cubyz/shaders/deferred_render_pass.fs @@ -5,9 +5,9 @@ layout(location = 0) out vec4 fragColor; layout(location = 0) in vec2 texCoords; layout(location = 1) flat in vec3[4] directions; -uniform sampler2D color; +layout(binding = 3) uniform sampler2D color; -uniform sampler2D depthTexture; +layout(binding = 4) uniform sampler2D depthTexture; uniform float zNear; uniform float zFar; uniform vec2 tanXY; diff --git a/assets/cubyz/shaders/entity_fragment.fs b/assets/cubyz/shaders/entity_fragment.fs index a1afc5b2..33766103 100644 --- a/assets/cubyz/shaders/entity_fragment.fs +++ b/assets/cubyz/shaders/entity_fragment.fs @@ -5,9 +5,10 @@ layout(location = 1) in vec3 mvVertexPos; layout(location = 2) in vec3 outLight; layout(location = 3) flat in vec3 normal; -out vec4 fragColor; +layout(location = 0) out vec4 fragColor; + +layout(binding = 0) uniform sampler2D textureSampler; -uniform sampler2D texture_sampler; uniform float contrast; float lightVariation(vec3 normal) { @@ -37,7 +38,7 @@ bool passDitherTest(float alpha) { } void main() { - fragColor = texture(texture_sampler, outTexCoord)*vec4(outLight*lightVariation(normal), 1); + fragColor = texture(textureSampler, outTexCoord)*vec4(outLight*lightVariation(normal), 1); if(!passDitherTest(fragColor.a)) discard; fragColor.a = 1; } diff --git a/assets/cubyz/shaders/graphics/Image.fs b/assets/cubyz/shaders/graphics/Image.fs index 0046913e..5936d3ce 100644 --- a/assets/cubyz/shaders/graphics/Image.fs +++ b/assets/cubyz/shaders/graphics/Image.fs @@ -1,7 +1,7 @@ #version 460 layout(location = 0) out vec4 frag_color; -uniform sampler2D image; +layout(binding = 0) uniform sampler2D image; layout(location = 0) in vec2 uv; layout(location = 1) flat in vec4 fColor; diff --git a/assets/cubyz/shaders/graphics/Line.fs b/assets/cubyz/shaders/graphics/Line.fs index 9deedff8..caf0d527 100644 --- a/assets/cubyz/shaders/graphics/Line.fs +++ b/assets/cubyz/shaders/graphics/Line.fs @@ -4,8 +4,6 @@ layout(location = 0) out vec4 frag_color; layout(location = 0) flat in vec4 color; -uniform sampler2D texture_sampler; - void main() { frag_color = color; } diff --git a/assets/cubyz/shaders/graphics/Line.vs b/assets/cubyz/shaders/graphics/Line.vs index 8e207ce6..75c9aed9 100644 --- a/assets/cubyz/shaders/graphics/Line.vs +++ b/assets/cubyz/shaders/graphics/Line.vs @@ -4,7 +4,6 @@ layout(location = 0) in vec2 vertex_pos; layout(location = 0) flat out vec4 color; - //in pixel uniform vec2 start; uniform vec2 direction; @@ -12,7 +11,6 @@ uniform vec2 screen; uniform int lineColor; - void main() { // Convert to opengl coordinates: vec2 position_percentage = (start + vertex_pos*direction)/screen; diff --git a/assets/cubyz/shaders/graphics/Text.fs b/assets/cubyz/shaders/graphics/Text.fs index 5ade0499..0c485f10 100644 --- a/assets/cubyz/shaders/graphics/Text.fs +++ b/assets/cubyz/shaders/graphics/Text.fs @@ -5,7 +5,7 @@ layout(location = 0) out vec4 frag_color; layout(location = 0) in vec2 frag_face_pos; layout(location = 1) flat in vec4 color; -uniform sampler2D texture_sampler; +layout(binding = 0) uniform sampler2D textureSampler; // in pixels uniform vec4 texture_rect; @@ -30,10 +30,10 @@ void main() { ); if ((fontEffects & 0x01000000) != 0) { // make it bold in y by sampling more pixels. vec2 pixel_offset = 1/fontSize; - frag_color = color*max(texture(texture_sampler, texture_position).r, - texture(texture_sampler, texture_position + vec2(0, 0.5f/fontSize.y)).r); + frag_color = color*max(texture(textureSampler, texture_position).r, + texture(textureSampler, texture_position + vec2(0, 0.5f/fontSize.y)).r); } else { - frag_color = color*texture(texture_sampler, + frag_color = color*texture(textureSampler, texture_position).r; } } diff --git a/assets/cubyz/shaders/item_drop.fs b/assets/cubyz/shaders/item_drop.fs index 3c55b4e5..69921a15 100644 --- a/assets/cubyz/shaders/item_drop.fs +++ b/assets/cubyz/shaders/item_drop.fs @@ -13,14 +13,15 @@ layout(location = 9) flat in uvec3 upper; layout(location = 0) out vec4 fragColor; +layout(binding = 0) uniform sampler2DArray textureSampler; +layout(binding = 1) uniform sampler2DArray emissionSampler; +layout(binding = 2) uniform sampler2DArray reflectivityAndAbsorptionSampler; +layout(binding = 4) uniform samplerCube reflectionMap; + uniform vec3 ambientLight; uniform mat4 projectionMatrix; uniform float sizeScale; -uniform sampler2DArray texture_sampler; -uniform sampler2DArray emissionSampler; -uniform sampler2DArray reflectivityAndAbsorptionSampler; -uniform samplerCube reflectionMap; uniform float reflectionMapSize; uniform float contrast; @@ -81,7 +82,7 @@ void mainBlockDrop() { reflectivity = reflectivity*(1 - fresnelReflection) + fresnelReflection; vec3 pixelLight = ambientLight*max(vec3(normalVariation), texture(emissionSampler, textureCoords).r*4); - fragColor = texture(texture_sampler, textureCoords)*vec4(pixelLight, 1); + fragColor = texture(textureSampler, textureCoords)*vec4(pixelLight, 1); fragColor.rgb += reflectivity*pixelLight; if(!passDitherTest(fragColor.a)) discard; diff --git a/assets/cubyz/shaders/item_texture_post.fs b/assets/cubyz/shaders/item_texture_post.fs index 94377be2..47923fcc 100644 --- a/assets/cubyz/shaders/item_texture_post.fs +++ b/assets/cubyz/shaders/item_texture_post.fs @@ -4,7 +4,8 @@ layout(location = 0) out vec4 fragColor; layout(location = 0) in vec2 texCoords; -uniform sampler2D color; +layout(binding = 3) uniform sampler2D color; + uniform bool transparent; void main() { diff --git a/assets/cubyz/shaders/ui/button.fs b/assets/cubyz/shaders/ui/button.fs index 8ddac775..6787f18c 100644 --- a/assets/cubyz/shaders/ui/button.fs +++ b/assets/cubyz/shaders/ui/button.fs @@ -1,11 +1,12 @@ #version 460 layout(location = 0) out vec4 frag_color; -uniform sampler2D image; layout(location = 0) in vec2 startCoord; layout(location = 1) flat in vec4 fColor; +layout(binding = 0) uniform sampler2D image; + uniform float scale; void main() { diff --git a/src/entity.zig b/src/entity.zig index de186d16..315638fd 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -87,7 +87,6 @@ pub const ClientEntityManager = struct { var uniforms: struct { projectionMatrix: c_int, viewMatrix: c_int, - texture_sampler: c_int, light: c_int, contrast: c_int, ambientLight: c_int, @@ -176,7 +175,6 @@ pub const ClientEntityManager = struct { c.glBindVertexArray(main.renderer.chunk_meshing.vao); c.glUniformMatrix4fv(uniforms.projectionMatrix, 1, c.GL_TRUE, @ptrCast(&projMatrix)); modelTexture.bindTo(0); - c.glUniform1i(uniforms.texture_sampler, 0); c.glUniform3fv(uniforms.ambientLight, 1, @ptrCast(&ambientLight)); c.glUniform3fv(uniforms.directionalLight, 1, @ptrCast(&directionalLight)); c.glUniform1f(uniforms.contrast, 0.12); diff --git a/src/graphics.zig b/src/graphics.zig index d85c0af7..15b39e16 100644 --- a/src/graphics.zig +++ b/src/graphics.zig @@ -393,7 +393,6 @@ pub const draw = struct { // MARK: draw screen: c_int, start: c_int, size: c_int, - image: c_int, color: c_int, uvOffset: c_int, uvDim: c_int, @@ -1055,7 +1054,6 @@ const TextRendering = struct { // MARK: TextRendering ratio: c_int, fontEffects: c_int, fontSize: c_int, - texture_sampler: c_int, alpha: c_int, } = undefined; @@ -1081,7 +1079,6 @@ const TextRendering = struct { // MARK: TextRendering shader = Shader.initAndGetUniforms("assets/cubyz/shaders/graphics/Text.vs", "assets/cubyz/shaders/graphics/Text.fs", "", &uniforms); shader.bind(); errdefer shader.deinit(); - c.glUniform1i(uniforms.texture_sampler, 0); c.glUniform1f(uniforms.alpha, 1.0); c.glUniform2f(uniforms.fontSize, @floatFromInt(textureWidth), @floatFromInt(textureHeight)); try ftError(hbft.FT_Init_FreeType(&freetypeLib)); @@ -2016,7 +2013,6 @@ pub const Fog = struct { // MARK: Fog const block_texture = struct { // MARK: block_texture var uniforms: struct { - color: c_int, transparent: c_int, } = undefined; var shader: Shader = undefined; @@ -2151,7 +2147,6 @@ pub fn generateBlockTexture(blockType: u16) Texture { defer c.glDeleteFramebuffers(1, &finalFrameBuffer.frameBuffer); block_texture.shader.bind(); c.glUniform1i(block_texture.uniforms.transparent, if(block.transparent()) c.GL_TRUE else c.GL_FALSE); - c.glUniform1i(block_texture.uniforms.color, 3); frameBuffer.bindTexture(c.GL_TEXTURE3); c.glBindVertexArray(draw.rectVAO); diff --git a/src/gui/components/Button.zig b/src/gui/components/Button.zig index 1984ee29..db9fbf3a 100644 --- a/src/gui/components/Button.zig +++ b/src/gui/components/Button.zig @@ -51,8 +51,6 @@ pub var buttonUniforms: struct { size: c_int, color: c_int, scale: c_int, - - image: c_int, } = undefined; pos: Vec2f, @@ -65,7 +63,6 @@ child: GuiComponent, pub fn __init() void { shader = Shader.initAndGetUniforms("assets/cubyz/shaders/ui/button.vs", "assets/cubyz/shaders/ui/button.fs", "", &buttonUniforms); shader.bind(); - graphics.c.glUniform1i(buttonUniforms.image, 0); normalTextures = Textures.init("assets/cubyz/ui/button"); hoveredTextures = Textures.init("assets/cubyz/ui/button_hovered"); pressedTextures = Textures.init("assets/cubyz/ui/button_pressed"); diff --git a/src/itemdrop.zig b/src/itemdrop.zig index f5cd8715..b7853530 100644 --- a/src/itemdrop.zig +++ b/src/itemdrop.zig @@ -551,10 +551,6 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer ambientLight: c_int, modelIndex: c_int, block: c_int, - texture_sampler: c_int, - emissionSampler: c_int, - reflectivityAndAbsorptionSampler: c_int, - reflectionMap: c_int, reflectionMapSize: c_int, contrast: c_int, } = undefined; @@ -681,10 +677,6 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer fn bindCommonUniforms(projMatrix: Mat4f, viewMatrix: Mat4f, ambientLight: Vec3f) void { itemShader.bind(); - c.glUniform1i(itemUniforms.texture_sampler, 0); - c.glUniform1i(itemUniforms.emissionSampler, 1); - c.glUniform1i(itemUniforms.reflectivityAndAbsorptionSampler, 2); - c.glUniform1i(itemUniforms.reflectionMap, 4); c.glUniform1f(itemUniforms.reflectionMapSize, main.renderer.reflectionCubeMapSize); c.glUniformMatrix4fv(itemUniforms.projectionMatrix, 1, c.GL_TRUE, @ptrCast(&projMatrix)); c.glUniform3fv(itemUniforms.ambientLight, 1, @ptrCast(&ambientLight)); diff --git a/src/renderer.zig b/src/renderer.zig index aa8d1fa8..74ac843e 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -35,8 +35,6 @@ pub const zFar = 65536.0; // TODO: Fix z-fighting problems. var deferredRenderPassShader: graphics.Shader = undefined; var deferredUniforms: struct { - color: c_int, - depthTexture: c_int, @"fog.color": c_int, @"fog.density": c_int, @"fog.fogLower": c_int, @@ -278,8 +276,6 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, skyColor: Vec3f, playerPo worldFrameBuffer.bindDepthTexture(c.GL_TEXTURE4); worldFrameBuffer.unbind(); deferredRenderPassShader.bind(); - c.glUniform1i(deferredUniforms.color, 3); - c.glUniform1i(deferredUniforms.depthTexture, 4); if(!blocks.meshes.hasFog(playerBlock)) { c.glUniform3fv(deferredUniforms.@"fog.color", 1, @ptrCast(&game.fog.skyColor)); c.glUniform1f(deferredUniforms.@"fog.density", game.fog.density); @@ -322,7 +318,6 @@ const Bloom = struct { // MARK: Bloom var secondPassShader: graphics.Shader = undefined; var colorExtractAndDownsampleShader: graphics.Shader = undefined; var colorExtractUniforms: struct { - depthTexture: c_int, zNear: c_int, zFar: c_int, tanXY: c_int, @@ -357,7 +352,6 @@ const Bloom = struct { // MARK: Bloom worldFrameBuffer.bindTexture(c.GL_TEXTURE3); worldFrameBuffer.bindDepthTexture(c.GL_TEXTURE4); buffer1.bind(); - c.glUniform1i(colorExtractUniforms.depthTexture, 4); if(!blocks.meshes.hasFog(playerBlock)) { c.glUniform3fv(colorExtractUniforms.@"fog.color", 1, @ptrCast(&game.fog.skyColor)); c.glUniform1f(colorExtractUniforms.@"fog.density", game.fog.density); @@ -438,7 +432,6 @@ const Bloom = struct { // MARK: Bloom pub const MenuBackGround = struct { var shader: Shader = undefined; var uniforms: struct { - image: c_int, viewMatrix: c_int, projectionMatrix: c_int, } = undefined; @@ -454,7 +447,6 @@ pub const MenuBackGround = struct { lastTime = std.time.nanoTimestamp(); shader = Shader.initAndGetUniforms("assets/cubyz/shaders/background/vertex.vs", "assets/cubyz/shaders/background/fragment.fs", "", &uniforms); shader.bind(); - c.glUniform1i(uniforms.image, 0); // 4 sides of a simple cube with some panorama texture on it. const rawData = [_]f32{ -1, 1, -1, 1, 1, diff --git a/src/renderer/chunk_meshing.zig b/src/renderer/chunk_meshing.zig index 942bea27..814b5ac2 100644 --- a/src/renderer/chunk_meshing.zig +++ b/src/renderer/chunk_meshing.zig @@ -39,10 +39,6 @@ const UniformStruct = struct { @"fog.density": c_int, @"fog.fogLower": c_int, @"fog.fogHigher": c_int, - texture_sampler: c_int, - emissionSampler: c_int, - reflectivityAndAbsorptionSampler: c_int, - reflectionMap: c_int, reflectionMapSize: c_int, lodDistance: c_int, zNear: c_int, @@ -137,10 +133,6 @@ pub fn endRender() void { fn bindCommonUniforms(locations: *UniformStruct, projMatrix: Mat4f, ambient: Vec3f, playerPos: Vec3d) void { c.glUniformMatrix4fv(locations.projectionMatrix, 1, c.GL_TRUE, @ptrCast(&projMatrix)); - c.glUniform1i(locations.texture_sampler, 0); - c.glUniform1i(locations.emissionSampler, 1); - c.glUniform1i(locations.reflectivityAndAbsorptionSampler, 2); - c.glUniform1i(locations.reflectionMap, 4); c.glUniform1f(locations.reflectionMapSize, renderer.reflectionCubeMapSize); c.glUniform1f(locations.contrast, 0);