Explicitly specify image bindings for all sampler uniforms.

progress towards #1376
This commit is contained in:
IntegratedQuantum 2025-05-02 15:49:01 +02:00
parent 9898db654b
commit 3ba4d5fd14
19 changed files with 36 additions and 68 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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));

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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() {

View File

@ -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() {

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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));

View File

@ -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,

View File

@ -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);