transparency.c 2.0 KB

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