let OpenGL handle sRGB conversion
This commit is contained in:
parent
5155008bf0
commit
4204a15b1e
@ -23,6 +23,6 @@ void main() {
|
|||||||
outputNormal.xyz = fragNormal;
|
outputNormal.xyz = fragNormal;
|
||||||
outputNormal.w = fragPosLightspaceZ;
|
outputNormal.w = fragPosLightspaceZ;
|
||||||
outputColor = texture(tex, fragTexCoord);
|
outputColor = texture(tex, fragTexCoord);
|
||||||
outputColor = vec4(pow(outputColor.rgb, vec3(gamma)), outputColor.a);
|
outputColor = vec4(outputColor.rgb, outputColor.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void lightPoint(int i);
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
fragColor = vec4(pow(texture(tex, fragTexCoord).rgb, vec3(gamma)), 1.0f);
|
fragColor = vec4(texture(tex, fragTexCoord).rgb, 1.0f);
|
||||||
|
|
||||||
finalpha = alpha;
|
finalpha = alpha;
|
||||||
light = ambient;
|
light = ambient;
|
||||||
|
@ -126,7 +126,8 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
|
|||||||
gl.GetFloatv(gl.MAX_TEXTURE_MAX_ANISOTROPY, &maxaf)
|
gl.GetFloatv(gl.MAX_TEXTURE_MAX_ANISOTROPY, &maxaf)
|
||||||
|
|
||||||
asset.InitWorldTextureAtlas()
|
asset.InitWorldTextureAtlas()
|
||||||
r.texture = NewTextureRGBA(asset.WorldTextureAtlas.Image)
|
r.texture = NewTexture()
|
||||||
|
r.texture.UpdatesRGB(asset.WorldTextureAtlas.Image)
|
||||||
r.texture.GenerateMipMap()
|
r.texture.GenerateMipMap()
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.texture.Handle())
|
gl.BindTexture(gl.TEXTURE_2D, r.texture.Handle())
|
||||||
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_ANISOTROPY, maxaf)
|
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_ANISOTROPY, maxaf)
|
||||||
|
@ -127,6 +127,37 @@ func (t *Texture) UpdateRGBA(image *image.RGBA) {
|
|||||||
t.updateFilters()
|
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.
|
// GenerateMipMap generates mipmap for the texture.
|
||||||
func (t *Texture) GenerateMipMap() {
|
func (t *Texture) GenerateMipMap() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user