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()
|
||||
{
|
||||
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_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
|
||||
|
||||
if (spline_handle(
|
||||
new_point_pos,
|
||||
camera,
|
||||
false,
|
||||
)) {
|
||||
if (spline_handle(new_point_pos, camera, false)) {
|
||||
inject_at(&world.track.points, 0, new_point_pos)
|
||||
log.debugf("add point before 0")
|
||||
}
|
||||
@ -1006,11 +1006,7 @@ draw :: proc() {
|
||||
|
||||
new_point_pos := points[points_len - 1] + tangent * 4
|
||||
|
||||
if (spline_handle(
|
||||
new_point_pos,
|
||||
camera,
|
||||
false,
|
||||
)) {
|
||||
if (spline_handle(new_point_pos, camera, false)) {
|
||||
inject_at(&world.track.points, points_len - 1 + 1, new_point_pos)
|
||||
log.debugf("add point before 0")
|
||||
}
|
||||
@ -1111,8 +1107,6 @@ game_init_window :: proc(args: []string) {
|
||||
|
||||
init_physfs(args)
|
||||
|
||||
render.init()
|
||||
|
||||
rl.SetConfigFlags({.WINDOW_RESIZABLE, .VSYNC_HINT})
|
||||
rl.InitWindow(1280, 720, "Odin + Raylib + Hot Reload template!")
|
||||
rl.SetExitKey(.KEY_NULL)
|
||||
@ -1172,7 +1166,7 @@ game_memory_size :: proc() -> int {
|
||||
game_hot_reloaded :: proc(mem: rawptr) {
|
||||
g_mem = (^Game_Memory)(mem)
|
||||
|
||||
render.init()
|
||||
render.init(&g_mem.assetman)
|
||||
|
||||
g_mem.runtime_world.orbit_camera.distance = 4
|
||||
}
|
||||
|
@ -1,36 +1,49 @@
|
||||
package render
|
||||
|
||||
import "game:assets"
|
||||
import rl "libs:raylib"
|
||||
import rlgl "libs:raylib/rlgl"
|
||||
import gl "vendor:OpenGL"
|
||||
|
||||
@(private = "file")
|
||||
assetman: ^assets.Asset_Manager
|
||||
|
||||
// Used by vendor:OpenGL
|
||||
rlgl_set_proc_address :: proc(p: rawptr, name: cstring) {
|
||||
(^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)
|
||||
rlgl.SetClipPlanes(0.1, 10000)
|
||||
}
|
||||
|
||||
clear_stencil :: proc() {
|
||||
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
|
||||
for i in 0 ..< model.materialCount {
|
||||
model.materials[i].shader = shader
|
||||
}
|
||||
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) {
|
||||
model := model
|
||||
model.transform = transform
|
||||
|
||||
light_shader := assets.get_shader(assetman, nil, "assets/shaders/light_ps.glsl", {}).shader
|
||||
|
||||
rlgl.DrawRenderBatchActive()
|
||||
|
||||
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)
|
||||
rlgl.SetCullFace(.FRONT)
|
||||
|
||||
rl.DrawModel(model, {}, 1, color)
|
||||
draw_model(model, light_shader, transform, color)
|
||||
rlgl.DrawRenderBatchActive()
|
||||
}
|
||||
|
||||
// Draw outside light
|
||||
{
|
||||
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.ColorMask(true, true, true, true)
|
||||
rlgl.SetCullFace(.BACK)
|
||||
|
||||
rl.DrawModel(model, {}, 1, color)
|
||||
draw_model(model, light_shader, transform, color)
|
||||
rlgl.DrawRenderBatchActive()
|
||||
}
|
||||
|
||||
{
|
||||
// Light when camera is inside
|
||||
if true {
|
||||
gl.StencilOp(gl.KEEP, gl.KEEP, gl.ZERO)
|
||||
gl.DepthFunc(gl.GREATER)
|
||||
rlgl.SetCullFace(.FRONT)
|
||||
|
||||
rl.DrawModel(model, {}, 1, color)
|
||||
draw_model(model, light_shader, transform, color)
|
||||
rlgl.DrawRenderBatchActive()
|
||||
}
|
||||
|
||||
gl.Clear(gl.STENCIL_BUFFER_BIT)
|
||||
|
||||
gl.StencilFunc(gl.ALWAYS, 0, ~u32(0))
|
||||
gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
|
||||
rlgl.SetCullFace(.BACK)
|
||||
|
@ -125,8 +125,7 @@ when ODIN_OS == .Windows {
|
||||
} else when ODIN_OS == .Linux {
|
||||
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
|
||||
// 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"}// 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"} // particular version of the library, I better specify it. Ideally,// though, it's best specified in terms of major (.so.4)
|
||||
} else when ODIN_OS == .Darwin {
|
||||
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"}
|
||||
@ -364,6 +363,7 @@ foreign lib {
|
||||
Frustum :: 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
|
||||
SetClipPlanes :: proc(nearPlane, farPlane: f64) --- // Set clip planes
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// 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