updated light.go added basic lighting example
This commit is contained in:
parent
d97aa6e3f6
commit
d3497d36da
5 changed files with 295 additions and 18 deletions
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
@ -22,7 +21,6 @@ type Light struct {
|
|||
target rl.Vector3
|
||||
color rl.Color
|
||||
enabled int32
|
||||
|
||||
// shader locations
|
||||
enabledLoc int32
|
||||
typeLoc int32
|
||||
|
@ -40,46 +38,32 @@ func NewLight(
|
|||
position, target rl.Vector3,
|
||||
color rl.Color,
|
||||
shader rl.Shader) Light {
|
||||
|
||||
light := Light{
|
||||
shader: shader,
|
||||
}
|
||||
|
||||
if lightCount < maxLightsCount {
|
||||
light.enabled = 1
|
||||
light.lightType = lightType
|
||||
light.position = position
|
||||
light.target = target
|
||||
light.color = color
|
||||
|
||||
light.enabledLoc = rl.GetShaderLocation(shader, fmt.Sprintf("lights[%d].enabled", lightCount))
|
||||
light.typeLoc = rl.GetShaderLocation(shader, fmt.Sprintf("lights[%d].type", lightCount))
|
||||
light.posLoc = rl.GetShaderLocation(shader, fmt.Sprintf("lights[%d].position", lightCount))
|
||||
light.targetLoc = rl.GetShaderLocation(shader, fmt.Sprintf("lights[%d].target", lightCount))
|
||||
light.colorLoc = rl.GetShaderLocation(shader, fmt.Sprintf("lights[%d].color", lightCount))
|
||||
light.UpdateValues()
|
||||
|
||||
lightCount++
|
||||
}
|
||||
|
||||
return light
|
||||
}
|
||||
|
||||
// Send light properties to shader
|
||||
func (lt *Light) UpdateValues() {
|
||||
// not pretty -_-
|
||||
// need nicer api
|
||||
sh := &reflect.SliceHeader{
|
||||
Len: 4,
|
||||
Cap: 4,
|
||||
}
|
||||
|
||||
// Send to shader light enabled state and type
|
||||
sh.Data = uintptr(unsafe.Pointer(<.enabled))
|
||||
rl.SetShaderValue(lt.shader, lt.enabledLoc, *(*[]float32)(unsafe.Pointer(sh)), rl.ShaderUniformInt)
|
||||
rl.SetShaderValue(lt.shader, lt.enabledLoc, unsafe.Slice((*float32)(unsafe.Pointer(<.enabled)), 4), rl.ShaderUniformInt)
|
||||
rl.SetShaderValue(lt.shader, lt.typeLoc, unsafe.Slice((*float32)(unsafe.Pointer(<.lightType)), 4), rl.ShaderUniformInt)
|
||||
|
||||
// Send to shader light position values
|
||||
sh.Data = uintptr(unsafe.Pointer(<.lightType))
|
||||
rl.SetShaderValue(lt.shader, lt.posLoc, []float32{lt.position.X, lt.position.Y, lt.position.Z}, rl.ShaderUniformVec3)
|
||||
|
||||
// Send to shader light target target values
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue