Improve headlights, fix z fighting
This commit is contained in:
parent
786d18cd75
commit
1c3810483a
BIN
assets/ae86_lights.glb
(Stored with Git LFS)
BIN
assets/ae86_lights.glb
(Stored with Git LFS)
Binary file not shown.
@ -18,5 +18,5 @@ out vec4 finalColor;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
finalColor = colDiffuse*fragColor;
|
finalColor = vec4(colDiffuse.rgb, colDiffuse.a * fragColor.x);
|
||||||
}
|
}
|
||||||
|
@ -822,7 +822,11 @@ draw :: proc() {
|
|||||||
|
|
||||||
render.draw_model(car_model, basic_shader.shader, car_matrix)
|
render.draw_model(car_model, basic_shader.shader, car_matrix)
|
||||||
|
|
||||||
render.draw_mesh_light(assets.get_model(&g_mem.assetman, "assets/ae86_lights.glb"), car_matrix, rl.Color{255, 255, 255, 100})
|
render.draw_mesh_light(
|
||||||
|
assets.get_model(&g_mem.assetman, "assets/ae86_lights.glb"),
|
||||||
|
car_matrix,
|
||||||
|
rl.Color{255, 255, 255, 100},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -984,11 +988,7 @@ draw :: proc() {
|
|||||||
|
|
||||||
new_point_pos := points[0] - tangent * 4
|
new_point_pos := points[0] - tangent * 4
|
||||||
|
|
||||||
if (spline_handle(
|
if (spline_handle(new_point_pos, camera, false)) {
|
||||||
new_point_pos,
|
|
||||||
camera,
|
|
||||||
false,
|
|
||||||
)) {
|
|
||||||
inject_at(&world.track.points, 0, new_point_pos)
|
inject_at(&world.track.points, 0, new_point_pos)
|
||||||
log.debugf("add point before 0")
|
log.debugf("add point before 0")
|
||||||
}
|
}
|
||||||
@ -1006,11 +1006,7 @@ draw :: proc() {
|
|||||||
|
|
||||||
new_point_pos := points[points_len - 1] + tangent * 4
|
new_point_pos := points[points_len - 1] + tangent * 4
|
||||||
|
|
||||||
if (spline_handle(
|
if (spline_handle(new_point_pos, camera, false)) {
|
||||||
new_point_pos,
|
|
||||||
camera,
|
|
||||||
false,
|
|
||||||
)) {
|
|
||||||
inject_at(&world.track.points, points_len - 1 + 1, new_point_pos)
|
inject_at(&world.track.points, points_len - 1 + 1, new_point_pos)
|
||||||
log.debugf("add point before 0")
|
log.debugf("add point before 0")
|
||||||
}
|
}
|
||||||
@ -1111,8 +1107,6 @@ game_init_window :: proc(args: []string) {
|
|||||||
|
|
||||||
init_physfs(args)
|
init_physfs(args)
|
||||||
|
|
||||||
render.init()
|
|
||||||
|
|
||||||
rl.SetConfigFlags({.WINDOW_RESIZABLE, .VSYNC_HINT})
|
rl.SetConfigFlags({.WINDOW_RESIZABLE, .VSYNC_HINT})
|
||||||
rl.InitWindow(1280, 720, "Odin + Raylib + Hot Reload template!")
|
rl.InitWindow(1280, 720, "Odin + Raylib + Hot Reload template!")
|
||||||
rl.SetExitKey(.KEY_NULL)
|
rl.SetExitKey(.KEY_NULL)
|
||||||
@ -1172,7 +1166,7 @@ game_memory_size :: proc() -> int {
|
|||||||
game_hot_reloaded :: proc(mem: rawptr) {
|
game_hot_reloaded :: proc(mem: rawptr) {
|
||||||
g_mem = (^Game_Memory)(mem)
|
g_mem = (^Game_Memory)(mem)
|
||||||
|
|
||||||
render.init()
|
render.init(&g_mem.assetman)
|
||||||
|
|
||||||
g_mem.runtime_world.orbit_camera.distance = 4
|
g_mem.runtime_world.orbit_camera.distance = 4
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,49 @@
|
|||||||
package render
|
package render
|
||||||
|
|
||||||
|
import "game:assets"
|
||||||
import rl "libs:raylib"
|
import rl "libs:raylib"
|
||||||
import rlgl "libs:raylib/rlgl"
|
import rlgl "libs:raylib/rlgl"
|
||||||
import gl "vendor:OpenGL"
|
import gl "vendor:OpenGL"
|
||||||
|
|
||||||
|
@(private = "file")
|
||||||
|
assetman: ^assets.Asset_Manager
|
||||||
|
|
||||||
// Used by vendor:OpenGL
|
// Used by vendor:OpenGL
|
||||||
rlgl_set_proc_address :: proc(p: rawptr, name: cstring) {
|
rlgl_set_proc_address :: proc(p: rawptr, name: cstring) {
|
||||||
(^rawptr)(p)^ = rl.GetGLProcAddress(name)
|
(^rawptr)(p)^ = rl.GetGLProcAddress(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
init :: proc() {
|
init :: proc(in_assetman: ^assets.Asset_Manager) {
|
||||||
|
assetman = in_assetman
|
||||||
gl.load_up_to(3, 3, rlgl_set_proc_address)
|
gl.load_up_to(3, 3, rlgl_set_proc_address)
|
||||||
|
rlgl.SetClipPlanes(0.1, 10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_stencil :: proc() {
|
clear_stencil :: proc() {
|
||||||
gl.Clear(gl.STENCIL_BUFFER_BIT)
|
gl.Clear(gl.STENCIL_BUFFER_BIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_model :: proc(model: rl.Model, shader: rl.Shader, transform: rl.Matrix) {
|
draw_model :: proc(
|
||||||
|
model: rl.Model,
|
||||||
|
shader: rl.Shader,
|
||||||
|
transform: rl.Matrix,
|
||||||
|
color: rl.Color = rl.WHITE,
|
||||||
|
) {
|
||||||
model := model
|
model := model
|
||||||
for i in 0 ..< model.materialCount {
|
for i in 0 ..< model.materialCount {
|
||||||
model.materials[i].shader = shader
|
model.materials[i].shader = shader
|
||||||
}
|
}
|
||||||
model.transform = transform
|
model.transform = transform
|
||||||
|
|
||||||
rl.DrawModel(model, rl.Vector3{}, 1, rl.WHITE)
|
rl.DrawModel(model, rl.Vector3{}, 1, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_mesh_light :: proc(model: rl.Model, transform: rl.Matrix, color: rl.Color) {
|
draw_mesh_light :: proc(model: rl.Model, transform: rl.Matrix, color: rl.Color) {
|
||||||
model := model
|
model := model
|
||||||
model.transform = transform
|
model.transform = transform
|
||||||
|
|
||||||
|
light_shader := assets.get_shader(assetman, nil, "assets/shaders/light_ps.glsl", {}).shader
|
||||||
|
|
||||||
rlgl.DrawRenderBatchActive()
|
rlgl.DrawRenderBatchActive()
|
||||||
|
|
||||||
gl.Enable(gl.STENCIL_TEST)
|
gl.Enable(gl.STENCIL_TEST)
|
||||||
@ -43,30 +56,34 @@ draw_mesh_light :: proc(model: rl.Model, transform: rl.Matrix, color: rl.Color)
|
|||||||
gl.ColorMask(false, false, false, false)
|
gl.ColorMask(false, false, false, false)
|
||||||
rlgl.SetCullFace(.FRONT)
|
rlgl.SetCullFace(.FRONT)
|
||||||
|
|
||||||
rl.DrawModel(model, {}, 1, color)
|
draw_model(model, light_shader, transform, color)
|
||||||
rlgl.DrawRenderBatchActive()
|
rlgl.DrawRenderBatchActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw outside light
|
||||||
{
|
{
|
||||||
gl.StencilFunc(gl.EQUAL, 1, ~u32(0))
|
gl.StencilFunc(gl.EQUAL, 1, ~u32(0))
|
||||||
gl.StencilOp(gl.ZERO, gl.ZERO, gl.ZERO)
|
gl.StencilOp(gl.KEEP, gl.ZERO, gl.ZERO)
|
||||||
gl.DepthFunc(gl.LEQUAL)
|
gl.DepthFunc(gl.LEQUAL)
|
||||||
gl.ColorMask(true, true, true, true)
|
gl.ColorMask(true, true, true, true)
|
||||||
rlgl.SetCullFace(.BACK)
|
rlgl.SetCullFace(.BACK)
|
||||||
|
|
||||||
rl.DrawModel(model, {}, 1, color)
|
draw_model(model, light_shader, transform, color)
|
||||||
rlgl.DrawRenderBatchActive()
|
rlgl.DrawRenderBatchActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// Light when camera is inside
|
||||||
|
if true {
|
||||||
gl.StencilOp(gl.KEEP, gl.KEEP, gl.ZERO)
|
gl.StencilOp(gl.KEEP, gl.KEEP, gl.ZERO)
|
||||||
gl.DepthFunc(gl.GREATER)
|
gl.DepthFunc(gl.GREATER)
|
||||||
rlgl.SetCullFace(.FRONT)
|
rlgl.SetCullFace(.FRONT)
|
||||||
|
|
||||||
rl.DrawModel(model, {}, 1, color)
|
draw_model(model, light_shader, transform, color)
|
||||||
rlgl.DrawRenderBatchActive()
|
rlgl.DrawRenderBatchActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gl.Clear(gl.STENCIL_BUFFER_BIT)
|
||||||
|
|
||||||
gl.StencilFunc(gl.ALWAYS, 0, ~u32(0))
|
gl.StencilFunc(gl.ALWAYS, 0, ~u32(0))
|
||||||
gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
|
gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
|
||||||
rlgl.SetCullFace(.BACK)
|
rlgl.SetCullFace(.BACK)
|
||||||
|
@ -125,8 +125,7 @@ when ODIN_OS == .Windows {
|
|||||||
} else when ODIN_OS == .Linux {
|
} else when ODIN_OS == .Linux {
|
||||||
foreign import lib {// Note(bumbread): I'm not sure why in `linux/` folder there are
|
foreign import lib {// Note(bumbread): I'm not sure why in `linux/` folder there are
|
||||||
// multiple copies of raylib.so, but since these bindings are for
|
// multiple copies of raylib.so, but since these bindings are for
|
||||||
// particular version of the library, I better specify it. Ideally,
|
"../src/libraylib.so.550" when RAYLIB_SHARED else "../src/libraylib.a", "system:dl", "system:pthread"} // particular version of the library, I better specify it. Ideally,// though, it's best specified in terms of major (.so.4)
|
||||||
"../src/libraylib.so.550" when RAYLIB_SHARED else "../src/libraylib.a", "system:dl", "system:pthread"}// though, it's best specified in terms of major (.so.4)
|
|
||||||
} else when ODIN_OS == .Darwin {
|
} else when ODIN_OS == .Darwin {
|
||||||
foreign import lib {"../macos" + ("-arm64" when ODIN_ARCH ==
|
foreign import lib {"../macos" + ("-arm64" when ODIN_ARCH ==
|
||||||
.arm64 else "") + "/libraylib" + (".500.dylib" when RAYLIB_SHARED else ".a"), "system:Cocoa.framework", "system:OpenGL.framework", "system:IOKit.framework"}
|
.arm64 else "") + "/libraylib" + (".500.dylib" when RAYLIB_SHARED else ".a"), "system:Cocoa.framework", "system:OpenGL.framework", "system:IOKit.framework"}
|
||||||
@ -364,6 +363,7 @@ foreign lib {
|
|||||||
Frustum :: proc(left, right, bottom, top, znear, zfar: f64) ---
|
Frustum :: proc(left, right, bottom, top, znear, zfar: f64) ---
|
||||||
Ortho :: proc(left, right, bottom, top, znear, zfar: f64) ---
|
Ortho :: proc(left, right, bottom, top, znear, zfar: f64) ---
|
||||||
Viewport :: proc(x, y, width, height: c.int) --- // Set the viewport area
|
Viewport :: proc(x, y, width, height: c.int) --- // Set the viewport area
|
||||||
|
SetClipPlanes :: proc(nearPlane, farPlane: f64) --- // Set clip planes
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Functions Declaration - Vertex level operations
|
// Functions Declaration - Vertex level operations
|
||||||
|
BIN
src_assets/ae86.blend
(Stored with Git LFS)
BIN
src_assets/ae86.blend
(Stored with Git LFS)
Binary file not shown.
BIN
src_assets/ae86.blend1
(Stored with Git LFS)
BIN
src_assets/ae86.blend1
(Stored with Git LFS)
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user