mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
342 lines
12 KiB
Plaintext
342 lines
12 KiB
Plaintext
// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
|
|
|
CCEffect %{
|
|
techniques:
|
|
- name: opaque
|
|
passes:
|
|
- vert: standard-vs
|
|
frag: standard-fs
|
|
embeddedMacros: { CC_SURFACES_LIGHTING_DISABLE_DIFFUSE: false, CC_SURFACES_LIGHTING_DISABLE_SPECULAR: true }
|
|
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, slide: true, range: [0, 1.0], step: 0.001 } }
|
|
occlusion: { value: 0.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
|
roughness: { value: 0.5, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
|
specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
|
normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
|
|
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
|
normalMap: { value: normal }
|
|
pbrMap: { value: grey, editor: { displayName: PbrOrRoughnessMap } }
|
|
occlusionMap: { value: white }
|
|
sssIntensity: { value: 1.0, target: scatterParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
|
sssMap: { value: black }
|
|
cavityMap: { value: white, editor: { tooltip: 'cavity map or specular map' } }
|
|
maskMap: { value: black, editor: { parent: USE_BACK_LIT } }
|
|
thickness: { value: 0.0, target: scatterParams.x, editor: { parent: USE_BACK_LIT, displayName: Object Thickness, range: [0, 1000.0], tooltip: 'i18n:ENGINE.assets.effect.propertyTips.transmitThicknessWithShadowMap' } }
|
|
extinction: { value: 0.0, target: scatterParams.y, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001, tooltip: 'i18n:ENGINE.assets.effect.propertyTips.transmitExtinctionWithShadowMap' } }
|
|
transmitColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting, red for human skin' } }
|
|
dualLobeRoughness: { value: 0.5, target: dualLobeParams.x, editor: { parent: USE_DUAL_LOBE_SPECULAR, range: [0, 1.0] } }
|
|
dualLobeIntensity: { value: 0.02, target: dualLobeParams.w, editor: { parent: USE_DUAL_LOBE_SPECULAR, slide: true, range: [0, 0.1], step: 0.001 } }
|
|
rasterizerState:
|
|
cullMode: None
|
|
depthStencilState:
|
|
depthFunc: less_equal
|
|
depthTest: true
|
|
depthWrite: true
|
|
stencilTestFront: true
|
|
stencilPassOpFront: replace
|
|
stencilRef: 0x78 # [0~255],use 120
|
|
|
|
- vert: standard-vs
|
|
frag: standard-fs
|
|
phase: forward-add
|
|
propertyIndex: 0
|
|
embeddedMacros: { CC_FORWARD_ADD: true, CC_SURFACES_LIGHTING_DISABLE_DIFFUSE: false, CC_SURFACES_LIGHTING_DISABLE_SPECULAR: true }
|
|
depthStencilState:
|
|
depthFunc: equal
|
|
depthTest: true
|
|
depthWrite: false
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: one
|
|
blendDst: one
|
|
blendSrcAlpha: zero
|
|
blendDstAlpha: one
|
|
|
|
- vert: shadow-caster-vs
|
|
frag: shadow-caster-fs
|
|
phase: shadow-caster
|
|
propertyIndex: 0
|
|
rasterizerState:
|
|
cullMode: none
|
|
properties:
|
|
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
|
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, 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 } }
|
|
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
|
|
|
- vert: standard-vs
|
|
frag: standard-fs
|
|
pass: specular-pass
|
|
propertyIndex: 0
|
|
embeddedMacros: { CC_SURFACES_LIGHTING_DISABLE_DIFFUSE: true, CC_SURFACES_LIGHTING_DISABLE_SPECULAR: false }
|
|
depthStencilState:
|
|
depthFunc: equal
|
|
depthTest: true
|
|
depthWrite: false
|
|
stencilTestFront: true
|
|
stencilFuncFront: equal
|
|
stencilRef: 0x78 # [0~255],use 120
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: one
|
|
blendDst: one
|
|
blendSrcAlpha: zero
|
|
blendDstAlpha: one
|
|
|
|
- vert: standard-vs
|
|
frag: standard-fs
|
|
pass: specular-pass
|
|
phase: forward-add
|
|
propertyIndex: 0
|
|
embeddedMacros: { CC_FORWARD_ADD: true, CC_SURFACES_LIGHTING_DISABLE_DIFFUSE: true, CC_SURFACES_LIGHTING_DISABLE_SPECULAR: false }
|
|
depthStencilState:
|
|
depthFunc: equal
|
|
depthTest: true
|
|
depthWrite: false
|
|
stencilTestFront: true
|
|
stencilFuncFront: equal
|
|
stencilRef: 0x78 # [0~255],use 120
|
|
blendState:
|
|
targets:
|
|
- blend: true
|
|
blendSrc: one
|
|
blendDst: one
|
|
blendSrcAlpha: zero
|
|
blendDstAlpha: one
|
|
}%
|
|
|
|
CCProgram shared-ubos %{
|
|
uniform Constants {
|
|
vec4 tilingOffset;
|
|
vec4 albedo;
|
|
vec4 albedoScaleAndCutoff;
|
|
vec4 pbrParams;
|
|
vec4 emissiveScaleParam;
|
|
vec4 transmitColor;
|
|
vec4 scatterParams;
|
|
vec4 dualLobeParams;
|
|
};
|
|
}%
|
|
|
|
CCProgram macro-remapping %{
|
|
// ui displayed macros
|
|
#pragma define-meta HAS_SECOND_UV
|
|
#pragma define-meta USE_TWOSIDE
|
|
#pragma define-meta USE_VERTEX_COLOR
|
|
#pragma define-meta USE_BACK_LIT
|
|
#pragma define-meta USE_DUAL_LOBE_SPECULAR
|
|
|
|
#define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
|
|
#define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
|
|
#define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
|
|
|
|
#define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR USE_DUAL_LOBE_SPECULAR
|
|
#define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT
|
|
#define CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT USE_BACK_LIT
|
|
#define CC_SURFACES_LIGHTING_SSS 1
|
|
|
|
// depend on UI macros
|
|
#if USE_NORMAL_MAP
|
|
#define CC_SURFACES_USE_TANGENT_SPACE 1
|
|
#endif
|
|
}%
|
|
|
|
CCProgram surface-vertex %{
|
|
}%
|
|
|
|
CCProgram surface-fragment %{
|
|
#if USE_ALBEDO_MAP
|
|
uniform sampler2D albedoMap;
|
|
#pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
|
|
#endif
|
|
#if USE_NORMAL_MAP
|
|
uniform sampler2D normalMap;
|
|
#pragma define-meta NORMAL_UV options([v_uv, v_uv1])
|
|
#endif
|
|
#pragma define-meta DEFAULT_UV options([v_uv, v_uv1])
|
|
#if USE_PBR_MAP
|
|
uniform sampler2D pbrMap;
|
|
#endif
|
|
#if USE_OCCLUSION_MAP
|
|
uniform sampler2D occlusionMap;
|
|
#endif
|
|
#if USE_SSS_MAP
|
|
uniform sampler2D sssMap;
|
|
#endif
|
|
|
|
#pragma define OCCLUSION_CHANNEL r
|
|
#pragma define ROUGHNESS_CHANNEL g
|
|
#pragma define METALLIC_CHANNEL b
|
|
#pragma define SPECULAR_INTENSITY_CHANNEL a
|
|
|
|
#if USE_ALPHA_TEST
|
|
#pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
|
|
#endif
|
|
|
|
//////////////////User Defines
|
|
#if USE_BACK_LIT
|
|
uniform sampler2D maskMap;
|
|
#endif
|
|
uniform sampler2D cavityMap;
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS
|
|
vec4 SurfacesFragmentModifyTransmitScatteringParams()
|
|
{
|
|
return vec4(scatterParams.y * 50.0, 0.0, 1.0, 0.01);
|
|
}
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_DIFFUSE_PARAMS
|
|
vec4 SurfacesFragmentModifyTransmitDiffuseParams()
|
|
{
|
|
float mask = 1.0;
|
|
#if USE_BACK_LIT
|
|
mask = texture(maskMap, FSInput_texcoord).x;
|
|
#endif
|
|
return vec4(scatterParams.x, mask, 1.0, 1.0);
|
|
}
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR
|
|
vec3 SurfacesFragmentModifyTransmitInScatteringColor()
|
|
{
|
|
return vec3(0.0);//1.0, 0.2, 0.05);
|
|
}
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
|
|
vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
|
|
{
|
|
return transmitColor.rgb;
|
|
}
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_DUAL_LOBE_SPECULAR_PARAMS
|
|
vec4 SurfacesFragmentModifyDualLobeSpecularParams(float roughness)
|
|
{
|
|
return vec4(dualLobeParams.x * roughness, 0.0, 0.0, dualLobeParams.w);
|
|
}
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_SSS_PARAMS
|
|
vec4 SurfacesFragmentModifySSSParams()
|
|
{
|
|
float sssStrength = scatterParams.z;
|
|
#if USE_SSS_MAP
|
|
sssStrength *= texture(sssMap, DEFAULT_UV).x;
|
|
#endif
|
|
return vec4(sssStrength, 0.0, 0.0, 0.0);
|
|
}
|
|
|
|
#define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
|
|
vec4 SurfacesFragmentModifyPBRParams()
|
|
{
|
|
vec4 pbr = pbrParams;
|
|
pbr.x = 1.0;
|
|
pbr.z = 0.0;
|
|
#if USE_PBR_MAP
|
|
// ao and metallic ignored from pbrMap
|
|
vec4 res = texture(pbrMap, DEFAULT_UV);
|
|
pbr.y *= res.ROUGHNESS_CHANNEL;
|
|
pbr.w *= res.SPECULAR_INTENSITY_CHANNEL;
|
|
#endif
|
|
#if USE_OCCLUSION_MAP
|
|
pbr.x = mix(1.0, texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL, pbrParams.x);
|
|
#endif
|
|
|
|
float cavity = texture(cavityMap, FSInput_texcoord).x;
|
|
pbr.w *= cavity;
|
|
return pbr;
|
|
}
|
|
|
|
#include <common-functions>
|
|
#include <surfaces/default-functions/skin>
|
|
#include <lighting-models/default-functions/skin>
|
|
}%
|
|
|
|
CCProgram standard-vs %{
|
|
precision highp float;
|
|
|
|
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
|
|
#include <macro-remapping>
|
|
#include <surfaces/effect-macros/common-macros>
|
|
|
|
// 2. common include with corresponding shader stage, include before surface functions
|
|
#include <surfaces/includes/common-vs>
|
|
|
|
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
|
|
// see surfaces/default-functions/xxx.chunk
|
|
#include <shared-ubos>
|
|
#include <surface-vertex>
|
|
|
|
// 4. surface include with corresponding shader stage and shading-model (optional)
|
|
#include <surfaces/includes/standard-vs>
|
|
|
|
// 5. shader entry with corresponding shader stage and technique usage/type
|
|
#include <shading-entries/main-functions/render-to-scene/vs>
|
|
}%
|
|
|
|
|
|
CCProgram shadow-caster-vs %{
|
|
precision highp float;
|
|
#include <macro-remapping>
|
|
#include <surfaces/effect-macros/render-to-shadowmap>
|
|
#include <surfaces/includes/common-vs>
|
|
#include <shared-ubos>
|
|
#include <surface-vertex>
|
|
#include <shading-entries/main-functions/render-to-shadowmap/vs>
|
|
}%
|
|
|
|
|
|
|
|
CCProgram standard-fs %{
|
|
// shading-model : standard
|
|
// lighting-model : standard (isotropy / anisotropy pbr)
|
|
// shader stage : fs
|
|
// technique usage/type : render-to-scene
|
|
|
|
precision highp float;
|
|
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
|
|
#include <macro-remapping>
|
|
#include <surfaces/effect-macros/common-macros>
|
|
|
|
// 2. common include with corresponding shader stage, include before surface functions
|
|
#include <surfaces/includes/common-fs>
|
|
|
|
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
|
|
// see surfaces/default-functions/xxx.chunk
|
|
#include <shared-ubos>
|
|
#include <surface-fragment>
|
|
|
|
// 4. lighting-model (optional)
|
|
#include <lighting-models/includes/standard>
|
|
|
|
// 5. surface include with corresponding shader stage and shading-model (optional)
|
|
#include <surfaces/includes/standard-fs>
|
|
|
|
// 6. shader entry with corresponding shader stage and technique usage/type
|
|
#include <shading-entries/main-functions/render-to-scene/fs>
|
|
}%
|
|
|
|
CCProgram shadow-caster-fs %{
|
|
precision highp float;
|
|
#include <macro-remapping>
|
|
#include <surfaces/effect-macros/render-to-shadowmap>
|
|
#include <surfaces/includes/common-fs>
|
|
#include <shared-ubos>
|
|
#include <surface-fragment>
|
|
#include <shading-entries/main-functions/render-to-shadowmap/fs>
|
|
}%
|
|
|
|
CCProgram reflect-map-fs %{
|
|
precision highp float;
|
|
#include <macro-remapping>
|
|
#include <surfaces/effect-macros/common-macros>
|
|
#include <surfaces/includes/common-fs>
|
|
#include <shared-ubos>
|
|
#include <surface-fragment>
|
|
#include <lighting-models/includes/standard>
|
|
#include <surfaces/includes/standard-fs>
|
|
#include <shading-entries/main-functions/render-to-reflectmap/fs>
|
|
}%
|