Layered Clouds.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /******************************************************************************/
  2. #include "!Header.h"
  3. #include "Layered Clouds.h"
  4. /******************************************************************************/
  5. void LayeredClouds_VS
  6. (
  7. VtxInput vtx,
  8. out Vec outPos:TEXCOORD0,
  9. out Vec4 outTex:TEXCOORD1, // xyz=3d tex coord, w=alpha
  10. out Vec4 outVtx:POSITION
  11. )
  12. {
  13. Vec pos=vtx.pos();
  14. outTex.xyz=pos.xyz*Vec(LCScale, 1, LCScale);
  15. outTex.w =CloudAlpha(outTex.y);
  16. pos.y =pos.y*LCScaleY+(-LCScaleY+1); // (pos.y-1)*LCScaleY+1
  17. outVtx=Project(outPos=TransformPos(pos));
  18. }
  19. /******************************************************************************/
  20. Vec4 LayeredClouds_PS(Vec inPos :TEXCOORD0,
  21. Vec4 inTex :TEXCOORD1,
  22. PIXEL ,
  23. out VecH4 outMask:COLOR1 ,
  24. uniform Int num ,
  25. uniform Bool blend ,
  26. uniform Bool mask ):COLOR
  27. {
  28. Half a=Sat(inTex.w);
  29. if(blend)
  30. {
  31. Flt range=TexDepthPoint(PIXEL_TO_SCREEN)/Normalize(inPos).z; // 0..Viewport.range
  32. a *=Sat(range*LCRange.x+LCRange.y);
  33. }
  34. Vec2 uv=Normalize(inTex.xyz).xz;
  35. VecH4 color;
  36. if(num>=4){Vec4 tex=Tex(Col3, uv*CL[3].scale + CL[3].position)*CL[3].color; if(num==4)color=tex;else color=Lerp(color, tex, tex.a);}
  37. if(num>=3){Vec4 tex=Tex(Col2, uv*CL[2].scale + CL[2].position)*CL[2].color; if(num==3)color=tex;else color=Lerp(color, tex, tex.a);}
  38. if(num>=2){Vec4 tex=Tex(Col1, uv*CL[1].scale + CL[1].position)*CL[1].color; if(num==2)color=tex;else color=Lerp(color, tex, tex.a);}
  39. if(num>=1){Vec4 tex=Tex(Col , uv*CL[0].scale + CL[0].position)*CL[0].color; if(num==1)color=tex;else color=Lerp(color, tex, tex.a);}
  40. color.a*=a;
  41. if(mask)
  42. {
  43. outMask.rgb=0;
  44. outMask.a =Sat(color.a*LCMaskContrast.x+LCMaskContrast.y); // (color.a-0.5)*LCMaskContrast+0.5
  45. }
  46. return color;
  47. }
  48. /******************************************************************************/
  49. // TECHNIQUES
  50. /******************************************************************************/
  51. TECHNIQUE(Clouds1 , LayeredClouds_VS(), LayeredClouds_PS(1, false, false));
  52. TECHNIQUE(Clouds2 , LayeredClouds_VS(), LayeredClouds_PS(2, false, false));
  53. TECHNIQUE(Clouds3 , LayeredClouds_VS(), LayeredClouds_PS(3, false, false));
  54. TECHNIQUE(Clouds4 , LayeredClouds_VS(), LayeredClouds_PS(4, false, false));
  55. TECHNIQUE(Clouds1B , LayeredClouds_VS(), LayeredClouds_PS(1, true , false));
  56. TECHNIQUE(Clouds2B , LayeredClouds_VS(), LayeredClouds_PS(2, true , false));
  57. TECHNIQUE(Clouds3B , LayeredClouds_VS(), LayeredClouds_PS(3, true , false));
  58. TECHNIQUE(Clouds4B , LayeredClouds_VS(), LayeredClouds_PS(4, true , false));
  59. TECHNIQUE(Clouds1M , LayeredClouds_VS(), LayeredClouds_PS(1, false, true ));
  60. TECHNIQUE(Clouds2M , LayeredClouds_VS(), LayeredClouds_PS(2, false, true ));
  61. TECHNIQUE(Clouds3M , LayeredClouds_VS(), LayeredClouds_PS(3, false, true ));
  62. TECHNIQUE(Clouds4M , LayeredClouds_VS(), LayeredClouds_PS(4, false, true ));
  63. TECHNIQUE(Clouds1BM, LayeredClouds_VS(), LayeredClouds_PS(1, true , true ));
  64. TECHNIQUE(Clouds2BM, LayeredClouds_VS(), LayeredClouds_PS(2, true , true ));
  65. TECHNIQUE(Clouds3BM, LayeredClouds_VS(), LayeredClouds_PS(3, true , true ));
  66. TECHNIQUE(Clouds4BM, LayeredClouds_VS(), LayeredClouds_PS(4, true , true ));
  67. /******************************************************************************/