transparency.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "./common.h"
  2. /* === Resources === */
  3. static R3D_Model cube = { 0 };
  4. static R3D_Model plane = { 0 };
  5. static R3D_Model sphere = { 0 };
  6. static Camera3D camera = { 0 };
  7. /* === Example === */
  8. const char* Init(void)
  9. {
  10. /* --- Initialize R3D with its internal resolution --- */
  11. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  12. SetTargetFPS(60);
  13. /* --- Load cube model --- */
  14. R3D_Mesh mesh = { 0 };
  15. mesh = R3D_GenMeshCube(1, 1, 1);
  16. cube = R3D_LoadModelFromMesh(&mesh);
  17. cube.meshes[0].shadowCastMode = R3D_SHADOW_CAST_DISABLED;
  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. /* --- Load plane model --- */
  24. mesh = R3D_GenMeshPlane(1000, 1000, 1, 1);
  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);
  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_SetAmbientColor((Color) { 10, 10, 10, 255 });
  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. }