| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - passes:
- - vert: tonemap-vs
- frag: copy-fs
- pass: copy-pass
- depthTest: false
- depthWrite: false
- - vert: tonemap-vs
- frag: tonemap-fs
- pass: tone-mapping
- depthStencilState:
- depthTest: false
- depthWrite: false
- rasterizerState:
- cullMode: none
- }%
- CCProgram tonemap-vs %{
- #include <./post-process/chunks/vs>
- }%
- CCProgram copy-fs %{
- precision highp float;
- #include <builtin/uniforms/cc-global>
- #include <common/data/packing>
- #pragma rate depthRaw pass
- uniform sampler2D depthRaw;
- in vec2 v_uv;
- layout(location = 0) out vec4 fragColor;
- void main() {
- float depth = texture(depthRaw, v_uv).r;
- fragColor = packDepthToRGBA(depth);
- }
- }%
- CCProgram tonemap-fs %{
- precision highp float;
- #define CC_SURFACES_ENABLE_DEBUG_VIEW 1
- #include <builtin/uniforms/cc-global>
- #include <common/common-define>
- #include <common/data/packing>
- #include <common/debug/debug-view-define>
- #include <common/color/gamma>
- #include <common/color/tone-mapping>
- #include <common/math/coordinates>
- #include <builtin/functionalities/fog>
- in vec2 v_uv;
- #pragma rate u_texSampler pass
- layout(binding = 0) uniform sampler2D u_texSampler;
- #pragma rate DepthTex pass
- layout(binding = 1) uniform sampler2D DepthTex; //Sample_Point_Clamp
- layout(location = 0) out vec4 fragColor;
- vec4 CCFragOutput_PostProcess(vec4 color) {
- // fog related
- vec4 worldPos = vec4(0.0);
- #if CC_USE_FOG != CC_FOG_NONE
- float depth = unpackRGBAToDepth(texture(DepthTex, v_uv));
- vec3 posHS = vec3(v_uv, depth) * 2.0 - vec3(1.0);
- CC_HANDLE_GET_CLIP_FLIP(posHS.xy);
- worldPos = GetWorldPosFromNDCPosRH(posHS, cc_matProj, cc_matViewProjInv);
- #endif
- // HDR fog
- // todo: apply fogColorBrightness to linear fogColor for supporting scatter lighting with HDR
- #if CC_USE_FOG != CC_FOG_NONE
- float fogFactor = 1.0;
- CC_TRANSFER_FOG_BASE(worldPos, fogFactor);
- CC_APPLY_FOG_BASE(color, fogFactor);
- #endif
- // tone mapping
- if (!DebugViewNeedDisplayOriginalData()) {
- #if CC_USE_FLOAT_OUTPUT
- color.rgb = HDRToLDR(color.rgb);
- color.rgb = LinearToSRGB(color.rgb);
- #endif
- }
- // LDR fog
- return color;
- }
- void main () {
- vec4 o = texture(u_texSampler, v_uv);
- fragColor = CCFragOutput_PostProcess(o);
- }
- }%
|