transparency.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <r3d/r3d.h>
  2. int main(void)
  3. {
  4. // Initialize window
  5. InitWindow(800, 450, "[r3d] - Transparency example");
  6. SetTargetFPS(60);
  7. // Initialize R3D
  8. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  9. // Create cube model
  10. R3D_Mesh mesh = R3D_GenMeshCube(1, 1, 1);
  11. R3D_Model cube = R3D_LoadModelFromMesh(&mesh);
  12. cube.materials[0].transparencyMode = R3D_TRANSPARENCY_ALPHA;
  13. cube.materials[0].albedo.color = (Color){100, 100, 255, 100};
  14. cube.materials[0].orm.occlusion = 1.0f;
  15. cube.materials[0].orm.roughness = 0.2f;
  16. cube.materials[0].orm.metalness = 0.2f;
  17. // Create plane model
  18. mesh = R3D_GenMeshPlane(1000, 1000, 1, 1);
  19. R3D_Model plane = R3D_LoadModelFromMesh(&mesh);
  20. plane.materials[0].orm.occlusion = 1.0f;
  21. plane.materials[0].orm.roughness = 1.0f;
  22. plane.materials[0].orm.metalness = 0.0f;
  23. // Create sphere model
  24. mesh = R3D_GenMeshSphere(0.5f, 64, 64);
  25. R3D_Model sphere = R3D_LoadModelFromMesh(&mesh);
  26. sphere.materials[0].orm.occlusion = 1.0f;
  27. sphere.materials[0].orm.roughness = 0.25f;
  28. sphere.materials[0].orm.metalness = 0.75f;
  29. // Setup camera
  30. Camera3D camera = {
  31. .position = {0, 2, 2},
  32. .target = {0, 0, 0},
  33. .up = {0, 1, 0},
  34. .fovy = 60
  35. };
  36. // Setup lighting
  37. R3D_ENVIRONMENT_SET(ambient.color, (Color){10, 10, 10, 255});
  38. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  39. R3D_LightLookAt(light, (Vector3){0, 10, 5}, (Vector3){0});
  40. R3D_SetLightActive(light, true);
  41. R3D_EnableShadow(light, 4096);
  42. // Main loop
  43. while (!WindowShouldClose())
  44. {
  45. UpdateCamera(&camera, CAMERA_ORBITAL);
  46. BeginDrawing();
  47. ClearBackground(RAYWHITE);
  48. R3D_Begin(camera);
  49. R3D_DrawModel(&plane, (Vector3){0, -0.5f, 0}, 1.0f);
  50. R3D_DrawModel(&sphere, (Vector3){0, 0, 0}, 1.0f);
  51. R3D_DrawModel(&cube, (Vector3){0, 0, 0}, 1.0f);
  52. R3D_End();
  53. EndDrawing();
  54. }
  55. // Cleanup
  56. R3D_UnloadModel(&plane, false);
  57. R3D_UnloadModel(&sphere, false);
  58. R3D_UnloadModel(&cube, false);
  59. R3D_Close();
  60. CloseWindow();
  61. return 0;
  62. }