transparency.odin 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package transparency
  2. import rl "vendor:raylib"
  3. import r3d "../r3d"
  4. main :: proc() {
  5. // Initialize window
  6. rl.InitWindow(800, 450, "[r3d] - Transparency example")
  7. defer rl.CloseWindow()
  8. rl.SetTargetFPS(60)
  9. // Initialize R3D
  10. r3d.Init(rl.GetScreenWidth(), rl.GetScreenHeight())
  11. defer r3d.Close()
  12. // Create cube model
  13. cube := r3d.GenMeshCube(1, 1, 1)
  14. defer r3d.UnloadMesh(cube)
  15. matCube := r3d.GetDefaultMaterial()
  16. matCube.transparencyMode = .ALPHA
  17. matCube.albedo.color = {150, 150, 255, 100}
  18. matCube.orm.occlusion = 1.0
  19. matCube.orm.roughness = 0.2
  20. matCube.orm.metalness = 0.2
  21. // Create plane model
  22. plane := r3d.GenMeshPlane(1000, 1000, 1, 1)
  23. defer r3d.UnloadMesh(plane)
  24. matPlane := r3d.GetDefaultMaterial()
  25. matPlane.orm.occlusion = 1.0
  26. matPlane.orm.roughness = 1.0
  27. matPlane.orm.metalness = 0.0
  28. // Create sphere model
  29. sphere := r3d.GenMeshSphere(0.5, 64, 64)
  30. defer r3d.UnloadMesh(sphere)
  31. matSphere := r3d.GetDefaultMaterial()
  32. matSphere.orm.occlusion = 1.0
  33. matSphere.orm.roughness = 0.25
  34. matSphere.orm.metalness = 0.75
  35. // Setup camera
  36. camera: rl.Camera3D = {
  37. position = {0, 2, 2},
  38. target = {0, 0, 0},
  39. up = {0, 1, 0},
  40. fovy = 60,
  41. }
  42. // Setup lighting
  43. env := r3d.GetEnvironment()
  44. env.ambient.color = {10, 10, 10, 255}
  45. light := r3d.CreateLight(.SPOT)
  46. r3d.LightLookAt(light, {0, 10, 5}, {0, 0, 0})
  47. r3d.SetLightActive(light, true)
  48. r3d.EnableShadow(light)
  49. // Main loop
  50. for !rl.WindowShouldClose()
  51. {
  52. rl.UpdateCamera(&camera, rl.CameraMode.ORBITAL)
  53. rl.BeginDrawing()
  54. rl.ClearBackground(rl.RAYWHITE)
  55. r3d.Begin(camera)
  56. r3d.DrawMesh(plane, matPlane, {0, -0.5, 0}, 1.0)
  57. r3d.DrawMesh(sphere, matSphere, {0, 0, 0}, 1.0)
  58. r3d.DrawMesh(cube, matCube, {0, 0, 0}, 1.0)
  59. r3d.End()
  60. rl.EndDrawing()
  61. }
  62. }