transparency.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "./common.h"
  2. #include "r3d.h"
  3. /* === Resources === */
  4. static R3D_Model cube = { 0 };
  5. static R3D_Model plane = { 0 };
  6. static R3D_Model sphere = { 0 };
  7. static Camera3D camera = { 0 };
  8. /* === Example === */
  9. const char* Init(void)
  10. {
  11. /* --- Initialize R3D with its internal resolution --- */
  12. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  13. SetTargetFPS(60);
  14. /* --- Load cube model --- */
  15. R3D_Mesh mesh = { 0 };
  16. mesh = R3D_GenMeshCube(1, 1, 1, true);
  17. cube = R3D_LoadModelFromMesh(&mesh);
  18. cube.materials[0].albedo.color = (Color){ 100, 100, 255, 100 };
  19. cube.materials[0].orm.occlusion = 1.0f;
  20. cube.materials[0].orm.roughness = 0.2f;
  21. cube.materials[0].orm.metalness = 0.2f;
  22. cube.materials[0].blendMode = R3D_BLEND_ALPHA;
  23. cube.materials[0].shadowCastMode = R3D_SHADOW_CAST_DISABLED;
  24. /* --- Load plane model --- */
  25. mesh = R3D_GenMeshPlane(1000, 1000, 1, 1, true);
  26. plane = R3D_LoadModelFromMesh(&mesh);
  27. plane.materials[0].orm.occlusion = 1.0f;
  28. plane.materials[0].orm.roughness = 1.0f;
  29. plane.materials[0].orm.metalness = 0.0f;
  30. /* --- Load sphere model --- */
  31. mesh = R3D_GenMeshSphere(0.5f, 64, 64, true);
  32. sphere = R3D_LoadModelFromMesh(&mesh);
  33. sphere.materials[0].orm.occlusion = 1.0f;
  34. sphere.materials[0].orm.roughness = 0.25f;
  35. sphere.materials[0].orm.metalness = 0.75f;
  36. /* --- Configure the camera --- */
  37. camera = (Camera3D){
  38. .position = (Vector3) { 0, 2, 2 },
  39. .target = (Vector3) { 0, 0, 0 },
  40. .up = (Vector3) { 0, 1, 0 },
  41. .fovy = 60,
  42. };
  43. /* --- Configure lighting --- */
  44. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  45. {
  46. R3D_LightLookAt(light, (Vector3) { 0, 10, 5 }, (Vector3) { 0 });
  47. R3D_SetLightActive(light, true);
  48. R3D_EnableShadow(light, 4096);
  49. }
  50. return "[r3d] - Transparency example";
  51. }
  52. void Update(float delta)
  53. {
  54. UpdateCamera(&camera, CAMERA_ORBITAL);
  55. }
  56. void Draw(void)
  57. {
  58. R3D_Begin(camera);
  59. {
  60. R3D_DrawModel(&plane, (Vector3) { 0, -0.5f, 0 }, 1.0f);
  61. R3D_DrawModel(&sphere, (Vector3) { 0 }, 1.0f);
  62. R3D_DrawModel(&cube, (Vector3) { 0 }, 1.0f);
  63. }
  64. R3D_End();
  65. }
  66. void Close(void)
  67. {
  68. R3D_UnloadModel(&plane, false);
  69. R3D_UnloadModel(&sphere, false);
  70. R3D_Close();
  71. }