Files
cocos4/editor/assets/effects/pipeline/deferred-lighting.effect
T
hyde zhou 019d35b22e [V3.5.0 deferred pipeline] fix vulkan crash problem (#10809)
* disable post-process alpha blend

* effects updated

* effects updated

* vk fix added

* disable gles3 fbf

* fix typo

* format and add comments

* add TODO

* fix TODO
2022-04-20 18:26:48 +08:00

137 lines
4.3 KiB
Plaintext

// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: lighting-vs
frag: lighting-fs
phase: deferred-lighting
depthStencilState:
depthFunc: greater
depthTest: true
depthWrite: false
}%
CCProgram lighting-vs %{
precision highp float;
#include <decode>
#include <cc-global>
#include <common>
out vec2 v_uv;
void main () {
vec4 position;
CCDecode(position);
CC_HANDLE_GET_CLIP_FLIP(position.xy);
gl_Position = vec4(position.x, position.y, 1.0, 1.0);
v_uv = a_texCoord;
}
}%
CCProgram lighting-fs %{
precision highp float;
#include <cc-global>
#include <shading-standard-base>
#include <shading-standard-additive>
#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1
#include <shading-cluster-additive>
#endif
#include <output-standard>
#include <cc-fog-base>
#include <octahedron-transform>
in vec2 v_uv;
#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT
#pragma extension([GL_EXT_shader_framebuffer_fetch, __VERSION__ < 450, enable])
#if __VERSION__ >= 450
layout(binding = 0, input_attachment_index = 0) uniform subpassInput gbuffer_albedoMap;
layout(binding = 1, input_attachment_index = 1) uniform subpassInput gbuffer_normalMap;
layout(binding = 2, input_attachment_index = 2) uniform subpassInput gbuffer_emissiveMap;
layout(binding = 3, input_attachment_index = 3) uniform subpassInput depth_stencil;
#elif __VERSION__ >= 300
layout(location = 0) inout vec4 gbuffer_albedoMap;
layout(location = 1) inout vec4 gbuffer_normalMap;
layout(location = 2) inout vec4 gbuffer_emissiveMap;
layout(binding = 3) uniform sampler2D depth_stencil;
#else
layout(binding = 3) uniform sampler2D depth_stencil;
#endif
#else
layout(binding = 0) uniform sampler2D gbuffer_albedoMap;
layout(binding = 1) uniform sampler2D gbuffer_normalMap;
layout(binding = 2) uniform sampler2D gbuffer_emissiveMap;
layout(binding = 3) uniform sampler2D depth_stencil;
#endif
#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450
layout(location = 0) out vec4 fragColor;
#endif
void main () {
StandardSurface s;
#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT
#if __VERSION__ >= 450
vec4 albedoMap = subpassLoad(gbuffer_albedoMap);
vec4 normalMap = subpassLoad(gbuffer_normalMap);
vec4 emissiveMap = subpassLoad(gbuffer_emissiveMap);
float depth = subpassLoad(depth_stencil).x;
#elif __VERSION__ >= 300
vec4 albedoMap = gbuffer_albedoMap;
vec4 normalMap = gbuffer_normalMap;
vec4 emissiveMap = gbuffer_emissiveMap;
float depth = texture(depth_stencil, v_uv).x;
#else
vec4 albedoMap = gl_LastFragData[0];
vec4 normalMap = gl_LastFragData[1];
vec4 emissiveMap = gl_LastFragData[2];
float depth = texture(depth_stencil, v_uv).x;
#endif
#else
vec4 albedoMap = texture(gbuffer_albedoMap,v_uv);
vec4 normalMap = texture(gbuffer_normalMap,v_uv);
vec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv);
float depth = texture(depth_stencil, v_uv).x;
#endif
s.albedo = albedoMap;
vec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;
s.position = position;
s.roughness = normalMap.z;
s.normal = oct_to_float32x3(normalMap.xy);
s.specularIntensity = 0.5;
s.metallic = normalMap.w;
s.emissive = emissiveMap.xyz;
s.occlusion = emissiveMap.w;
// fixme: default value is 0, and give black result
float fogFactor;
CC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);
vec4 shadowPos;
CC_TRANSFER_SHADOW_BASE(vec4(position, 1), shadowPos);
vec4 color = CCStandardShadingBase(s, shadowPos) +
#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1
CCClusterShadingAdditive(s, shadowPos);
#else
CCStandardShadingAdditive(s, shadowPos);
#endif
CC_APPLY_FOG_BASE(color, fogFactor);
color = CCFragOutput(color);
#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT
#if __VERSION__ >= 450
fragColor = color;
#elif __VERSION__ >= 300
gbuffer_emissiveMap = color;
#else
gl_FragData[2] = color;
#endif
#else
fragColor = color;
#endif
}
}%