tofu

Making something with OpenGL in Go
Log | Files | Refs

commit c69546899afc84662eb6c4d57579c30033cf4b3e
parent 173b8323918b38e4a0f0071be99622d7ac987746
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 18 Nov 2024 13:48:42 +0900

fix bug: normalize norm

Diffstat:
Mcmd/sample/fragment.glsl | 4++--
Mcmd/sample/main.go | 5++---
Mcmd/sample/teapot.glsl | 17+----------------
3 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/cmd/sample/fragment.glsl b/cmd/sample/fragment.glsl @@ -54,8 +54,8 @@ void main() { diffuse = diff * vec3(texture(material.diffuse, texPos)) * light.diffuse * intensity; viewDir = normalize(camPos - fpos); - reflectDir = reflect(-lightDir, fnormal); - spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shiness); + reflectDir = reflect(-lightDir, normalize(fnormal)); + spec = pow(max(dot(viewDir, reflectDir), 0), material.shiness); specular = vec3(texture(material.specular, texPos)) * spec * light.specular * intensity; fcol += vec4(ambient + diffuse + specular, 0) * attenuation; diff --git a/cmd/sample/main.go b/cmd/sample/main.go @@ -149,7 +149,6 @@ type App struct { func (app *App) Update() error { now := float32(time.Since(app.startedAt).Seconds()) - now = 0 processInput(app) if app.termination { return tofu.Termination @@ -198,11 +197,11 @@ func (app *App) Update() error { app.teapotProgram.Use() app.teapotProgram.SetMat4("view", view) app.teapotProgram.SetMat4("projection", projection) - app.teapotProgram.SetMat4("model", tofu.Translate(tofu.Vec3{0, 0, 0}).Mul(tofu.Scale(0.06))) + app.teapotProgram.SetMat4("model", tofu.Translate(tofu.Vec3{-5, -5, 0}).Mul(tofu.Scale(0.06))) app.teapotProgram.SetVec3("camPos", camera.Pos) app.teapotProgram.SetVec3("material.diffuse", tofu.Vec3{0.3, 0.4, 0.4}) app.teapotProgram.SetVec3("material.specular", tofu.Vec3{0.3, 0.4, 0.4}) - app.teapotProgram.SetFloat32("material.shiness", 0) + app.teapotProgram.SetFloat32("material.shiness", 32) app.teapotProgram.SetVec3("sun.dir", sunDir) app.teapotProgram.SetVec3("sun.ambient", sunCol.MulF(0.5)) app.teapotProgram.SetVec3("sun.diffuse", sunCol.MulF(0.3)) diff --git a/cmd/sample/teapot.glsl b/cmd/sample/teapot.glsl @@ -54,26 +54,11 @@ void main() { diffuse = diff * material.diffuse * light.diffuse * intensity; viewDir = normalize(camPos - fpos); - reflectDir = reflect(-lightDir, fnormal); + reflectDir = reflect(-lightDir, normalize(fnormal)); spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shiness); specular = material.specular * spec * light.specular * intensity; - - // BUG: -/* - fcol += vec4(specular.x, 0, 0, 0); - fcol += vec4(diffuse.x, 0, 0, 0); - fcol += vec4(ambient.x, 0, 0, 0); - if (fcol.x == 1) { - fcol = vec4(0, 1, 1, 1); - return; - } -*/ fcol += vec4((ambient+diffuse+specular) * attenuation, 0); - if (fcol.x == 0) { - fcol = vec4(0, 1, 1, 1); - } - return; ambient = material.diffuse * sun.ambient;