transparency.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "./common.h"
  2. /* === Resources === */
  3. static Model cube = { 0 };
  4. static Model plane = { 0 };
  5. static Model sphere = { 0 };
  6. static Camera3D camera = { 0 };
  7. /* === Examples === */
  8. const char* Init(void)
  9. {
  10. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  11. SetTargetFPS(60);
  12. // NOTE: This mode is already the default one, but the call is made here for example purposes.
  13. // In this mode, R3D will attempt to detect when to perform deferred or forward rendering
  14. // automatically based on the alpha of the albedo color or the format of the albedo texture.
  15. R3D_ApplyRenderMode(R3D_RENDER_AUTO_DETECT);
  16. cube = LoadModelFromMesh(GenMeshCube(1, 1, 1));
  17. cube.materials[0].maps[MATERIAL_MAP_ALBEDO].color = (Color){ 100, 100, 255, 100 };
  18. cube.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
  19. cube.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.2f;
  20. cube.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.2f;
  21. plane = LoadModelFromMesh(GenMeshPlane(1000, 1000, 1, 1));
  22. plane.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
  23. plane.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 1.0f;
  24. plane.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.0f;
  25. sphere = LoadModelFromMesh(GenMeshSphere(0.5f, 64, 64));
  26. sphere.materials[0].maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
  27. sphere.materials[0].maps[MATERIAL_MAP_ROUGHNESS].value = 0.25f;
  28. sphere.materials[0].maps[MATERIAL_MAP_METALNESS].value = 0.75f;
  29. camera = (Camera3D){
  30. .position = (Vector3) { 0, 2, 2 },
  31. .target = (Vector3) { 0, 0, 0 },
  32. .up = (Vector3) { 0, 1, 0 },
  33. .fovy = 60,
  34. };
  35. R3D_Light light = R3D_CreateLight(R3D_LIGHT_SPOT);
  36. {
  37. R3D_SetLightPosition(light, (Vector3) { 0, 10, 5 });
  38. R3D_SetLightTarget(light, (Vector3) { 0 });
  39. R3D_SetLightActive(light, true);
  40. R3D_EnableShadow(light, 4096);
  41. }
  42. return "[r3d] - transparency example";
  43. }
  44. void Update(float delta)
  45. {
  46. UpdateCamera(&camera, CAMERA_ORBITAL);
  47. }
  48. void Draw(void)
  49. {
  50. R3D_Begin(camera);
  51. {
  52. R3D_ApplyShadowCastMode(R3D_SHADOW_CAST_FRONT_FACES);
  53. R3D_DrawModel(plane, (Vector3) { 0, -0.5f, 0 }, 1.0f);
  54. R3D_DrawModel(sphere, (Vector3) { 0 }, 1.0f);
  55. R3D_ApplyShadowCastMode(R3D_SHADOW_CAST_DISABLED);
  56. R3D_DrawModel(cube, (Vector3) { 0 }, 1.0f);
  57. }
  58. R3D_End();
  59. }
  60. void Close(void)
  61. {
  62. UnloadModel(plane);
  63. UnloadModel(sphere);
  64. R3D_Close();
  65. }