let OpenGL handle sRGB conversion
This commit is contained in:
		| @@ -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); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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() { | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user