fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. struct VolumeObject
  5. {
  6. float Red, Green, Blue, Alpha, Volume;
  7.  
  8. VolumeObject(float red, float green, float blue, float alpha, float volume) : Red(red), Green(green), Blue(blue), Alpha(alpha), Volume(volume)
  9. {
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. VolumeObject volumes[] = { VolumeObject(1, 0, 0, 0.5f, 0.25f), VolumeObject(1, 0, 0, 0.5f, 0.5f), VolumeObject(1, 0, 0, 0.5f, 0.25f) };
  16.  
  17. float colorR = 0;
  18. float colorG = 0;
  19. float colorB = 0;
  20. float colorA = 1;
  21.  
  22. for (int i = 0; i < 3; ++i)
  23. {
  24. float scale = colorA - colorA * exp(-volumes[i].Alpha * volumes[i].Volume);
  25. std::cout << "Scale: " << scale << std::endl;
  26. colorR += volumes[i].Red * scale;
  27. colorG += volumes[i].Green * scale;
  28. colorB += volumes[i].Blue * scale;
  29. colorA *= exp(-volumes[i].Alpha * volumes[i].Volume);
  30. std::cout << colorR << " " << colorG << " " << colorB << " " << colorA << std::endl;
  31. }
  32. colorR /= colorA;
  33. colorG /= colorA;
  34. colorB /= colorA;
  35. colorA /= colorA;
  36. std::cout << "Final Color" << std::endl;
  37. std::cout << colorR << " " << colorG << " " << colorB << " " << colorA << std::endl;
  38. return 0;
  39. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
Scale: 0.117503
0.117503 0 0 0.882497
Scale: 0.195208
0.312711 0 0 0.687289
Scale: 0.0807586
0.393469 0 0 0.606531
Final Color
0.648721 0 0 1