diff --git a/internal/asset/shader/world/geometry.frag b/internal/asset/shader/world/geometry.frag index f22028d..324b423 100644 --- a/internal/asset/shader/world/geometry.frag +++ b/internal/asset/shader/world/geometry.frag @@ -23,6 +23,6 @@ void main() { outputNormal.xyz = fragNormal; outputNormal.w = fragPosLightspaceZ; outputColor = texture(tex, fragTexCoord); - outputColor = vec4(pow(outputColor.rgb, vec3(gamma)), outputColor.a); + outputColor = vec4(outputColor.rgb, outputColor.a); } diff --git a/internal/asset/shader/world/water.frag b/internal/asset/shader/world/water.frag index 3681ebf..52856d6 100644 --- a/internal/asset/shader/world/water.frag +++ b/internal/asset/shader/world/water.frag @@ -34,7 +34,7 @@ void lightPoint(int i); void main() { - fragColor = vec4(pow(texture(tex, fragTexCoord).rgb, vec3(gamma)), 1.0f); + fragColor = vec4(texture(tex, fragTexCoord).rgb, 1.0f); finalpha = alpha; light = ambient; diff --git a/internal/render/render_world.go b/internal/render/render_world.go index 89d8970..f85dcdf 100644 --- a/internal/render/render_world.go +++ b/internal/render/render_world.go @@ -126,7 +126,8 @@ func (r *WorldRenderer) Init(w *world.World) (err error) { gl.GetFloatv(gl.MAX_TEXTURE_MAX_ANISOTROPY, &maxaf) asset.InitWorldTextureAtlas() - r.texture = NewTextureRGBA(asset.WorldTextureAtlas.Image) + r.texture = NewTexture() + r.texture.UpdatesRGB(asset.WorldTextureAtlas.Image) r.texture.GenerateMipMap() gl.BindTexture(gl.TEXTURE_2D, r.texture.Handle()) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_ANISOTROPY, maxaf) diff --git a/internal/render/texture.go b/internal/render/texture.go index 05e2326..51856c4 100644 --- a/internal/render/texture.go +++ b/internal/render/texture.go @@ -127,6 +127,37 @@ func (t *Texture) UpdateRGBA(image *image.RGBA) { t.updateFilters() } +// UpdatesRGB updates the content of the texture with image in sRGB space. +// It deletes existing mipmap, you need to generate it again. +// +// The internal data is converted from sRGB to linear space by OpenGL: +// +// linear = sRGB/12.92 (if sRGB <= 0.04045) +// [(sRGB+0.055)/1.055]^2.4 (if sRGB > 0.04045) +// +// The Alpha component is not converted. +func (t *Texture) UpdatesRGB(image *image.RGBA) { + // Restore current texture binding + defer gl.BindTexture(gl.TEXTURE_2D, curTextureBinding()) + + gl.BindTexture(gl.TEXTURE_2D, t.tex) + gl.TexImage2D( + gl.TEXTURE_2D, + 0, + gl.SRGB_ALPHA, + int32(image.Rect.Size().X), + int32(image.Rect.Size().Y), + 0, + gl.RGBA, + gl.UNSIGNED_BYTE, + gl.Ptr(image.Pix), + ) + gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) + + t.hasMipmap = false + t.updateFilters() +} + // GenerateMipMap generates mipmap for the texture. func (t *Texture) GenerateMipMap() {