fog.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "./common.h"
  2. /* === Resources === */
  3. static Model sponza = { 0 };
  4. static Camera3D camera = { 0 };
  5. /* === Examples === */
  6. const char* Init(void)
  7. {
  8. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  9. SetTargetFPS(60);
  10. sponza = RES_LoadModel("sponza.glb");
  11. for (int i = 0; i < sponza.materialCount; i++) {
  12. sponza.materials[i].maps[MATERIAL_MAP_ALBEDO].color = WHITE;
  13. sponza.materials[i].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
  14. sponza.materials[i].maps[MATERIAL_MAP_ROUGHNESS].value = 1.0f;
  15. sponza.materials[i].maps[MATERIAL_MAP_METALNESS].value = 1.0f;
  16. }
  17. R3D_SetFogMode(R3D_FOG_EXP);
  18. R3D_Light light = R3D_CreateLight(R3D_LIGHT_DIR);
  19. R3D_SetLightDirection(light, (Vector3) { 0, -1, 0 });
  20. R3D_SetLightActive(light, true);
  21. camera = (Camera3D){
  22. .position = (Vector3) { 0, 0, 0 },
  23. .target = (Vector3) { 0, 0, -1 },
  24. .up = (Vector3) { 0, 1, 0 },
  25. .fovy = 60,
  26. };
  27. DisableCursor();
  28. return "[r3d] - fog example";
  29. }
  30. void Update(float delta)
  31. {
  32. UpdateCamera(&camera, CAMERA_FREE);
  33. }
  34. void Draw(void)
  35. {
  36. R3D_Begin(camera);
  37. R3D_DrawModel(sponza, (Vector3) { 0 }, 1.0f);
  38. R3D_End();
  39. DrawFPS(10, 10);
  40. }
  41. void Close(void)
  42. {
  43. UnloadModel(sponza);
  44. R3D_Close();
  45. }