HDR output buffer (WIP)
This commit is contained in:
@ -121,9 +121,15 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
|
||||
return errors.New("output: " + err.Error())
|
||||
}
|
||||
|
||||
// get the maximum anisotropic filtering level
|
||||
var maxaf float32
|
||||
gl.GetFloatv(gl.MAX_TEXTURE_MAX_ANISOTROPY, &maxaf)
|
||||
|
||||
asset.InitWorldTextureAtlas()
|
||||
r.texture = NewTextureRGBA(asset.WorldTextureAtlas.Image)
|
||||
r.texture.GenerateMipMap()
|
||||
gl.BindTexture(gl.TEXTURE_2D, r.texture.Handle())
|
||||
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_ANISOTROPY, maxaf)
|
||||
r.gbuffer.shader.SetUniformTexture("tex", r.texture)
|
||||
r.water.shader.SetUniformTexture("tex", r.texture)
|
||||
|
||||
@ -261,7 +267,7 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
|
||||
// output
|
||||
gl.GenTextures(1, &r.output.tex)
|
||||
gl.BindTexture(gl.TEXTURE_2D, r.output.tex)
|
||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.FLOAT, nil)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
|
||||
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, r.output.tex, 0)
|
||||
@ -288,8 +294,12 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
|
||||
func (r *WorldRenderer) ResizeDisplay(newSize itype.Vec2i) {
|
||||
}
|
||||
|
||||
var sun = [3]float32{0.2, 0.4, 0.3}
|
||||
var alpha float32 = 0.55
|
||||
var (
|
||||
sun = [3]float32{0.2, 0.4, 0.3}
|
||||
alpha = float32(0.55)
|
||||
gamma = float32(2.2)
|
||||
exposure = float32(1)
|
||||
)
|
||||
|
||||
func (r *WorldRenderer) Render(world *world.World, view *View) {
|
||||
io.RenderPos = io.ViewPos
|
||||
@ -317,6 +327,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
|
||||
imgui.SliderFloat3("Sun", &sun, -1, 1)
|
||||
normalSun := itype.Vec3f(sun).Normalize()
|
||||
imgui.SliderFloat("Water Alpha", &alpha, 0, 1)
|
||||
imgui.SliderFloat("Gamma", &gamma, 1.6, 2.8)
|
||||
imgui.SliderFloat("Exposure", &exposure, 0, 2)
|
||||
|
||||
gl.Enable(gl.CULL_FACE)
|
||||
gl.Enable(gl.DEPTH_TEST)
|
||||
@ -356,6 +368,7 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
|
||||
r.gbuffer.shader.SetUniformMat4("lightspace", lightspace)
|
||||
r.gbuffer.shader.SetUniformMat4("view", view.View())
|
||||
r.gbuffer.shader.SetUniformMat4("projection", view.Perspective())
|
||||
r.gbuffer.shader.SetUniformMat4("mvp", view.Perspective().Mul4(view.View()))
|
||||
r.gbuffer.shader.SetUniformVec3f("viewPos", view.EyePos)
|
||||
|
||||
world.Render()
|
||||
@ -384,7 +397,7 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
|
||||
|
||||
// 4. Render the actual output with deferred lighting
|
||||
gl.BindFramebuffer(gl.FRAMEBUFFER, r.output.fbo)
|
||||
gl.ClearColor(io.ClearColor[0], io.ClearColor[1], io.ClearColor[2], io.ClearColor[3])
|
||||
gl.ClearColor(0, 0, 0, 0)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
gl.Disable(gl.DEPTH_TEST)
|
||||
r.lighting.shader.UseProgram()
|
||||
@ -418,10 +431,14 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
|
||||
|
||||
// Finally. Copy the output texture to the back buffer
|
||||
gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
|
||||
gl.ClearColor(io.ClearColor[0], io.ClearColor[1], io.ClearColor[2], io.ClearColor[3])
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
gl.Disable(gl.DEPTH_TEST)
|
||||
gl.Disable(gl.BLEND)
|
||||
r.output.shader.UseProgram()
|
||||
r.output.shader.BindTextures()
|
||||
r.output.shader.SetUniformFloat("gamma", gamma)
|
||||
r.output.shader.SetUniformFloat("exposure", exposure)
|
||||
|
||||
DrawScreenQuad()
|
||||
|
||||
|
Reference in New Issue
Block a user