emission.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "./common.h"
  2. #include "r3d.h"
  3. #include <raylib.h>
  4. #include <raymath.h>
  5. /* === Resources === */
  6. static R3D_Model model = { 0 };
  7. static R3D_Mesh plane = { 0 };
  8. static R3D_Material material = { 0 };
  9. static Camera3D camera = { 0 };
  10. static R3D_Light light = { 0 };
  11. static float rotModel = 0.0f;
  12. /* === Toggle Light === */
  13. void ToggleLight(void)
  14. {
  15. if (R3D_IsLightActive(light)) {
  16. R3D_SetLightActive(light, false);
  17. R3D_SetAmbientColor(BLACK);
  18. }
  19. else {
  20. R3D_SetLightActive(light, true);
  21. R3D_SetAmbientColor(DARKGRAY);
  22. }
  23. }
  24. /* === Example === */
  25. const char* Init(void)
  26. {
  27. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  28. SetTargetFPS(60);
  29. R3D_SetBackgroundColor(BLACK);
  30. R3D_SetAmbientColor(DARKGRAY);
  31. R3D_SetTonemapMode(R3D_TONEMAP_ACES);
  32. R3D_SetTonemapExposure(0.8f);
  33. R3D_SetTonemapWhite(2.5f);
  34. R3D_SetBloomMode(R3D_BLOOM_ADDITIVE);
  35. R3D_SetBloomSoftThreshold(0.2f);
  36. R3D_SetBloomIntensity(0.2f);
  37. R3D_SetBloomThreshold(0.6f);
  38. model = R3D_LoadModel(RESOURCES_PATH "emission.glb");
  39. plane = R3D_GenMeshPlane(1000, 1000, 1, 1, true);
  40. material = R3D_GetDefaultMaterial();
  41. camera = (Camera3D) {
  42. .position = (Vector3) { -1.0f, 1.75f, 1.75f },
  43. .target = (Vector3) { 0, 0.5f, 0 },
  44. .up = (Vector3) { 0, 1, 0 },
  45. .fovy = 60,
  46. };
  47. light = R3D_CreateLight(R3D_LIGHT_SPOT);
  48. {
  49. R3D_LightLookAt(light, (Vector3) { 0, 10, 5 }, (Vector3) { 0 });
  50. R3D_SetLightOuterCutOff(light, 45.0f);
  51. R3D_SetLightInnerCutOff(light, 22.5f);
  52. R3D_EnableShadow(light, 4096);
  53. R3D_SetLightActive(light, true);
  54. }
  55. return "[r3d] - Emission example";
  56. }
  57. void Update(float delta)
  58. {
  59. if (IsKeyPressed(KEY_SPACE)) {
  60. ToggleLight();
  61. }
  62. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
  63. camera.position.y = Clamp(camera.position.y + 0.01f * GetMouseDelta().y, 0.25f, 2.5f);
  64. rotModel += GetMouseDelta().x;
  65. }
  66. }
  67. void Draw(void)
  68. {
  69. R3D_Begin(camera);
  70. R3D_DrawMesh(&plane, &material, MatrixIdentity());
  71. R3D_DrawModelEx(&model, (Vector3) { 0 }, (Vector3) { 0, 1, 0 }, rotModel, (Vector3) { 10.0f, 10.0f, 10.0f });
  72. R3D_End();
  73. DrawText("Press SPACE to toggle the light", 10, 10, 20, LIME);
  74. DrawCredits("Model by har15204405");
  75. }
  76. void Close(void)
  77. {
  78. R3D_UnloadModel(&model, true);
  79. R3D_UnloadMesh(&plane);
  80. R3D_Close();
  81. }