Files
cocos4/editor/assets/effects/pipeline/float-output-process.effect
T

83 lines
2.1 KiB
Plaintext

// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- 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 tonemap-fs %{
precision highp float;
#include <builtin/uniforms/cc-global>
#include <common/common-define>
#include <common/color/gamma>
#include <common/color/aces>
#include <common/debug/debug-view-define>
#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;
vec3 HDR2LDR_PostProcess(vec3 color) {
vec3 tempColor = color.rgb;
#if CC_USE_HDR && CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
tempColor.rgb = ACESToneMap(color.rgb);
#endif
return tempColor.rgb;
}
vec4 CCFragOutput_PostProcess(vec4 color) {
// fog related
vec4 worldPos = vec4(0.0);
#if CC_USE_FOG != CC_FOG_NONE
float depth = texture(DepthTex, v_uv).r;
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
// todo: apply fogColorBrightness to fogColor for supporting scatter lighting with HDR
// tone mapping
if (!DebugViewNeedDisplayOriginalData()) {
#if CC_USE_FLOAT_OUTPUT
color.rgb = HDR2LDR_PostProcess(color.rgb);
color.rgb = LinearToSRGB(color.rgb);
#endif
}
// LDR fog
#if CC_USE_FOG != CC_FOG_NONE
float fogFactor = 1.0;
CC_TRANSFER_FOG_BASE(worldPos, fogFactor);
CC_APPLY_FOG_BASE(color, fogFactor);
#endif
return color;
}
void main () {
vec4 o = texture(u_texSampler, v_uv);
fragColor = CCFragOutput_PostProcess(o);
}
}%