tofu

Making something with OpenGL in Go
Log | Files | Refs

commit 7c7d3b856a7f34a9f9e1e32bdb43a38d90dd0ec7
parent 9360873ea55df80f683402e47f5f79bb55efe620
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed, 13 Nov 2024 09:41:18 +0900

emission

Diffstat:
Mcmd/sample/fragment.glsl | 5++++-
Mcmd/sample/main.go | 10+++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/cmd/sample/fragment.glsl b/cmd/sample/fragment.glsl @@ -3,6 +3,7 @@ struct Material { sampler2D diffuse; sampler2D specular; + sampler2D emission; float shiness; }; @@ -36,6 +37,8 @@ void main() { float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shiness); vec3 specular = vec3(texture(material.specular, texPos)) * spec * light.specular; - fcol = vec4(ambient + diffuse + specular, 1.0); + vec3 emission = texture(material.emission, texPos).rgb; + + fcol = vec4(ambient + diffuse + specular + emission, 1.0); } diff --git a/cmd/sample/main.go b/cmd/sample/main.go @@ -22,7 +22,7 @@ func init() { } func processInput(app *App) { - const speed = 0.1 + const speed = 0.05 if tofu.IsKeyPressed(tofu.KeyQ) { app.termination = true return @@ -141,10 +141,12 @@ type App struct { startedAt time.Time texture *tofu.Texture specularMap *tofu.Texture + emission *tofu.Texture } func (app *App) Update() error { now := float32(time.Since(app.startedAt).Seconds()) + now = 0 processInput(app) if app.termination { return tofu.Termination @@ -173,6 +175,7 @@ func (app *App) Update() error { app.program.SetVec3("camPos", camera.Pos) app.program.SetTexture("material.diffuse", app.texture) app.program.SetTexture("material.specular", app.specularMap) + app.program.SetTexture("material.emission", app.emission) app.program.SetFloat32("material.shiness", 32) model := tofu.Translate(tofu.Vec3{0, 0, 0}). Mul(tofu.Rotate(now, tofu.Vec3{math.Sqrt2 / 2, -math.Sqrt2 / 2, 0})) @@ -214,6 +217,7 @@ func main() { lightFpath := filepath.Join(filepath.Dir(f), "light_fragment.glsl") texturePath := filepath.Join(filepath.Dir(f), "container2.png") specularMapPath := filepath.Join(filepath.Dir(f), "container2_specular.png") + emissionPath := filepath.Join(filepath.Dir(f), "matrix.jpg") app.program, err = tofu.NewProgram(vpath, fpath) if err != nil { @@ -231,6 +235,10 @@ func main() { if err != nil { log.Fatalf("NewTesture: %v", err) } + app.emission, err = tofu.NewTexture(emissionPath) + if err != nil { + log.Fatalf("NewTesture: %v", err) + } camera = tofu.NewCamera() camera.MoveTo(tofu.Vec3{0, 0, 3})