mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
60e44f7564
* terrain and model automatic choose lightmap shader * fix eslint error
250 lines
6.9 KiB
Plaintext
250 lines
6.9 KiB
Plaintext
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
|
|
|
CCEffect %{
|
|
techniques:
|
|
- passes:
|
|
- vert: standard-vs
|
|
frag: standard-fs
|
|
phase: reflection
|
|
depthStencilState:
|
|
depthTest: true
|
|
depthWrite: false
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: src_alpha
|
|
blendDst: one_minus_src_alpha
|
|
blendDstAlpha: one_minus_src_alpha
|
|
properties: &props
|
|
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
|
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } }
|
|
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
|
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
|
occlusion: { value: 1.0, target: pbrParams.x }
|
|
roughness: { value: 0.8, target: pbrParams.y }
|
|
metallic: { value: 0.6, target: pbrParams.z }
|
|
normalStrenth: { value: 1.0, target: pbrParams.w, editor: { parent: USE_NORMAL_MAP } }
|
|
emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } }
|
|
emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz }
|
|
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
|
normalMap: { value: normal }
|
|
pbrMap: { value: grey }
|
|
metallicRoughnessMap: { value: grey }
|
|
occlusionMap: { value: white }
|
|
emissiveMap: { value: grey }
|
|
}%
|
|
|
|
CCProgram shared-ubos %{
|
|
uniform Constants {
|
|
vec4 tilingOffset;
|
|
vec4 albedo;
|
|
vec4 albedoScaleAndCutoff;
|
|
vec4 pbrParams;
|
|
vec4 emissive;
|
|
vec4 emissiveScaleParam;
|
|
};
|
|
}%
|
|
|
|
CCProgram standard-vs %{
|
|
precision highp float;
|
|
#include <input-standard>
|
|
#include <cc-global>
|
|
#include <decode-base>
|
|
#include <cc-local-batch>
|
|
#include <shared-ubos>
|
|
#include <cc-fog-vs>
|
|
#include <cc-shadow-map-vs>
|
|
|
|
#if USE_VERTEX_COLOR
|
|
in vec4 a_color;
|
|
out vec4 v_color;
|
|
#endif
|
|
|
|
out vec3 v_position;
|
|
out vec3 v_normal;
|
|
out vec2 v_uv;
|
|
out vec2 v_uv1;
|
|
|
|
#if USE_NORMAL_MAP
|
|
out vec3 v_tangent;
|
|
out vec3 v_bitangent;
|
|
#endif
|
|
|
|
#if HAS_SECOND_UV || CC_USE_LIGHTMAP
|
|
in vec2 a_texCoord1;
|
|
#endif
|
|
|
|
#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
|
#include <lightingmap-vs>
|
|
#endif
|
|
|
|
void main () {
|
|
StandardVertInput In;
|
|
CCVertInput(In);
|
|
|
|
mat4 matWorld, matWorldIT;
|
|
CCGetWorldMatrixFull(matWorld, matWorldIT);
|
|
|
|
vec4 pos = matWorld * In.position;
|
|
|
|
v_position = pos.xyz;
|
|
v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);
|
|
#if USE_NORMAL_MAP
|
|
v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);
|
|
v_bitangent = cross(v_normal, v_tangent) * In.tangent.w; // note the cross order
|
|
#endif
|
|
|
|
v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;
|
|
#if HAS_SECOND_UV
|
|
v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;
|
|
#endif
|
|
|
|
#if USE_VERTEX_COLOR
|
|
v_color = a_color;
|
|
#endif
|
|
|
|
CC_TRANSFER_FOG(pos);
|
|
CC_TRANSFER_SHADOW(pos);
|
|
|
|
#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
|
CCLightingMapCaclUV();
|
|
#endif
|
|
|
|
|
|
gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;
|
|
}
|
|
}%
|
|
|
|
CCProgram standard-fs %{
|
|
precision highp float;
|
|
#include <cc-global>
|
|
#include <shared-ubos>
|
|
#include <cc-fog-fs>
|
|
#include <standard-surface-entry>
|
|
#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
|
#include <lightingmap-fs>
|
|
#endif
|
|
|
|
in vec3 v_position;
|
|
in vec2 v_uv;
|
|
in vec2 v_uv1;
|
|
in vec3 v_normal;
|
|
|
|
#if USE_VERTEX_COLOR
|
|
in vec4 v_color;
|
|
#endif
|
|
|
|
#if USE_ALBEDO_MAP
|
|
uniform sampler2D albedoMap;
|
|
#pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
|
|
#endif
|
|
#if USE_NORMAL_MAP
|
|
in vec3 v_tangent;
|
|
in vec3 v_bitangent;
|
|
uniform sampler2D normalMap;
|
|
#pragma define-meta NORMAL_UV options([v_uv, v_uv1])
|
|
#endif
|
|
#pragma define-meta PBR_UV options([v_uv, v_uv1])
|
|
#if USE_PBR_MAP
|
|
uniform sampler2D pbrMap;
|
|
#endif
|
|
#if USE_METALLIC_ROUGHNESS_MAP
|
|
uniform sampler2D metallicRoughnessMap;
|
|
#endif
|
|
#if USE_OCCLUSION_MAP
|
|
uniform sampler2D occlusionMap;
|
|
#endif
|
|
#if USE_EMISSIVE_MAP
|
|
uniform sampler2D emissiveMap;
|
|
#pragma define-meta EMISSIVE_UV options([v_uv, v_uv1])
|
|
#endif
|
|
|
|
#pragma define OCCLUSION_CHANNEL r
|
|
#pragma define ROUGHNESS_CHANNEL g
|
|
#pragma define METALLIC_CHANNEL b
|
|
|
|
#if USE_ALPHA_TEST
|
|
#pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
|
|
#endif
|
|
|
|
void surf (out StandardSurface s) {
|
|
vec4 baseColor = albedo;
|
|
#if USE_VERTEX_COLOR
|
|
baseColor *= v_color;
|
|
#endif
|
|
#if USE_ALBEDO_MAP
|
|
vec4 texColor = texture(albedoMap, ALBEDO_UV);
|
|
texColor.rgb = SRGBToLinear(texColor.rgb);
|
|
baseColor *= texColor;
|
|
#endif
|
|
s.albedo = baseColor;
|
|
s.albedo.rgb *= albedoScaleAndCutoff.xyz;
|
|
|
|
#if USE_ALPHA_TEST
|
|
if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
|
|
#endif
|
|
|
|
#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD
|
|
s.lightmap = texture(cc_lightingMap, v_luv);
|
|
#endif
|
|
|
|
s.normal = v_normal;
|
|
#if USE_NORMAL_MAP
|
|
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
|
s.normal =
|
|
(nmmp.x * pbrParams.w) * normalize(v_tangent) +
|
|
(nmmp.y * pbrParams.w) * normalize(v_bitangent) +
|
|
nmmp.z * normalize(s.normal);
|
|
#endif
|
|
|
|
HIGHP_VALUE_TO_STRUCT_DEFINED(v_position, s.position);
|
|
|
|
vec4 pbr = pbrParams;
|
|
#if USE_PBR_MAP
|
|
vec4 res = texture(pbrMap, PBR_UV);
|
|
pbr.x *= res.OCCLUSION_CHANNEL;
|
|
pbr.y *= res.ROUGHNESS_CHANNEL;
|
|
pbr.z *= res.METALLIC_CHANNEL;
|
|
#endif
|
|
#if USE_METALLIC_ROUGHNESS_MAP
|
|
vec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);
|
|
pbr.z *= metallicRoughness.METALLIC_CHANNEL;
|
|
pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;
|
|
#endif
|
|
#if USE_OCCLUSION_MAP
|
|
pbr.x *= texture(occlusionMap, PBR_UV).OCCLUSION_CHANNEL;
|
|
#endif
|
|
s.occlusion = pbr.x;
|
|
s.roughness = pbr.y;
|
|
s.specularIntensity = 0.5;
|
|
s.metallic = pbr.z;
|
|
|
|
s.emissive = emissive.rgb * emissiveScaleParam.xyz;
|
|
#if USE_EMISSIVE_MAP
|
|
s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);
|
|
#endif
|
|
}
|
|
|
|
#pragma builtin(local)
|
|
layout(set = 2, binding = 12) uniform sampler2D cc_reflectionTexture;
|
|
|
|
layout(location = 0) out vec4 fragColorX;
|
|
|
|
void main () {
|
|
StandardSurface s; surf(s);
|
|
vec4 color = CCStandardShadingBase(s, CC_SHADOW_POSITION);
|
|
CC_APPLY_FOG(color, s.position.xyz);
|
|
vec4 baseColor = CCFragOutput(color);
|
|
|
|
vec2 noise = v_normal.xy * 0.02;
|
|
#if USE_NORMAL_MAP
|
|
noise = texture(normalMap, ALBEDO_UV).xy * 0.02;
|
|
#endif
|
|
|
|
vec2 resolution = cc_screenSize.xy;
|
|
vec2 uv = (gl_FragCoord.xy / resolution) + noise;
|
|
vec4 reflectionColor = texture(cc_reflectionTexture, uv);
|
|
fragColorX = mix(baseColor, reflectionColor, 0.5);
|
|
fragColorX.w = 1.0;
|
|
}
|
|
}% |