mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Compare commits
4 Commits
01f06cce1e
...
3c0f82a735
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c0f82a735 | |||
| c058b82a92 | |||
| 908e5e96aa | |||
| c83e263476 |
4
.github/workflows/build-nmage.yml
vendored
4
.github/workflows/build-nmage.yml
vendored
@ -9,10 +9,10 @@ jobs:
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
|
||||
- name: Install golang 1.18
|
||||
- name: Install golang
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.18'
|
||||
go-version: '>=1.18'
|
||||
|
||||
- name: Install assimp-go dylib
|
||||
run: sudo mkdir -p /usr/local/lib && sudo wget https://github.com/bloeys/assimp-go/releases/download/v0.4.2/libassimp_darwin_amd64.dylib -O /usr/local/lib/libassimp.5.dylib
|
||||
|
||||
240
main.go
240
main.go
@ -22,16 +22,24 @@ import (
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
// @Todo:
|
||||
// Integrate physx
|
||||
// Create VAO struct independent from VBO to support multi-VBO use cases (e.g. instancing)
|
||||
// Renderer batching
|
||||
// Scene graph
|
||||
// Separate engine loop from rendering loop? or leave it to the user?
|
||||
// Abstract keys enum away from sdl
|
||||
// Proper Asset loading
|
||||
// Frustum culling
|
||||
// Material system editor with fields automatically extracted from the shader
|
||||
/*
|
||||
@TODO:
|
||||
- Rendering:
|
||||
- Phong lighting model
|
||||
- Point lights
|
||||
- Spotlights
|
||||
- HDR
|
||||
- Cascaded shadow mapping
|
||||
- Skeletal animations
|
||||
- Create VAO struct independent from VBO to support multi-VBO use cases (e.g. instancing)
|
||||
- Renderer batching
|
||||
- Scene graph
|
||||
- Separate engine loop from rendering loop? or leave it to the user?
|
||||
- Abstract keys enum away from sdl
|
||||
- Proper Asset loading
|
||||
- Frustum culling
|
||||
- Material system editor with fields automatically extracted from the shader
|
||||
*/
|
||||
|
||||
const (
|
||||
camSpeed = 15
|
||||
@ -45,27 +53,34 @@ var (
|
||||
window *engine.Window
|
||||
|
||||
pitch float32 = 0
|
||||
yaw float32 = -90
|
||||
yaw float32 = 0
|
||||
cam *camera.Camera
|
||||
|
||||
simpleMat *materials.Material
|
||||
skyboxMat *materials.Material
|
||||
whiteMat *materials.Material
|
||||
containerMat *materials.Material
|
||||
palleteMat *materials.Material
|
||||
skyboxMat *materials.Material
|
||||
debugDepthMat *materials.Material
|
||||
|
||||
chairMesh *meshes.Mesh
|
||||
cubeMesh *meshes.Mesh
|
||||
sphereMesh *meshes.Mesh
|
||||
chairMesh *meshes.Mesh
|
||||
skyboxMesh *meshes.Mesh
|
||||
|
||||
cubeModelMat = gglm.NewTrMatId()
|
||||
|
||||
lightPos1 = gglm.NewVec3(-2, 0, 2)
|
||||
lightColor1 = gglm.NewVec3(1, 1, 1)
|
||||
|
||||
debugDepthMat *materials.Material
|
||||
debugDrawDepthBuffer bool
|
||||
|
||||
skyboxCmap assets.Cubemap
|
||||
|
||||
dpiScaling float32
|
||||
|
||||
// Light settings
|
||||
ambientColor = gglm.NewVec3(0.2, 0.2, 0.2)
|
||||
|
||||
// Lights
|
||||
lightPos1 = gglm.NewVec3(-2, 10, 0)
|
||||
lightColor1 = gglm.NewVec3(1, 1, 1)
|
||||
)
|
||||
|
||||
type OurGame struct {
|
||||
@ -165,7 +180,7 @@ func (g *OurGame) handleWindowEvents(e sdl.Event) {
|
||||
cam.AspectRatio = float32(width) / float32(height)
|
||||
cam.Update()
|
||||
|
||||
simpleMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
palleteMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
debugDepthMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
}
|
||||
}
|
||||
@ -209,13 +224,24 @@ func (g *OurGame) Init() {
|
||||
|
||||
var err error
|
||||
|
||||
//Create materials
|
||||
simpleMat = materials.NewMaterial("Simple mat", "./res/shaders/simple.glsl")
|
||||
debugDepthMat = materials.NewMaterial("Debug depth mat", "./res/shaders/debug-depth.glsl")
|
||||
skyboxMat = materials.NewMaterial("Skybox mat", "./res/shaders/skybox.glsl")
|
||||
// Camera
|
||||
winWidth, winHeight := g.Win.SDLWin.GetSize()
|
||||
cam = camera.NewPerspective(
|
||||
gglm.NewVec3(0, 0, 10),
|
||||
gglm.NewVec3(0, 0, -1),
|
||||
gglm.NewVec3(0, 1, 0),
|
||||
0.1, 200,
|
||||
45*gglm.Deg2Rad,
|
||||
float32(winWidth)/float32(winHeight),
|
||||
)
|
||||
|
||||
//Load meshes
|
||||
cubeMesh, err = meshes.NewMesh("Cube", "./res/models/tex-cube.fbx", 0)
|
||||
cubeMesh, err = meshes.NewMesh("Cube", "./res/models/cube.fbx", 0)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load mesh. Err: ", err)
|
||||
}
|
||||
|
||||
sphereMesh, err = meshes.NewMesh("Sphere", "./res/models/sphere.fbx", 0)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load mesh. Err: ", err)
|
||||
}
|
||||
@ -231,7 +257,22 @@ func (g *OurGame) Init() {
|
||||
}
|
||||
|
||||
//Load textures
|
||||
tex, err := assets.LoadTexturePNG("./res/textures/pallete-endesga-64-1x.png", &assets.TextureLoadOptions{TextureIsSrgba: true})
|
||||
whiteTex, err := assets.LoadTexturePNG("./res/textures/white.png", &assets.TextureLoadOptions{TextureIsSrgba: true})
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load texture. Err: ", err)
|
||||
}
|
||||
|
||||
containerDiffuseTex, err := assets.LoadTexturePNG("./res/textures/container-diffuse.png", &assets.TextureLoadOptions{TextureIsSrgba: true})
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load texture. Err: ", err)
|
||||
}
|
||||
|
||||
containerSpecularTex, err := assets.LoadTexturePNG("./res/textures/container-specular.png", &assets.TextureLoadOptions{TextureIsSrgba: true})
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load texture. Err: ", err)
|
||||
}
|
||||
|
||||
palleteTex, err := assets.LoadTexturePNG("./res/textures/pallete-endesga-64-1x.png", &assets.TextureLoadOptions{TextureIsSrgba: true})
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load texture. Err: ", err)
|
||||
}
|
||||
@ -246,36 +287,47 @@ func (g *OurGame) Init() {
|
||||
logging.ErrLog.Fatalln("Failed to load cubemap. Err: ", err)
|
||||
}
|
||||
|
||||
// Configure materials
|
||||
simpleMat.DiffuseTex = tex.TexID
|
||||
// Create materials
|
||||
whiteMat = materials.NewMaterial("White mat", "./res/shaders/simple.glsl")
|
||||
whiteMat.Shininess = 128
|
||||
whiteMat.DiffuseTex = whiteTex.TexID
|
||||
whiteMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
whiteMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
whiteMat.SetUnifFloat32("material.shininess", whiteMat.Shininess)
|
||||
whiteMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
whiteMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
|
||||
//Movement, scale and rotation
|
||||
containerMat = materials.NewMaterial("Container mat", "./res/shaders/simple.glsl")
|
||||
containerMat.Shininess = 128
|
||||
containerMat.DiffuseTex = containerDiffuseTex.TexID
|
||||
containerMat.SpecularTex = containerSpecularTex.TexID
|
||||
containerMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
containerMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
containerMat.SetUnifFloat32("material.shininess", containerMat.Shininess)
|
||||
containerMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
containerMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
|
||||
palleteMat = materials.NewMaterial("Pallete mat", "./res/shaders/simple.glsl")
|
||||
palleteMat.Shininess = 128
|
||||
palleteMat.DiffuseTex = palleteTex.TexID
|
||||
palleteMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
palleteMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
palleteMat.SetUnifFloat32("material.shininess", palleteMat.Shininess)
|
||||
palleteMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
palleteMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
|
||||
debugDepthMat = materials.NewMaterial("Debug depth mat", "./res/shaders/debug-depth.glsl")
|
||||
debugDepthMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
|
||||
skyboxMat = materials.NewMaterial("Skybox mat", "./res/shaders/skybox.glsl")
|
||||
|
||||
// Movement, scale and rotation
|
||||
translationMat := gglm.NewTranslationMat(gglm.NewVec3(0, 0, 0))
|
||||
scaleMat := gglm.NewScaleMat(gglm.NewVec3(1, 1, 1))
|
||||
rotMat := gglm.NewRotMat(gglm.NewQuatEuler(gglm.NewVec3(-90, -90, 0).AsRad()))
|
||||
|
||||
cubeModelMat.Mul(translationMat.Mul(rotMat.Mul(scaleMat)))
|
||||
|
||||
// Camera
|
||||
winWidth, winHeight := g.Win.SDLWin.GetSize()
|
||||
cam = camera.NewPerspective(
|
||||
gglm.NewVec3(0, 0, 10),
|
||||
gglm.NewVec3(0, 0, -1),
|
||||
gglm.NewVec3(0, 1, 0),
|
||||
0.1, 200,
|
||||
45*gglm.Deg2Rad,
|
||||
float32(winWidth)/float32(winHeight),
|
||||
)
|
||||
simpleMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
debugDepthMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
|
||||
updateViewMat()
|
||||
|
||||
//Lights
|
||||
simpleMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
simpleMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
|
||||
sdl.SetRelativeMouseMode(true)
|
||||
}
|
||||
|
||||
func (g *OurGame) Update() {
|
||||
@ -287,14 +339,27 @@ func (g *OurGame) Update() {
|
||||
g.updateCameraLookAround()
|
||||
g.updateCameraPos()
|
||||
|
||||
imgui.ShowDemoWindow()
|
||||
|
||||
//Rotating cubes
|
||||
if input.KeyDown(sdl.K_SPACE) {
|
||||
cubeModelMat.Rotate(10*timing.DT()*gglm.Deg2Rad, gglm.NewVec3(1, 1, 1).Normalize())
|
||||
}
|
||||
|
||||
g.showDebugWindow()
|
||||
|
||||
if input.KeyClicked(sdl.K_F4) {
|
||||
fmt.Printf("Pos: %s; Forward: %s; |Forward|: %f\n", cam.Pos.String(), cam.Forward.String(), cam.Forward.Mag())
|
||||
}
|
||||
|
||||
g.Win.SDLWin.SetTitle(fmt.Sprint("nMage (", timing.GetAvgFPS(), " fps)"))
|
||||
}
|
||||
|
||||
func (g *OurGame) showDebugWindow() {
|
||||
|
||||
imgui.ShowDemoWindow()
|
||||
|
||||
imgui.Begin("Debug controls")
|
||||
|
||||
// Camera
|
||||
if imgui.DragFloat3("Cam Pos", &cam.Pos.Data) {
|
||||
updateViewMat()
|
||||
}
|
||||
@ -302,22 +367,44 @@ func (g *OurGame) Update() {
|
||||
updateViewMat()
|
||||
}
|
||||
|
||||
imgui.Spacing()
|
||||
|
||||
// Light settings
|
||||
if imgui.DragFloat3("Ambient Color", &ambientColor.Data) {
|
||||
whiteMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
containerMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
palleteMat.SetUnifVec3("ambientColor", ambientColor)
|
||||
}
|
||||
|
||||
imgui.Spacing()
|
||||
|
||||
if imgui.DragFloat("Specular Shininess", &whiteMat.Shininess) {
|
||||
whiteMat.SetUnifFloat32("material.shininess", whiteMat.Shininess)
|
||||
containerMat.SetUnifFloat32("material.shininess", whiteMat.Shininess)
|
||||
palleteMat.SetUnifFloat32("material.shininess", whiteMat.Shininess)
|
||||
}
|
||||
|
||||
imgui.Spacing()
|
||||
|
||||
// Lights
|
||||
if imgui.DragFloat3("Light Pos 1", &lightPos1.Data) {
|
||||
simpleMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
whiteMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
containerMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
palleteMat.SetUnifVec3("lightPos1", lightPos1)
|
||||
}
|
||||
|
||||
if imgui.DragFloat3("Light Color 1", &lightColor1.Data) {
|
||||
simpleMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
whiteMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
containerMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
palleteMat.SetUnifVec3("lightColor1", lightColor1)
|
||||
}
|
||||
|
||||
imgui.Spacing()
|
||||
|
||||
// Other
|
||||
imgui.Checkbox("Debug depth buffer", &debugDrawDepthBuffer)
|
||||
|
||||
imgui.End()
|
||||
|
||||
if input.KeyClicked(sdl.K_F4) {
|
||||
fmt.Printf("Pos: %s; Forward: %s; |Forward|: %f\n", cam.Pos.String(), cam.Forward.String(), cam.Forward.Mag())
|
||||
}
|
||||
|
||||
g.Win.SDLWin.SetTitle(fmt.Sprint("nMage (", timing.GetAvgFPS(), " fps)"))
|
||||
}
|
||||
|
||||
func (g *OurGame) updateCameraLookAround() {
|
||||
@ -332,12 +419,12 @@ func (g *OurGame) updateCameraLookAround() {
|
||||
|
||||
// Pitch
|
||||
pitch += float32(-mouseY) * mouseSensitivity * timing.DT()
|
||||
if pitch > 89.0 {
|
||||
pitch = 89.0
|
||||
if pitch > 1.5 {
|
||||
pitch = 1.5
|
||||
}
|
||||
|
||||
if pitch < -89.0 {
|
||||
pitch = -89.0
|
||||
if pitch < -1.5 {
|
||||
pitch = -1.5
|
||||
}
|
||||
|
||||
// Update cam forward
|
||||
@ -380,19 +467,33 @@ func (g *OurGame) updateCameraPos() {
|
||||
|
||||
func (g *OurGame) Render() {
|
||||
|
||||
matToUse := simpleMat
|
||||
tempModelMatrix := cubeModelMat.Clone()
|
||||
|
||||
whiteMat.SetUnifVec3("camPos", &cam.Pos)
|
||||
containerMat.SetUnifVec3("camPos", &cam.Pos)
|
||||
palleteMat.SetUnifVec3("camPos", &cam.Pos)
|
||||
|
||||
sunMat := palleteMat
|
||||
chairMat := palleteMat
|
||||
cubeMat := containerMat
|
||||
if debugDrawDepthBuffer {
|
||||
matToUse = debugDepthMat
|
||||
sunMat = debugDepthMat
|
||||
chairMat = debugDepthMat
|
||||
cubeMat = debugDepthMat
|
||||
}
|
||||
|
||||
tempModelMatrix := cubeModelMat.Clone()
|
||||
window.Rend.Draw(chairMesh, tempModelMatrix, matToUse)
|
||||
// Draw sun
|
||||
window.Rend.Draw(sphereMesh, gglm.NewTrMatId().Translate(lightPos1).Scale(gglm.NewVec3(0.1, 0.1, 0.1)), sunMat)
|
||||
|
||||
// Chair
|
||||
window.Rend.Draw(chairMesh, tempModelMatrix, chairMat)
|
||||
|
||||
// Cubes
|
||||
rowSize := 1
|
||||
for y := 0; y < rowSize; y++ {
|
||||
for x := 0; x < rowSize; x++ {
|
||||
tempModelMatrix.Translate(gglm.NewVec3(-6, 0, 0))
|
||||
window.Rend.Draw(cubeMesh, tempModelMatrix, matToUse)
|
||||
window.Rend.Draw(cubeMesh, tempModelMatrix, cubeMat)
|
||||
}
|
||||
tempModelMatrix.Translate(gglm.NewVec3(float32(rowSize), -1, 0))
|
||||
}
|
||||
@ -420,7 +521,6 @@ func (g *OurGame) DrawSkybox() {
|
||||
|
||||
skyboxMat.SetUnifMat4("viewMat", viewMat)
|
||||
skyboxMat.SetUnifMat4("projMat", &cam.ProjMat)
|
||||
// window.Rend.Draw(cubeMesh, gglm.NewTrMatId(), skyboxMat)
|
||||
for i := 0; i < len(skyboxMesh.SubMeshes); i++ {
|
||||
gl.DrawElementsBaseVertexWithOffset(gl.TRIANGLES, skyboxMesh.SubMeshes[i].IndexCount, gl.UNSIGNED_INT, uintptr(skyboxMesh.SubMeshes[i].BaseIndex), skyboxMesh.SubMeshes[i].BaseVertex)
|
||||
}
|
||||
@ -438,6 +538,8 @@ func (g *OurGame) DeInit() {
|
||||
|
||||
func updateViewMat() {
|
||||
cam.Update()
|
||||
simpleMat.SetUnifMat4("viewMat", &cam.ViewMat)
|
||||
whiteMat.SetUnifMat4("viewMat", &cam.ViewMat)
|
||||
containerMat.SetUnifMat4("viewMat", &cam.ViewMat)
|
||||
palleteMat.SetUnifMat4("viewMat", &cam.ViewMat)
|
||||
debugDepthMat.SetUnifMat4("viewMat", &cam.ViewMat)
|
||||
}
|
||||
|
||||
@ -12,10 +12,16 @@ type Material struct {
|
||||
Name string
|
||||
ShaderProg shaders.ShaderProgram
|
||||
|
||||
DiffuseTex uint32
|
||||
|
||||
UnifLocs map[string]int32
|
||||
AttribLocs map[string]int32
|
||||
|
||||
// Phong shading
|
||||
DiffuseTex uint32
|
||||
SpecularTex uint32
|
||||
NormalTex uint32
|
||||
EmissionTex uint32
|
||||
|
||||
Shininess float32
|
||||
}
|
||||
|
||||
func (m *Material) Bind() {
|
||||
@ -24,6 +30,15 @@ func (m *Material) Bind() {
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE0)
|
||||
gl.BindTexture(gl.TEXTURE_2D, m.DiffuseTex)
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE1)
|
||||
gl.BindTexture(gl.TEXTURE_2D, m.SpecularTex)
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE2)
|
||||
gl.BindTexture(gl.TEXTURE_2D, m.NormalTex)
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE3)
|
||||
gl.BindTexture(gl.TEXTURE_2D, m.EmissionTex)
|
||||
}
|
||||
|
||||
func (m *Material) UnBind() {
|
||||
@ -32,6 +47,15 @@ func (m *Material) UnBind() {
|
||||
//TODO: Should we unbind textures here? Are these two lines needed?
|
||||
// gl.ActiveTexture(gl.TEXTURE0)
|
||||
// gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
|
||||
// gl.ActiveTexture(gl.TEXTURE1)
|
||||
// gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
|
||||
// gl.ActiveTexture(gl.TEXTURE2)
|
||||
// gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
|
||||
// gl.ActiveTexture(gl.TEXTURE3)
|
||||
// gl.BindTexture(gl.TEXTURE_2D, 0)
|
||||
}
|
||||
|
||||
func (m *Material) GetAttribLoc(attribName string) int32 {
|
||||
|
||||
Binary file not shown.
BIN
res/models/cube.fbx
Executable file
BIN
res/models/cube.fbx
Executable file
Binary file not shown.
BIN
res/models/sphere.fbx
Executable file
BIN
res/models/sphere.fbx
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -18,7 +18,12 @@ uniform mat4 projMat;
|
||||
|
||||
void main()
|
||||
{
|
||||
// @TODO: Calculate this on the CPU and send it as a uniform
|
||||
|
||||
// This produces the normal matrix that multiplies with the model normal to produce the
|
||||
// world space normal. Based on 'One last thing' section from: https://learnopengl.com/Lighting/Basic-Lighting
|
||||
vertNormal = mat3(transpose(inverse(modelMat))) * vertNormalIn;
|
||||
|
||||
vertUV0 = vertUV0In;
|
||||
vertColor = vertColorIn;
|
||||
fragPos = vec3(modelMat * vec4(vertPosIn, 1.0));
|
||||
@ -29,14 +34,22 @@ void main()
|
||||
//shader:fragment
|
||||
#version 410
|
||||
|
||||
uniform float ambientStrength = 0;
|
||||
uniform vec3 ambientLightColor = vec3(1, 1, 1);
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
sampler2D normal;
|
||||
sampler2D emission;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
uniform Material material;
|
||||
|
||||
uniform vec3 camPos;
|
||||
uniform vec3 ambientColor = vec3(0.2, 0.2, 0.2);
|
||||
|
||||
uniform vec3 lightPos1;
|
||||
uniform vec3 lightColor1;
|
||||
|
||||
uniform sampler2D diffTex;
|
||||
|
||||
in vec3 vertColor;
|
||||
in vec3 vertNormal;
|
||||
in vec2 vertUV0;
|
||||
@ -46,10 +59,24 @@ out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightDir = normalize(lightPos1 - fragPos);
|
||||
float diffStrength = max(0.0, dot(normalize(vertNormal), lightDir));
|
||||
vec3 lightDir = normalize(lightPos1 - fragPos);
|
||||
vec4 diffuseTexColor = texture(material.diffuse, vertUV0);
|
||||
|
||||
vec3 finalAmbientColor = ambientLightColor * ambientStrength;
|
||||
vec4 texColor = texture(diffTex, vertUV0);
|
||||
fragColor = vec4(texColor.rgb * vertColor * (finalAmbientColor + diffStrength*lightColor1) , texColor.a);
|
||||
// Ambient
|
||||
vec3 finalAmbient = ambientColor * diffuseTexColor.rgb;
|
||||
|
||||
// Diffuse
|
||||
float diffuseAmount = max(0.0, dot(normalize(vertNormal), lightDir));
|
||||
vec3 finalDiffuse = diffuseAmount * lightColor1 * diffuseTexColor.rgb;
|
||||
|
||||
// Specular
|
||||
vec3 viewDir = normalize(camPos - fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, vertNormal);
|
||||
float specularAmount = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
vec3 finalSpecular = specularAmount * lightColor1 * texture(material.specular, vertUV0).rgb;
|
||||
|
||||
// Emission
|
||||
vec3 finalEmission = texture(material.emission, vertUV0).rgb;
|
||||
|
||||
fragColor = vec4(finalAmbient + finalDiffuse + finalSpecular + finalEmission, 1);
|
||||
}
|
||||
|
||||
BIN
res/textures/container-diffuse.png
Executable file
BIN
res/textures/container-diffuse.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 457 KiB |
BIN
res/textures/container-specular.png
Executable file
BIN
res/textures/container-specular.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
BIN
res/textures/white.png
Executable file
BIN
res/textures/white.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 232 B |
@ -109,6 +109,7 @@ func (i *ImguiInfo) Render(winWidth, winHeight float32, fbWidth, fbHeight int32)
|
||||
cmd.CallUserCallback(list)
|
||||
} else {
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE0)
|
||||
gl.BindTexture(gl.TEXTURE_2D, *i.TexID)
|
||||
clipRect := cmd.ClipRect()
|
||||
gl.Scissor(int32(clipRect.X), int32(fbHeight)-int32(clipRect.W), int32(clipRect.Z-clipRect.X), int32(clipRect.W-clipRect.Y))
|
||||
@ -142,6 +143,7 @@ func (i *ImguiInfo) AddFontTTF(fontPath string, fontSize float32, fontConfig *im
|
||||
f := a.AddFontFromFileTTFV(fontPath, fontSize, fontConfigToUse, glyphRangesToUse.Data())
|
||||
pixels, width, height, _ := a.GetTextureDataAsAlpha8()
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE0)
|
||||
gl.BindTexture(gl.TEXTURE_2D, *i.TexID)
|
||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(width), int32(height), 0, gl.RED, gl.UNSIGNED_BYTE, pixels)
|
||||
|
||||
@ -225,6 +227,7 @@ func NewImGui(shaderPath string) ImguiInfo {
|
||||
gl.GenTextures(1, imguiInfo.TexID)
|
||||
|
||||
// Upload font to gpu
|
||||
gl.ActiveTexture(gl.TEXTURE0)
|
||||
gl.BindTexture(gl.TEXTURE_2D, *imguiInfo.TexID)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
||||
|
||||
Reference in New Issue
Block a user