transparency.c 2.2 KB

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