pbr.odin 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package pbr
  2. import rl "vendor:raylib"
  3. import r3d "../r3d"
  4. main :: proc() {
  5. // Initialize window
  6. rl.InitWindow(800, 450, "[r3d] - PBR example")
  7. defer rl.CloseWindow()
  8. rl.SetTargetFPS(60)
  9. // Initialize R3D
  10. r3d.Init(rl.GetScreenWidth(), rl.GetScreenHeight())
  11. defer r3d.Close()
  12. r3d.SetAntiAliasing(.FXAA)
  13. // Setup environment sky
  14. cubemap := r3d.LoadCubemap("./resources/panorama/indoor.png", .AUTO_DETECT)
  15. defer r3d.UnloadCubemap(cubemap)
  16. env := r3d.GetEnvironment()
  17. env.background.skyBlur = 0.775
  18. env.background.sky = cubemap
  19. // Setup environment ambient
  20. ambientMap := r3d.GenAmbientMap(cubemap, {.ILLUMINATION, .REFLECTION})
  21. defer r3d.UnloadAmbientMap(ambientMap)
  22. env.ambient._map = ambientMap
  23. // Setup bloom
  24. env.bloom.mode = .MIX
  25. env.bloom.intensity = 0.02
  26. // Setup tonemapping
  27. env.tonemap.mode = .FILMIC
  28. env.tonemap.exposure = 1.0
  29. env.tonemap.white = 4.0
  30. // Load model
  31. r3d.SetTextureFilter(.ANISOTROPIC_4X)
  32. model := r3d.LoadModel("./resources/models/DamagedHelmet.glb")
  33. defer r3d.UnloadModel(model, true)
  34. modelMatrix := rl.Matrix(1)
  35. modelScale: f32 = 1.0
  36. // Setup camera
  37. camera: rl.Camera3D = {
  38. position = {0, 0, 2.5},
  39. target = {0, 0, 0},
  40. up = {0, 1, 0},
  41. fovy = 60,
  42. }
  43. // Main loop
  44. for !rl.WindowShouldClose()
  45. {
  46. // Update model scale with mouse wheel
  47. modelScale = clamp(modelScale + rl.GetMouseWheelMove() * 0.1, 0.25, 2.5)
  48. // Rotate model with left mouse button
  49. if rl.IsMouseButtonDown(.LEFT) {
  50. mouseDelta := rl.GetMouseDelta()
  51. pitch := (mouseDelta.y * 0.005) / modelScale
  52. yaw := (mouseDelta.x * 0.005) / modelScale
  53. rotate := rl.MatrixRotateXYZ({pitch, yaw, 0.0})
  54. modelMatrix = rotate * modelMatrix
  55. }
  56. rl.BeginDrawing()
  57. rl.ClearBackground(rl.RAYWHITE)
  58. r3d.Begin(camera)
  59. scale := rl.MatrixScale(modelScale, modelScale, modelScale)
  60. transform := scale * modelMatrix
  61. r3d.DrawModelPro(model, transform)
  62. r3d.End()
  63. rl.EndDrawing()
  64. }
  65. }