sky.effect 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: sky-vs
  7. frag: sky-fs
  8. properties: &props
  9. environmentMap: { value: grey }
  10. positionScaling: { value: 1.0, target: params.w, editor: { tooltip: 'Set a smaller value (such as less than 1.0) to remove the effects of fog' } }
  11. blendEnvironmentMap: { value: grey, editor: { parent: BLEND_ENV_MAP } }
  12. blendWeight: { value: 0.0, target: params.x, editor: { parent: BLEND_ENV_MAP } }
  13. brightMultiplier: { value: 1.0, target: params.y }
  14. priority : max - 10
  15. rasterizerState : &r1
  16. cullMode : none
  17. depthStencilState : &d1
  18. depthTest: true
  19. depthWrite : false
  20. - vert: sky-vs
  21. frag: sky-fs
  22. phase: deferred-forward
  23. propertyIndex: 0
  24. priority: max - 10
  25. rasterizerState: *r1
  26. depthStencilState: *d1
  27. }%
  28. CCProgram shared-ubos %{
  29. uniform Constants {
  30. vec4 params;
  31. };
  32. }%
  33. CCProgram surface-vertex %{
  34. #define CC_SURFACES_VERTEX_MODIFY_WORLD_POS
  35. vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
  36. {
  37. // Apply uniform scaling for atmosphere effects
  38. return cc_cameraPos.xyz + In.worldPos * params.w;
  39. }
  40. }%
  41. CCProgram surface-fragment %{
  42. uniform samplerCube environmentMap;
  43. #if BLEND_ENV_MAP
  44. uniform samplerCube blendEnvironmentMap;
  45. #endif
  46. #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
  47. vec3 sampleEnvMap(samplerCube tex, vec3 R)
  48. {
  49. vec3 c = vec3(1.0);
  50. #if USE_RGBE_CUBEMAP
  51. c *= unpackRGBE(fragTextureLod(tex, R, 0.0));
  52. #else
  53. c *= SRGBToLinear(fragTextureLod(tex, R, 0.0).rgb);
  54. #endif
  55. return c;
  56. }
  57. vec4 SurfacesFragmentModifyBaseColorAndTransparency()
  58. {
  59. vec3 c = vec3(1.0);
  60. vec3 normal = normalize(FSInput_worldNormal);
  61. vec3 rotationDir = RotationVecFromAxisY(normal.xyz, cc_surfaceTransform.z, cc_surfaceTransform.w);
  62. c = sampleEnvMap(environmentMap, rotationDir);
  63. #if BLEND_ENV_MAP
  64. c = mix(c, sampleEnvMap(blendEnvironmentMap, rotationDir), params.x);
  65. #endif
  66. return vec4(c * cc_ambientSky.w * params.y, 1.0);
  67. }
  68. }%
  69. CCProgram sky-vs %{
  70. precision highp float;
  71. #include <surfaces/effect-macros/sky>
  72. #include <surfaces/includes/common-vs>
  73. #include <shared-ubos>
  74. #include <surface-vertex>
  75. #include <shading-entries/main-functions/misc/sky-vs>
  76. }%
  77. CCProgram sky-fs %{
  78. precision highp float;
  79. #include <surfaces/effect-macros/sky>
  80. #include <surfaces/includes/common-fs>
  81. #include <shared-ubos>
  82. #include <surface-fragment>
  83. #include <shading-entries/main-functions/misc/sky-fs>
  84. }%