mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Add spot light shadow for 3D (#7643)
This commit is contained in:
committed by
GitHub
parent
0c8ebc83bc
commit
3c669c4d9f
@@ -4,11 +4,11 @@ export default [
|
||||
{
|
||||
"name": "billboard",
|
||||
"techniques": [
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "billboard|vert:vs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "builtin-billboard|vert:vs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "billboard|vert:vs_main|tinted-fs:add",
|
||||
"name": "builtin-billboard|vert:vs_main|tinted-fs:add",
|
||||
"hash": 2143664850,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -44,11 +44,11 @@ export default [
|
||||
{
|
||||
"name": "clear-stencil",
|
||||
"techniques": [
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true }] }, "rasterizerState": { "cullMode": 0 }, "program": "clear-stencil|sprite-vs:vert|sprite-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true }] }, "rasterizerState": { "cullMode": 0 }, "program": "builtin-clear-stencil|sprite-vs:vert|sprite-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "clear-stencil|sprite-vs:vert|sprite-fs:frag",
|
||||
"name": "builtin-clear-stencil|sprite-vs:vert|sprite-fs:frag",
|
||||
"hash": 1062464958,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [], "samplers": [] },
|
||||
@@ -66,11 +66,11 @@ export default [
|
||||
{
|
||||
"name": "graphics",
|
||||
"techniques": [
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 4, "blendSrcAlpha": 1, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "graphics|vs:vert|fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 4, "blendSrcAlpha": 1, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "builtin-graphics|vs:vert|fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "graphics|vs:vert|fs:frag",
|
||||
"name": "builtin-graphics|vs:vert|fs:frag",
|
||||
"hash": 3946667351,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -90,11 +90,11 @@ export default [
|
||||
{
|
||||
"name": "particle-gpu",
|
||||
"techniques": [
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "builtin-particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add",
|
||||
"name": "builtin-particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add",
|
||||
"hash": 3696836305,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -175,11 +175,11 @@ export default [
|
||||
{
|
||||
"name": "particle-trail",
|
||||
"techniques": [
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "particle-trail|particle-trail:vs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "frameTile_velLenScale": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "frameTile_velLenScale": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "particle-trail|particle-trail:vs_main|tinted-fs:add",
|
||||
"name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add",
|
||||
"hash": 4115155772,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -217,11 +217,11 @@ export default [
|
||||
{
|
||||
"name": "particle",
|
||||
"techniques": [
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
{ "name": "add", "passes": [{ "rasterizerState": { "cullMode": 0 }, "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 1, "blendSrcAlpha": 2, "blendDstAlpha": 1 }] }, "program": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "depthStencilState": { "depthTest": true, "depthWrite": false }, "properties": { "mainTexture": { "value": "grey", "type": 28 }, "mainTiling_Offset": { "value": [1, 1, 0, 0], "type": 16 }, "tintColor": { "value": [0.5, 0.5, 0.5, 0.5], "type": 16 } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
|
||||
"name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
|
||||
"hash": 66662317,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -261,11 +261,11 @@ export default [
|
||||
{
|
||||
"name": "sprite",
|
||||
"techniques": [
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "sprite|sprite-vs:vert|sprite-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false }, "properties": { "alphaThreshold": { "value": [0.5], "type": 13 } } }] }
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false }, "properties": { "alphaThreshold": { "value": [0.5], "type": 13 } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "sprite|sprite-vs:vert|sprite-fs:frag",
|
||||
"name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag",
|
||||
"hash": 3640649043,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -296,15 +296,15 @@ export default [
|
||||
{
|
||||
"name": "standard",
|
||||
"techniques": [
|
||||
{ "name": "opaque", "passes": [{ "program": "standard|standard-vs:vert|standard-fs:frag", "properties": { "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16, "handleInfo": ["albedo", 0, 16] }, "albedoScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["albedoScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["albedoScaleAndCutoff", 3, 13] }, "occlusion": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 0, 13] }, "roughness": { "value": [0.8], "type": 13, "handleInfo": ["pbrParams", 1, 13] }, "metallic": { "value": [0.6], "type": 13, "handleInfo": ["pbrParams", 2, 13] }, "normalStrenth": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 3, 13] }, "emissive": { "value": [0, 0, 0, 1], "type": 16 }, "emissiveScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["emissiveScaleParam", 0, 15] }, "mainTexture": { "value": "grey", "type": 28, "handleInfo": ["albedoMap", 0, 28] }, "normalMap": { "value": "normal", "type": 28 }, "pbrMap": { "value": "grey", "type": 28 }, "metallicRoughnessMap": { "value": "grey", "type": 28 }, "occlusionMap": { "value": "white", "type": 28 }, "emissiveMap": { "value": "grey", "type": 28 }, "albedo": { "type": 16, "value": [1, 1, 1, 1] }, "albedoScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] }, "pbrParams": { "type": 16, "value": [1, 0.8, 0.6, 1] }, "emissiveScaleParam": { "type": 16, "value": [1, 1, 1, 0] }, "albedoMap": { "type": 28, "value": "grey" } } }, { "phase": "forward-add", "propertyIndex": 0, "embeddedMacros": { "CC_FORWARD_ADD": true }, "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 1, "blendSrcAlpha": 0, "blendDstAlpha": 1 }] }, "program": "standard|standard-vs:vert|standard-fs:frag", "depthStencilState": { "depthFunc": 2, "depthTest": true, "depthWrite": false }, "properties": { "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16, "handleInfo": ["albedo", 0, 16] }, "albedoScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["albedoScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["albedoScaleAndCutoff", 3, 13] }, "occlusion": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 0, 13] }, "roughness": { "value": [0.8], "type": 13, "handleInfo": ["pbrParams", 1, 13] }, "metallic": { "value": [0.6], "type": 13, "handleInfo": ["pbrParams", 2, 13] }, "normalStrenth": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 3, 13] }, "emissive": { "value": [0, 0, 0, 1], "type": 16 }, "emissiveScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["emissiveScaleParam", 0, 15] }, "mainTexture": { "value": "grey", "type": 28, "handleInfo": ["albedoMap", 0, 28] }, "normalMap": { "value": "normal", "type": 28 }, "pbrMap": { "value": "grey", "type": 28 }, "metallicRoughnessMap": { "value": "grey", "type": 28 }, "occlusionMap": { "value": "white", "type": 28 }, "emissiveMap": { "value": "grey", "type": 28 }, "albedo": { "type": 16, "value": [1, 1, 1, 1] }, "albedoScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] }, "pbrParams": { "type": 16, "value": [1, 0.8, 0.6, 1] }, "emissiveScaleParam": { "type": 16, "value": [1, 1, 1, 0] }, "albedoMap": { "type": 28, "value": "grey" } } }, { "phase": "shadow-caster", "propertyIndex": 0, "rasterizerState": { "cullMode": 1 }, "program": "standard|shadow-caster-vs:vert|shadow-caster-fs:frag" }] }
|
||||
{ "name": "opaque", "passes": [{ "program": "builtin-standard|standard-vs:vert|standard-fs:frag", "properties": { "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16, "handleInfo": ["albedo", 0, 16] }, "albedoScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["albedoScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["albedoScaleAndCutoff", 3, 13] }, "occlusion": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 0, 13] }, "roughness": { "value": [0.8], "type": 13, "handleInfo": ["pbrParams", 1, 13] }, "metallic": { "value": [0.6], "type": 13, "handleInfo": ["pbrParams", 2, 13] }, "normalStrenth": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 3, 13] }, "emissive": { "value": [0, 0, 0, 1], "type": 16 }, "emissiveScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["emissiveScaleParam", 0, 15] }, "mainTexture": { "value": "grey", "type": 28, "handleInfo": ["albedoMap", 0, 28] }, "normalMap": { "value": "normal", "type": 28 }, "pbrMap": { "value": "grey", "type": 28 }, "metallicRoughnessMap": { "value": "grey", "type": 28 }, "occlusionMap": { "value": "white", "type": 28 }, "emissiveMap": { "value": "grey", "type": 28 }, "albedo": { "type": 16, "value": [1, 1, 1, 1] }, "albedoScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] }, "pbrParams": { "type": 16, "value": [1, 0.8, 0.6, 1] }, "emissiveScaleParam": { "type": 16, "value": [1, 1, 1, 0] }, "albedoMap": { "type": 28, "value": "grey" } } }, { "phase": "forward-add", "propertyIndex": 0, "embeddedMacros": { "CC_FORWARD_ADD": true }, "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 1, "blendSrcAlpha": 0, "blendDstAlpha": 1 }] }, "program": "builtin-standard|standard-vs:vert|standard-fs:frag", "depthStencilState": { "depthFunc": 2, "depthTest": true, "depthWrite": false }, "properties": { "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16, "handleInfo": ["albedo", 0, 16] }, "albedoScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["albedoScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["albedoScaleAndCutoff", 3, 13] }, "occlusion": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 0, 13] }, "roughness": { "value": [0.8], "type": 13, "handleInfo": ["pbrParams", 1, 13] }, "metallic": { "value": [0.6], "type": 13, "handleInfo": ["pbrParams", 2, 13] }, "normalStrenth": { "value": [1], "type": 13, "handleInfo": ["pbrParams", 3, 13] }, "emissive": { "value": [0, 0, 0, 1], "type": 16 }, "emissiveScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["emissiveScaleParam", 0, 15] }, "mainTexture": { "value": "grey", "type": 28, "handleInfo": ["albedoMap", 0, 28] }, "normalMap": { "value": "normal", "type": 28 }, "pbrMap": { "value": "grey", "type": 28 }, "metallicRoughnessMap": { "value": "grey", "type": 28 }, "occlusionMap": { "value": "white", "type": 28 }, "emissiveMap": { "value": "grey", "type": 28 }, "albedo": { "type": 16, "value": [1, 1, 1, 1] }, "albedoScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] }, "pbrParams": { "type": 16, "value": [1, 0.8, 0.6, 1] }, "emissiveScaleParam": { "type": 16, "value": [1, 1, 1, 0] }, "albedoMap": { "type": 28, "value": "grey" } } }, { "phase": "shadow-caster", "propertyIndex": 0, "rasterizerState": { "cullMode": 1 }, "program": "builtin-standard|shadow-caster-vs:vert|shadow-caster-fs:frag" }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "standard|standard-vs:vert|standard-fs:frag",
|
||||
"hash": 3299871340,
|
||||
"name": "builtin-standard|standard-vs:vert|standard-fs:frag",
|
||||
"hash": 21874207,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_shadowMap", "defines": ["!CC_FORWARD_ADD", "CC_RECEIVE_SHADOW"] }] },
|
||||
"locals": { "blocks": [{ "name": "CCMorph", "defines": ["CC_USE_MORPH"] }, { "name": "CCSkinningTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinningAnimation", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinning", "defines": ["CC_USE_SKINNING", "!CC_USE_BAKED_ANIMATION"] }, { "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD"] }], "samplers": [{ "name": "cc_PositionDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_POSITION"] }, { "name": "cc_NormalDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_NORMAL"] }, { "name": "cc_TangentDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_TANGENT"] }, { "name": "cc_jointTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "cc_lightingMap", "defines": ["USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }] }
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }] },
|
||||
"locals": { "blocks": [{ "name": "CCMorph", "defines": ["CC_USE_MORPH"] }, { "name": "CCSkinningTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinningAnimation", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinning", "defines": ["CC_USE_SKINNING", "!CC_USE_BAKED_ANIMATION"] }, { "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD"] }], "samplers": [{ "name": "cc_PositionDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_POSITION"] }, { "name": "cc_NormalDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_NORMAL"] }, { "name": "cc_TangentDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_TANGENT"] }, { "name": "cc_jointTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_lightingMap", "defines": ["USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }] }
|
||||
},
|
||||
"defines": [
|
||||
{ "name": "CC_USE_MORPH", "type": "boolean" },
|
||||
@@ -376,8 +376,8 @@ export default [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "standard|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
||||
"hash": 1605919020,
|
||||
"name": "builtin-standard|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
||||
"hash": 3020491,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCShadow", "defines": [] }], "samplers": [] },
|
||||
"locals": { "blocks": [{ "name": "CCMorph", "defines": ["CC_USE_MORPH"] }, { "name": "CCSkinningTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinningAnimation", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinning", "defines": ["CC_USE_SKINNING", "!CC_USE_BAKED_ANIMATION"] }, { "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }], "samplers": [{ "name": "cc_PositionDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_POSITION"] }, { "name": "cc_NormalDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_NORMAL"] }, { "name": "cc_TangentDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_TANGENT"] }, { "name": "cc_jointTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }] }
|
||||
@@ -436,15 +436,15 @@ export default [
|
||||
{
|
||||
"name": "terrain",
|
||||
"techniques": [
|
||||
{ "name": "opaque", "passes": [{ "program": "terrain|terrain-vs:vert|terrain-fs:frag", "properties": { "UVScale": { "value": [1, 1, 1, 1], "type": 16 }, "lightMapUVParam": { "value": [0, 0, 0, 0], "type": 16 }, "weightMap": { "value": "black", "type": 28 }, "detailMap0": { "value": "grey", "type": 28 }, "detailMap1": { "value": "grey", "type": 28 }, "detailMap2": { "value": "grey", "type": 28 }, "detailMap3": { "value": "grey", "type": 28 }, "lightMap": { "value": "grey", "type": 28 } } }, { "phase": "forward-add", "propertyIndex": 0, "embeddedMacros": { "CC_FORWARD_ADD": true }, "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 1, "blendSrcAlpha": 0, "blendDstAlpha": 1 }] }, "program": "terrain|terrain-vs:vert|terrain-fs:frag", "depthStencilState": { "depthFunc": 2, "depthTest": true, "depthWrite": false }, "properties": { "UVScale": { "value": [1, 1, 1, 1], "type": 16 }, "lightMapUVParam": { "value": [0, 0, 0, 0], "type": 16 }, "weightMap": { "value": "black", "type": 28 }, "detailMap0": { "value": "grey", "type": 28 }, "detailMap1": { "value": "grey", "type": 28 }, "detailMap2": { "value": "grey", "type": 28 }, "detailMap3": { "value": "grey", "type": 28 }, "lightMap": { "value": "grey", "type": 28 } } }, { "phase": "shadow-add", "propertyIndex": 0, "rasterizerState": { "cullMode": 2 }, "program": "terrain|shadow-caster-vs:vert|shadow-caster-fs:frag" }] }
|
||||
{ "name": "opaque", "passes": [{ "program": "builtin-terrain|terrain-vs:vert|terrain-fs:frag", "properties": { "UVScale": { "value": [1, 1, 1, 1], "type": 16 }, "lightMapUVParam": { "value": [0, 0, 0, 0], "type": 16 }, "weightMap": { "value": "black", "type": 28 }, "detailMap0": { "value": "grey", "type": 28 }, "detailMap1": { "value": "grey", "type": 28 }, "detailMap2": { "value": "grey", "type": 28 }, "detailMap3": { "value": "grey", "type": 28 }, "lightMap": { "value": "grey", "type": 28 } } }, { "phase": "forward-add", "propertyIndex": 0, "embeddedMacros": { "CC_FORWARD_ADD": true }, "blendState": { "targets": [{ "blend": true, "blendSrc": 1, "blendDst": 1, "blendSrcAlpha": 0, "blendDstAlpha": 1 }] }, "program": "builtin-terrain|terrain-vs:vert|terrain-fs:frag", "depthStencilState": { "depthFunc": 2, "depthTest": true, "depthWrite": false }, "properties": { "UVScale": { "value": [1, 1, 1, 1], "type": 16 }, "lightMapUVParam": { "value": [0, 0, 0, 0], "type": 16 }, "weightMap": { "value": "black", "type": 28 }, "detailMap0": { "value": "grey", "type": 28 }, "detailMap1": { "value": "grey", "type": 28 }, "detailMap2": { "value": "grey", "type": 28 }, "detailMap3": { "value": "grey", "type": 28 }, "lightMap": { "value": "grey", "type": 28 } } }, { "phase": "shadow-add", "propertyIndex": 0, "rasterizerState": { "cullMode": 2 }, "program": "builtin-terrain|shadow-caster-vs:vert|shadow-caster-fs:frag" }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "terrain|terrain-vs:vert|terrain-fs:frag",
|
||||
"hash": 1355930085,
|
||||
"name": "builtin-terrain|terrain-vs:vert|terrain-fs:frag",
|
||||
"hash": 3410959967,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_shadowMap", "defines": ["!CC_FORWARD_ADD", "CC_RECEIVE_SHADOW"] }] },
|
||||
"locals": { "blocks": [{ "name": "CCLocal", "defines": [] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD"] }], "samplers": [] }
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }] },
|
||||
"locals": { "blocks": [{ "name": "CCLocal", "defines": [] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD"] }], "samplers": [{ "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }] }
|
||||
},
|
||||
"defines": [
|
||||
{ "name": "CC_USE_FOG", "type": "number", "range": [0, 4] },
|
||||
@@ -477,7 +477,7 @@ export default [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "terrain|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
||||
"name": "builtin-terrain|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
||||
"hash": 3874167763,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [] },
|
||||
@@ -497,11 +497,11 @@ export default [
|
||||
{
|
||||
"name": "unlit",
|
||||
"techniques": [
|
||||
{ "name": "opaque", "passes": [{ "program": "unlit|unlit-vs:vert|unlit-fs:frag", "properties": { "mainTexture": { "value": "grey", "type": 28 }, "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16 }, "colorScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["colorScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["colorScaleAndCutoff", 3, 13] }, "color": { "type": 16, "handleInfo": ["mainColor", 0, 16] }, "colorScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] } } }] }
|
||||
{ "name": "opaque", "passes": [{ "program": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", "properties": { "mainTexture": { "value": "grey", "type": 28 }, "tilingOffset": { "value": [1, 1, 0, 0], "type": 16 }, "mainColor": { "value": [1, 1, 1, 1], "type": 16 }, "colorScale": { "value": [1, 1, 1], "type": 15, "handleInfo": ["colorScaleAndCutoff", 0, 15] }, "alphaThreshold": { "value": [0.5], "type": 13, "handleInfo": ["colorScaleAndCutoff", 3, 13] }, "color": { "type": 16, "handleInfo": ["mainColor", 0, 16] }, "colorScaleAndCutoff": { "type": 16, "value": [1, 1, 1, 0.5] } } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "unlit|unlit-vs:vert|unlit-fs:frag",
|
||||
"name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag",
|
||||
"hash": 561717302,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -562,11 +562,11 @@ export default [
|
||||
{
|
||||
"name": "planar-shadow",
|
||||
"techniques": [
|
||||
{ "passes": [{ "phase": "planarShadow", "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "program": "planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", "depthStencilState": { "depthTest": true, "depthWrite": false, "stencilTestFront": true, "stencilFuncFront": 5, "stencilPassOpFront": 2, "stencilRefBack": 128, "stencilRefFront": 128, "stencilReadMaskBack": 128, "stencilReadMaskFront": 128, "stencilWriteMaskBack": 128, "stencilWriteMaskFront": 128 } }] }
|
||||
{ "passes": [{ "phase": "planarShadow", "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "program": "pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", "depthStencilState": { "depthTest": true, "depthWrite": false, "stencilTestFront": true, "stencilFuncFront": 5, "stencilPassOpFront": 2, "stencilRefBack": 128, "stencilRefFront": 128, "stencilReadMaskBack": 128, "stencilReadMaskFront": 128, "stencilWriteMaskBack": 128, "stencilWriteMaskFront": 128 } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag",
|
||||
"name": "pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag",
|
||||
"hash": 2901856202,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [] },
|
||||
@@ -610,11 +610,11 @@ export default [
|
||||
{
|
||||
"name": "skybox",
|
||||
"techniques": [
|
||||
{ "passes": [{ "rasterizerState": { "cullMode": 0 }, "program": "skybox|sky-vs:vert|sky-fs:frag", "priority": 245, "depthStencilState": { "depthTest": true, "depthWrite": false } }] }
|
||||
{ "passes": [{ "rasterizerState": { "cullMode": 0 }, "program": "pipeline/skybox|sky-vs:vert|sky-fs:frag", "priority": 245, "depthStencilState": { "depthTest": true, "depthWrite": false } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "skybox|sky-vs:vert|sky-fs:frag",
|
||||
"name": "pipeline/skybox|sky-vs:vert|sky-fs:frag",
|
||||
"hash": 2319917655,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": [] }] },
|
||||
@@ -639,11 +639,11 @@ export default [
|
||||
{
|
||||
"name": "profiler",
|
||||
"techniques": [
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "profiler|profiler-vs:vert|profiler-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "util/profiler|profiler-vs:vert|profiler-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "profiler|profiler-vs:vert|profiler-fs:frag",
|
||||
"name": "util/profiler|profiler-vs:vert|profiler-fs:frag",
|
||||
"hash": 2029303284,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] },
|
||||
@@ -673,11 +673,11 @@ export default [
|
||||
{
|
||||
"name": "splash-screen",
|
||||
"techniques": [
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "splash-screen|splash-screen-vs:vert|splash-screen-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
{ "passes": [{ "blendState": { "targets": [{ "blend": true, "blendSrc": 2, "blendDst": 4, "blendDstAlpha": 4 }] }, "rasterizerState": { "cullMode": 0 }, "program": "util/splash-screen|splash-screen-vs:vert|splash-screen-fs:frag", "depthStencilState": { "depthTest": false, "depthWrite": false } }] }
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "splash-screen|splash-screen-vs:vert|splash-screen-fs:frag",
|
||||
"name": "util/splash-screen|splash-screen-vs:vert|splash-screen-fs:frag",
|
||||
"hash": 2106901053,
|
||||
"builtins": {
|
||||
"globals": { "blocks": [], "samplers": [] },
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -32,8 +32,9 @@ import { BufferUsageBit, Format, MemoryUsageBit, Device, DescriptorSet, InputAss
|
||||
InputAssemblerInfo, Attribute, Buffer, BufferInfo } from '../gfx';
|
||||
import { Mat4 } from '../math';
|
||||
import { SubModel } from '../renderer/scene/submodel';
|
||||
import { IRenderObject, UBOLocalBatched } from './define';
|
||||
import { UBOLocalBatched } from './define';
|
||||
import { Pass } from '../renderer';
|
||||
import { Model } from '../renderer/scene';
|
||||
import { SubModelPool, SubModelView, ShaderHandle } from '../renderer/core/memory-pools';
|
||||
|
||||
export interface IBatchedItem {
|
||||
@@ -82,7 +83,7 @@ export class BatchedBuffer {
|
||||
this.batches.length = 0;
|
||||
}
|
||||
|
||||
public merge (subModel: SubModel, passIdx: number, ro: IRenderObject) {
|
||||
public merge (subModel: SubModel, passIdx: number, model: Model) {
|
||||
const flatBuffers = subModel.subMesh.flatBuffers;
|
||||
if (flatBuffers.length === 0) { return; }
|
||||
let vbSize = 0;
|
||||
@@ -137,7 +138,7 @@ export class BatchedBuffer {
|
||||
}
|
||||
|
||||
// update world matrix
|
||||
Mat4.toArray(batch.uboData, ro.model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET + batch.mergeCount * 16);
|
||||
Mat4.toArray(batch.uboData, model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET + batch.mergeCount * 16);
|
||||
if (!batch.mergeCount) {
|
||||
descriptorSet.bindBuffer(UBOLocalBatched.BINDING, batch.ubo);
|
||||
descriptorSet.update();
|
||||
@@ -205,7 +206,7 @@ export class BatchedBuffer {
|
||||
descriptorSet.update();
|
||||
|
||||
const uboData = new Float32Array(UBOLocalBatched.COUNT);
|
||||
Mat4.toArray(uboData, ro.model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET);
|
||||
Mat4.toArray(uboData, model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET);
|
||||
|
||||
this.batches.push({
|
||||
mergeCount: 1,
|
||||
|
||||
@@ -140,6 +140,7 @@ export enum ModelLocalBindings {
|
||||
SAMPLER_MORPH_TANGENT,
|
||||
SAMPLER_LIGHTMAP,
|
||||
SAMPLER_SPRITE,
|
||||
SAMPLER_SPOT_LIGHTING_MAP,
|
||||
|
||||
COUNT,
|
||||
}
|
||||
@@ -469,6 +470,17 @@ const UNIFORM_SPRITE_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM
|
||||
localDescriptorSetLayout.layouts[UNIFORM_SPRITE_TEXTURE_NAME] = UNIFORM_SPRITE_TEXTURE_LAYOUT;
|
||||
localDescriptorSetLayout.bindings[UNIFORM_SPRITE_TEXTURE_BINDING] = UNIFORM_SPRITE_TEXTURE_DESCRIPTOR;
|
||||
|
||||
/**
|
||||
* @en The sampler for spot light shadow map
|
||||
* @zn 聚光灯阴影纹理采样器
|
||||
*/
|
||||
const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME = 'cc_spotLightingMap';
|
||||
export const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_SPOT_LIGHTING_MAP;
|
||||
const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT);
|
||||
const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME, Type.SAMPLER2D, 1);
|
||||
localDescriptorSetLayout.layouts[UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME] = UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_LAYOUT;
|
||||
localDescriptorSetLayout.bindings[UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING] = UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_DESCRIPTOR;
|
||||
|
||||
export const CAMERA_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, Layers.BitMask.GIZMOS, Layers.BitMask.EDITOR,
|
||||
Layers.BitMask.SCENE_GIZMO, Layers.BitMask.PROFILER]);
|
||||
|
||||
|
||||
@@ -33,9 +33,10 @@ import { RenderPipeline, IRenderPipelineInfo } from '../render-pipeline';
|
||||
import { ForwardFlow } from './forward-flow';
|
||||
import { RenderTextureConfig, MaterialConfig } from '../pipeline-serialization';
|
||||
import { ShadowFlow } from '../shadow/shadow-flow';
|
||||
import { IRenderObject, UBOGlobal, UBOShadow } from '../define';
|
||||
import { IRenderObject, UBOGlobal, UBOShadow, UNIFORM_SHADOWMAP_BINDING } from '../define';
|
||||
import { BufferUsageBit, MemoryUsageBit, ClearFlag } from '../../gfx/define';
|
||||
import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, TextureLayout, RenderPassInfo, BufferInfo, Feature } from '../../gfx';
|
||||
import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, TextureLayout,
|
||||
RenderPassInfo, BufferInfo, Feature, Framebuffer } from '../../gfx';
|
||||
import { SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { legacyCC } from '../../global-exports';
|
||||
import { RenderView } from '../render-view';
|
||||
@@ -46,6 +47,7 @@ import { Skybox } from '../../renderer/scene/skybox';
|
||||
import { Shadows, ShadowType } from '../../renderer/scene/shadows';
|
||||
import { sceneCulling, getShadowWorldMatrix } from './scene-culling';
|
||||
import { UIFlow } from '../ui/ui-flow';
|
||||
import { Light } from '../../renderer/scene/light';
|
||||
|
||||
const matShadowView = new Mat4();
|
||||
const matShadowViewProj = new Mat4();
|
||||
@@ -109,6 +111,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
*/
|
||||
public renderObjects: IRenderObject[] = [];
|
||||
public shadowObjects: IRenderObject[] = [];
|
||||
public shadowFrameBufferMap: Map<Light, Framebuffer> = new Map();
|
||||
protected _isHDR: boolean = false;
|
||||
protected _shadingScale: number = 1.0;
|
||||
protected _fpScale: number = 1.0 / 1024.0;
|
||||
@@ -208,6 +211,10 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
const shadowInfo = this.shadows;
|
||||
|
||||
if (mainLight && shadowInfo.type === ShadowType.ShadowMap) {
|
||||
if (this.shadowFrameBufferMap.has(mainLight)) {
|
||||
this._descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, this.shadowFrameBufferMap.get(mainLight)!.colorTextures[0]!);
|
||||
}
|
||||
|
||||
// light view
|
||||
let shadowCameraView: Mat4;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ export class ForwardStage extends RenderStage {
|
||||
this._instancedQueue.queue.add(instancedBuffer);
|
||||
} else if (batchingScheme === BatchingSchemes.VB_MERGING) {
|
||||
const batchedBuffer = BatchedBuffer.get(pass);
|
||||
batchedBuffer.merge(subModel, p, ro);
|
||||
batchedBuffer.merge(subModel, p, ro.model);
|
||||
this._batchedQueue.queue.add(batchedBuffer);
|
||||
} else {
|
||||
for (k = 0; k < this._renderQueues.length; k++) {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* @hidden
|
||||
*/
|
||||
|
||||
import { aabb, intersect, frustum } from '../../geometry';
|
||||
import { aabb, intersect, sphere } from '../../geometry';
|
||||
import { Model } from '../../renderer/scene/model';
|
||||
import { Camera, SKYBOX_FLAG } from '../../renderer/scene/camera';
|
||||
import { Layers } from '../../scene-graph/layers';
|
||||
@@ -38,7 +38,7 @@ import { RenderView } from '../';
|
||||
import { Pool } from '../../memop';
|
||||
import { IRenderObject, UBOShadow } from '../define';
|
||||
import { ShadowType, Shadows } from '../../renderer/scene/shadows';
|
||||
import { SphereLight, DirectionalLight } from '../../renderer/scene';
|
||||
import { SphereLight, DirectionalLight, Light } from '../../renderer/scene';
|
||||
|
||||
const _tempVec3 = new Vec3();
|
||||
const _dir_negate = new Vec3();
|
||||
@@ -46,6 +46,8 @@ const _vec3_p = new Vec3();
|
||||
const _mat4_trans = new Mat4();
|
||||
const _castWorldBounds = new aabb();
|
||||
let _castBoundsInited = false;
|
||||
const _validLights: Light[] = [];
|
||||
const _sphere = sphere.create(0, 0, 0, 1);
|
||||
|
||||
const roPool = new Pool<IRenderObject>(() => ({ model: null!, depth: 0 }), 128);
|
||||
const shadowPool = new Pool<IRenderObject>(() => ({ model: null!, depth: 0 }), 128);
|
||||
@@ -145,6 +147,57 @@ function updateDirLight (pipeline: ForwardPipeline, light: DirectionalLight) {
|
||||
Mat4.toArray(pipeline.shadowUBO, shadows.matLight, UBOShadow.MAT_LIGHT_PLANE_PROJ_OFFSET);
|
||||
}
|
||||
|
||||
export function lightCollecting (view: RenderView, lightNumber: number) {
|
||||
_validLights.length = 0;
|
||||
|
||||
const camera = view.camera;
|
||||
const scene = camera.scene!;
|
||||
_validLights.push(scene.mainLight!);
|
||||
|
||||
const spotLights = scene.spotLights;
|
||||
for (let i = 0; i < spotLights.length; i++) {
|
||||
const light = spotLights[i];
|
||||
sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range);
|
||||
if (intersect.sphere_frustum(_sphere, view.camera.frustum) &&
|
||||
lightNumber > _validLights.length) {
|
||||
_validLights.push(light);
|
||||
}
|
||||
}
|
||||
|
||||
return _validLights;
|
||||
}
|
||||
|
||||
export function shadowCollecting (pipeline: ForwardPipeline, view: RenderView) {
|
||||
const camera = view.camera;
|
||||
const scene = camera.scene!;
|
||||
const shadows = pipeline.shadows;
|
||||
const shadowObjects = pipeline.shadowObjects;
|
||||
shadowPool.freeArray(shadowObjects); shadowObjects.length = 0;
|
||||
|
||||
_castBoundsInited = false;
|
||||
|
||||
const models = scene.models;
|
||||
for (let i = 0; i < models.length; i++) {
|
||||
const model = models[i];
|
||||
// filter model by view visibility
|
||||
if (model.node && ((view.visibility & model.node.layer) === model.node.layer) ||
|
||||
(view.visibility & model.visFlags)) {
|
||||
|
||||
// shadow render Object
|
||||
if (model.castShadow && model.worldBounds) {
|
||||
if (!_castBoundsInited) {
|
||||
_castWorldBounds.copy(model.worldBounds);
|
||||
_castBoundsInited = true;
|
||||
}
|
||||
aabb.merge(_castWorldBounds, _castWorldBounds, model.worldBounds);
|
||||
shadowObjects.push(getCastShadowRenderObject(model, camera));
|
||||
}
|
||||
}
|
||||
|
||||
if (_castWorldBounds) { aabb.toBoundingSphere(shadows.sphere, _castWorldBounds); }
|
||||
}
|
||||
}
|
||||
|
||||
export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
const camera = view.camera;
|
||||
const scene = camera.scene!;
|
||||
@@ -153,12 +206,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
|
||||
const renderObjects = pipeline.renderObjects;
|
||||
roPool.freeArray(renderObjects); renderObjects.length = 0;
|
||||
const shadowObjects = pipeline.shadowObjects;
|
||||
shadowPool.freeArray(shadowObjects); shadowObjects.length = 0;
|
||||
|
||||
// Each time the calculation,
|
||||
// reset the flag.
|
||||
_castBoundsInited = false;
|
||||
|
||||
if (shadows.enabled) {
|
||||
Color.toArray(pipeline.shadowUBO, shadows.shadowColor, UBOShadow.SHADOW_COLOR_OFFSET);
|
||||
@@ -191,16 +238,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
if (model.node && ((view.visibility & model.node.layer) === model.node.layer) ||
|
||||
(view.visibility & model.visFlags)) {
|
||||
|
||||
// shadow render Object
|
||||
if (model.castShadow && model.worldBounds) {
|
||||
if (!_castBoundsInited) {
|
||||
_castWorldBounds.copy(model.worldBounds);
|
||||
_castBoundsInited = true;
|
||||
}
|
||||
aabb.merge(_castWorldBounds, _castWorldBounds, model.worldBounds);
|
||||
shadowObjects.push(getCastShadowRenderObject(model, camera));
|
||||
}
|
||||
|
||||
// frustum culling
|
||||
if (model.worldBounds && !intersect.aabb_frustum(model.worldBounds, camera.frustum)) {
|
||||
continue;
|
||||
@@ -211,8 +248,4 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_castWorldBounds) {
|
||||
aabb.toBoundingSphere(shadows.sphere, _castWorldBounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,18 @@
|
||||
* @packageDocumentation
|
||||
* @module pipeline
|
||||
*/
|
||||
|
||||
import { BatchedBuffer } from './batched-buffer';
|
||||
import { BatchingSchemes } from '../renderer/core/pass';
|
||||
import { ForwardPipeline } from './forward/forward-pipeline';
|
||||
import { InstancedBuffer } from './instanced-buffer';
|
||||
import { Model } from '../renderer/scene/model';
|
||||
import { PipelineStateManager } from './pipeline-state-manager';
|
||||
import { DSPool, ShaderPool, PassView, PassPool, SubModelPool, SubModelView,
|
||||
ShaderHandle } from '../renderer/core/memory-pools';
|
||||
import { Vec3, nextPow2, Mat4, Vec4, Color } from '../../core/math';
|
||||
import { sphere, intersect } from '../geometry';
|
||||
import { Device, RenderPass, Buffer, BufferUsageBit, MemoryUsageBit,
|
||||
BufferInfo, BufferViewInfo, CommandBuffer, Filter, Address, Sampler, DescriptorSet } from '../gfx';
|
||||
import { Pool } from '../memop';
|
||||
import { RenderBatchedQueue } from './render-batched-queue';
|
||||
import { RenderInstancedQueue } from './render-instanced-queue';
|
||||
@@ -42,29 +47,36 @@ import { SphereLight } from '../renderer/scene/sphere-light';
|
||||
import { SpotLight } from '../renderer/scene/spot-light';
|
||||
import { SubModel } from '../renderer/scene/submodel';
|
||||
import { getPhaseID } from './pass-phase';
|
||||
import {
|
||||
Buffer, BufferInfo, BufferUsageBit, BufferViewInfo, CommandBuffer, Device, MemoryUsageBit, RenderPass,
|
||||
} from '../gfx';
|
||||
import {
|
||||
DSPool, PassPool, PassView, ShaderHandle, ShaderPool, SubModelPool, SubModelView,
|
||||
} from '../renderer/core/memory-pools';
|
||||
import { IRenderObject, SetIndex, UBOForwardLight } from './define';
|
||||
import { genSamplerHash, samplerLib } from '../renderer';
|
||||
import { ShadowType } from '../renderer/scene/shadows';
|
||||
import { Light, LightType } from '../renderer/scene/light';
|
||||
import { Vec3, nextPow2 } from '../math';
|
||||
import { intersect, sphere } from '../geometry';
|
||||
import { IRenderObject, SetIndex, UBOForwardLight, UBOShadow, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from './define';
|
||||
|
||||
const _samplerInfo = [
|
||||
Filter.LINEAR,
|
||||
Filter.LINEAR,
|
||||
Filter.NONE,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
Address.CLAMP,
|
||||
];
|
||||
|
||||
interface IAdditiveLightPass {
|
||||
subModel: SubModel;
|
||||
passIdx: number;
|
||||
dynamicOffsets: number[];
|
||||
lights: Light[];
|
||||
}
|
||||
|
||||
const _lightPassPool = new Pool<IAdditiveLightPass>(() => ({ subModel: null!, passIdx: -1, dynamicOffsets: [] }), 16);
|
||||
const _lightPassPool = new Pool<IAdditiveLightPass>(() => ({ subModel: null!, passIdx: -1, dynamicOffsets: [], lights: []}), 16);
|
||||
|
||||
const _vec4Array = new Float32Array(4);
|
||||
const _sphere = sphere.create(0, 0, 0, 1);
|
||||
const _dynamicOffsets: number[] = [];
|
||||
const _lightIndices: number[] = [];
|
||||
const _matShadowView = new Mat4();
|
||||
const _matShadowViewProj = new Mat4();
|
||||
const _vec4ShadowInfo = new Vec4();
|
||||
|
||||
function cullSphereLight (light: SphereLight, model: Model) {
|
||||
return !!(model.worldBounds && !intersect.aabb_aabb(model.worldBounds, light.aabb));
|
||||
@@ -99,6 +111,7 @@ function getLightPassIndices (subModels: SubModel[], lightPassIndices: number[])
|
||||
* @zh 叠加光照队列。
|
||||
*/
|
||||
export class RenderAdditiveLightQueue {
|
||||
private _pipeline: ForwardPipeline;
|
||||
private _device: Device;
|
||||
|
||||
private _validLights: Light[] = [];
|
||||
@@ -127,9 +140,11 @@ export class RenderAdditiveLightQueue {
|
||||
|
||||
private _batchedQueue: RenderBatchedQueue;
|
||||
|
||||
private _lightMeterScale = 10000.0;
|
||||
private _lightMeterScale: number = 10000.0;
|
||||
private _sampler: Sampler | null = null;
|
||||
|
||||
constructor (pipeline: ForwardPipeline) {
|
||||
this._pipeline = pipeline;
|
||||
this._device = pipeline.device;
|
||||
this._isHDR = pipeline.isHDR;
|
||||
this._fpScale = pipeline.fpScale;
|
||||
@@ -150,6 +165,9 @@ export class RenderAdditiveLightQueue {
|
||||
this._firstlightBufferView = this._device.createBuffer(new BufferViewInfo(this._lightBuffer, 0, UBOForwardLight.SIZE));
|
||||
|
||||
this._lightBufferData = new Float32Array(this._lightBufferElementCount * this._lightBufferCount);
|
||||
|
||||
const shadowMapSamplerHash = genSamplerHash(_samplerInfo);
|
||||
this._sampler = samplerLib.getSampler(this._device, shadowMapSamplerHash);
|
||||
}
|
||||
|
||||
public gatherLightPasses (view: RenderView, cmdBuff: CommandBuffer) {
|
||||
@@ -163,6 +181,7 @@ export class RenderAdditiveLightQueue {
|
||||
for (let i = 0; i < this._lightPasses.length; i++) {
|
||||
const lp = this._lightPasses[i];
|
||||
lp.dynamicOffsets.length = 0;
|
||||
lp.lights.length = 0;
|
||||
}
|
||||
_lightPassPool.freeArray(this._lightPasses);
|
||||
this._lightPasses.length = 0;
|
||||
@@ -234,7 +253,7 @@ export class RenderAdditiveLightQueue {
|
||||
for (let l = 0; l < _lightIndices.length; l++) {
|
||||
const idx = _lightIndices[l];
|
||||
const buffer = BatchedBuffer.get(pass, idx);
|
||||
buffer.merge(subModel, lightPassIdx, ro);
|
||||
buffer.merge(subModel, lightPassIdx, model);
|
||||
buffer.dynamicOffsets[0] = this._lightBufferStride * idx;
|
||||
this._batchedQueue.queue.add(buffer);
|
||||
}
|
||||
@@ -243,6 +262,7 @@ export class RenderAdditiveLightQueue {
|
||||
lp.subModel = subModel;
|
||||
lp.passIdx = lightPassIdx;
|
||||
for (let l = 0; l < _lightIndices.length; l++) {
|
||||
lp.lights.push(validLights[l]);
|
||||
lp.dynamicOffsets.push(this._lightBufferStride * _lightIndices[l]);
|
||||
}
|
||||
|
||||
@@ -259,7 +279,7 @@ export class RenderAdditiveLightQueue {
|
||||
this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff);
|
||||
|
||||
for (let i = 0; i < this._lightPasses.length; i++) {
|
||||
const { subModel, passIdx, dynamicOffsets } = this._lightPasses[i];
|
||||
const { subModel, passIdx, dynamicOffsets, lights } = this._lightPasses[i];
|
||||
const shader = ShaderPool.get(SubModelPool.get(subModel.handle, SubModelView.SHADER_0 + passIdx) as ShaderHandle);
|
||||
const pass = subModel.passes[passIdx];
|
||||
const ia = subModel.inputAssembler;
|
||||
@@ -272,6 +292,11 @@ export class RenderAdditiveLightQueue {
|
||||
cmdBuff.bindInputAssembler(ia);
|
||||
|
||||
for (let j = 0; j < dynamicOffsets.length; ++j) {
|
||||
const light = lights[j];
|
||||
if (light.type === LightType.SPOT && this._pipeline.shadowFrameBufferMap.has(light) &&
|
||||
this._pipeline.shadows.type === ShadowType.ShadowMap) {
|
||||
this._updateShadowUBO(localDS, light);
|
||||
}
|
||||
_dynamicOffsets[0] = dynamicOffsets[j];
|
||||
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, localDS, _dynamicOffsets);
|
||||
cmdBuff.draw(ia);
|
||||
@@ -279,6 +304,33 @@ export class RenderAdditiveLightQueue {
|
||||
}
|
||||
}
|
||||
|
||||
// update spot light UBO
|
||||
protected _updateShadowUBO (descriptorSet: DescriptorSet, light: Light) {
|
||||
const shadowInfo = this._pipeline.shadows;
|
||||
const shadowUBO = this._pipeline.shadowUBO;
|
||||
const spotLight = light as SpotLight;
|
||||
// light view
|
||||
Mat4.invert(_matShadowView, spotLight.node!.getWorldMatrix());
|
||||
|
||||
// light proj
|
||||
Mat4.perspective(_matShadowViewProj, spotLight.spotAngle, spotLight.aspect, 0.001, spotLight.range);
|
||||
|
||||
// light viewProj
|
||||
Mat4.multiply(_matShadowViewProj, _matShadowViewProj, _matShadowView);
|
||||
|
||||
Mat4.toArray(shadowUBO, _matShadowViewProj, UBOShadow.MAT_LIGHT_VIEW_PROJ_OFFSET);
|
||||
|
||||
Color.toArray(shadowUBO, shadowInfo.shadowColor, UBOShadow.SHADOW_COLOR_OFFSET);
|
||||
|
||||
_vec4ShadowInfo.set(shadowInfo.size.x, shadowInfo.size.y, shadowInfo.pcf, shadowInfo.bias / 100.0);
|
||||
Vec4.toArray(shadowUBO, _vec4ShadowInfo, UBOShadow.SHADOW_INFO_OFFSET);
|
||||
|
||||
descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, this._pipeline.shadowFrameBufferMap.get(light)!.colorTextures[0]!);
|
||||
descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, this._sampler!);
|
||||
descriptorSet.update();
|
||||
this._pipeline.descriptorSet.getBuffer(UBOShadow.BINDING).update(shadowUBO);
|
||||
}
|
||||
|
||||
protected _updateUBOs (view: RenderView, cmdBuff: CommandBuffer) {
|
||||
const { exposure } = view.camera;
|
||||
|
||||
|
||||
@@ -29,70 +29,143 @@
|
||||
*/
|
||||
|
||||
import { SubModel } from '../renderer/scene/submodel';
|
||||
import { IRenderObject, SetIndex } from './define';
|
||||
import { Device, RenderPass, Buffer, Shader, CommandBuffer } from '../gfx';
|
||||
import { IRenderObject, SetIndex, UBOShadow } from './define';
|
||||
import { Device, RenderPass, Buffer, Shader, CommandBuffer, DescriptorSet } from '../gfx';
|
||||
import { getPhaseID } from './pass-phase';
|
||||
import { PipelineStateManager } from './pipeline-state-manager';
|
||||
import { DSPool, ShaderPool, PassPool, PassView, SubModelPool, SubModelView, ShaderHandle } from '../renderer/core/memory-pools';
|
||||
import { ShaderPool, SubModelPool, SubModelView, ShaderHandle } from '../renderer/core/memory-pools';
|
||||
import { Pass } from '../renderer/core/pass';
|
||||
import { RenderInstancedQueue } from './render-instanced-queue';
|
||||
import { BatchingSchemes } from '../renderer/core/pass';
|
||||
import { InstancedBuffer } from './instanced-buffer';
|
||||
import { RenderBatchedQueue } from './render-batched-queue';
|
||||
import { BatchedBuffer } from './batched-buffer';
|
||||
import { Color, Mat4, Vec4, Vec3 } from '../math';
|
||||
import { Shadows, ShadowType } from '../renderer/scene/shadows';
|
||||
import { ForwardPipeline } from './forward/forward-pipeline';
|
||||
import { Light, LightType } from '../renderer/scene/light';
|
||||
import { SpotLight } from '../renderer/scene/spot-light';
|
||||
import { intersect } from '../geometry';
|
||||
import { Model } from '../renderer/scene/model';
|
||||
import { DirectionalLight } from '../renderer/scene/directional-light';
|
||||
import { getShadowWorldMatrix } from './forward/scene-culling';
|
||||
|
||||
const _matShadowView = new Mat4();
|
||||
const _matShadowViewProj = new Mat4();
|
||||
const _vec4ShadowInfo = new Vec4();
|
||||
const _vec3Center = new Vec3();
|
||||
|
||||
const _phaseID = getPhaseID('shadow-caster');
|
||||
function getShadowPassIndex (subModels: SubModel[]) {
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const passes = subModels[j].passes;
|
||||
for (let k = 0; k < passes.length; k++) {
|
||||
if (passes[k].phase === _phaseID) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 阴影渲染队列
|
||||
*/
|
||||
export class RenderShadowMapBatchedQueue {
|
||||
private _pipeline: ForwardPipeline;
|
||||
private _subModelsArray: SubModel[] = [];
|
||||
private _passArray: Pass[] = [];
|
||||
private _shaderArray: Shader[] = [];
|
||||
private _shadowMapBuffer: Buffer | null = null;
|
||||
private _phaseID = getPhaseID('shadow-caster');
|
||||
private _instancedQueue: RenderInstancedQueue = new RenderInstancedQueue();
|
||||
private _batchedQueue: RenderBatchedQueue = new RenderBatchedQueue();
|
||||
private _shadowMapBuffer: Buffer;
|
||||
|
||||
// changes
|
||||
private _device: Device;
|
||||
private _shadowInfo: Shadows;
|
||||
private _descriptorSet: DescriptorSet;
|
||||
private _shadowObjects: IRenderObject[];
|
||||
private _shadowUBO: Float32Array;
|
||||
private _instancedQueue: RenderInstancedQueue;
|
||||
private _batchedQueue: RenderBatchedQueue;
|
||||
|
||||
|
||||
public constructor (pipeline: ForwardPipeline) {
|
||||
this._pipeline = pipeline;
|
||||
this._device = pipeline.device;
|
||||
this._shadowInfo = pipeline.shadows;
|
||||
this._descriptorSet = pipeline.descriptorSet;
|
||||
this._shadowObjects = pipeline.shadowObjects;
|
||||
this._shadowUBO = pipeline.shadowUBO;
|
||||
this._shadowMapBuffer = pipeline.descriptorSet.getBuffer(UBOShadow.BINDING);
|
||||
|
||||
this._instancedQueue = new RenderInstancedQueue();
|
||||
this._batchedQueue = new RenderBatchedQueue();
|
||||
}
|
||||
|
||||
public gatherLightPasses (light: Light) {
|
||||
this.clear();
|
||||
if (light && this._shadowInfo.type === ShadowType.ShadowMap) {
|
||||
this._updateUBOs(light);
|
||||
|
||||
for (let i = 0; i < this._shadowObjects.length; i++) {
|
||||
const ro = this._shadowObjects[i];
|
||||
const model = ro.model;
|
||||
|
||||
switch (light.type) {
|
||||
case LightType.DIRECTIONAL:
|
||||
this.add(model);
|
||||
break;
|
||||
case LightType.SPOT:
|
||||
const spotLight = light as SpotLight;
|
||||
if ((model.worldBounds &&
|
||||
(!intersect.aabb_aabb(model.worldBounds, spotLight.aabb) ||
|
||||
!intersect.aabb_frustum(model.worldBounds, spotLight.frustum)))) continue;
|
||||
this.add(model);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* clear ligth-Batched-Queue
|
||||
*/
|
||||
public clear (shadowMapBuffer: Buffer) {
|
||||
public clear () {
|
||||
this._subModelsArray.length = 0;
|
||||
this._shaderArray.length = 0;
|
||||
this._passArray.length = 0;
|
||||
this._instancedQueue.clear();
|
||||
this._batchedQueue.clear();
|
||||
this._shadowMapBuffer = shadowMapBuffer;
|
||||
}
|
||||
|
||||
public add (renderObj: IRenderObject, subModelIdx: number, passIdx: number) {
|
||||
const subModel = renderObj.model.subModels[subModelIdx];
|
||||
const pass = subModel.passes[passIdx];
|
||||
public add (model: Model) {
|
||||
const subModels = model.subModels;
|
||||
// this assumes shadow pass index is the same for all submodels
|
||||
const shadowPassIdx = getShadowPassIndex(subModels);
|
||||
|
||||
if (pass.phase === this._phaseID) {
|
||||
if (this._shadowMapBuffer) {
|
||||
if (pass.batchingScheme === BatchingSchemes.INSTANCING) { // instancing
|
||||
const buffer = InstancedBuffer.get(pass);
|
||||
buffer.merge(subModel, renderObj.model.instancedAttributes, passIdx);
|
||||
this._instancedQueue.queue.add(buffer);
|
||||
} else if(pass.batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging
|
||||
const buffer = BatchedBuffer.get(pass);
|
||||
buffer.merge(subModel, passIdx, renderObj);
|
||||
this._batchedQueue.queue.add(buffer);
|
||||
} else { // standard draw
|
||||
const shader = ShaderPool.get(SubModelPool.get(subModel.handle, SubModelView.SHADER_0 + passIdx) as ShaderHandle);
|
||||
this._subModelsArray.push(subModel);
|
||||
this._shaderArray.push(shader);
|
||||
this._passArray.push(pass);
|
||||
}
|
||||
if (shadowPassIdx < 0) return;
|
||||
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const subModel = subModels[j];
|
||||
const pass = subModel.passes[shadowPassIdx];
|
||||
const batchingScheme = pass.batchingScheme;
|
||||
subModel.descriptorSet.bindBuffer(UBOShadow.BINDING, this._shadowMapBuffer);
|
||||
subModel.descriptorSet.update();
|
||||
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) { // instancing
|
||||
const buffer = InstancedBuffer.get(pass);
|
||||
buffer.merge(subModel, model.instancedAttributes, shadowPassIdx);
|
||||
this._instancedQueue.queue.add(buffer);
|
||||
} else if (pass.batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging
|
||||
const buffer = BatchedBuffer.get(pass);
|
||||
buffer.merge(subModel, shadowPassIdx, model);
|
||||
this._batchedQueue.queue.add(buffer);
|
||||
} else {
|
||||
this._subModelsArray.length = 0;
|
||||
this._shaderArray.length = 0;
|
||||
this._passArray.length = 0;
|
||||
this._instancedQueue.clear();
|
||||
this._batchedQueue.clear();
|
||||
const shader = ShaderPool.get(SubModelPool.get(subModel.handle, SubModelView.SHADER_0 + shadowPassIdx) as ShaderHandle);
|
||||
this._subModelsArray.push(subModel);
|
||||
this._shaderArray.push(shader);
|
||||
this._passArray.push(pass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,4 +193,62 @@ export class RenderShadowMapBatchedQueue {
|
||||
cmdBuff.draw(ia);
|
||||
}
|
||||
}
|
||||
|
||||
private _updateUBOs (light: Light) {
|
||||
switch (light.type) {
|
||||
case LightType.DIRECTIONAL:
|
||||
// light view
|
||||
let shadowCameraView: Mat4;
|
||||
const mainLight = light as DirectionalLight;
|
||||
mainLight.update();
|
||||
|
||||
// light proj
|
||||
let x: number = 0;
|
||||
let y: number = 0;
|
||||
let far: number = 0;
|
||||
if (this._shadowInfo.autoAdapt) {
|
||||
shadowCameraView = getShadowWorldMatrix(this._pipeline, mainLight.node?.getWorldRotation()!, mainLight.direction, _vec3Center);
|
||||
// if orthoSize is the smallest, auto calculate orthoSize.
|
||||
const radius = this._shadowInfo.sphere.radius;
|
||||
x = radius * this._shadowInfo.aspect;
|
||||
y = radius;
|
||||
|
||||
const halfFar = Vec3.distance(this._shadowInfo.sphere.center, _vec3Center);
|
||||
far = Math.min(halfFar * Shadows.COEFFICIENT_OF_EXPANSION, Shadows.MAX_FAR);
|
||||
} else {
|
||||
shadowCameraView = mainLight.node!.getWorldMatrix();
|
||||
|
||||
x = this._shadowInfo.orthoSize * this._shadowInfo.aspect;
|
||||
y = this._shadowInfo.orthoSize;
|
||||
|
||||
far = this._shadowInfo.far;
|
||||
}
|
||||
|
||||
Mat4.invert(_matShadowView, shadowCameraView!);
|
||||
|
||||
const projectionSignY = this._device.screenSpaceSignY * this._device.UVSpaceSignY;
|
||||
Mat4.ortho(_matShadowViewProj, -x, x, -y, y, this._shadowInfo.near, far,
|
||||
this._device.clipSpaceMinZ, projectionSignY);
|
||||
break;
|
||||
case LightType.SPOT:
|
||||
const spotLight = light as SpotLight;
|
||||
// light view
|
||||
Mat4.invert(_matShadowView, spotLight.node!.getWorldMatrix());
|
||||
|
||||
// light proj
|
||||
Mat4.perspective(_matShadowViewProj, spotLight.spotAngle, spotLight.aspect, 0.001, spotLight.range);
|
||||
break;
|
||||
}
|
||||
// light viewProj
|
||||
Mat4.multiply(_matShadowViewProj, _matShadowViewProj, _matShadowView);
|
||||
|
||||
Mat4.toArray(this._shadowUBO, _matShadowViewProj, UBOShadow.MAT_LIGHT_VIEW_PROJ_OFFSET);
|
||||
|
||||
Color.toArray(this._shadowUBO, this._shadowInfo.shadowColor, UBOShadow.SHADOW_COLOR_OFFSET);
|
||||
|
||||
_vec4ShadowInfo.set(this._shadowInfo.size.x, this._shadowInfo.size.y, this._shadowInfo.pcf, this._shadowInfo.bias);
|
||||
Vec4.toArray(this._shadowUBO, _vec4ShadowInfo, UBOShadow.SHADOW_INFO_OFFSET);
|
||||
|
||||
this._descriptorSet.getBuffer(UBOShadow.BINDING).update(this._shadowUBO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import { PIPELINE_FLOW_SHADOW, UNIFORM_SHADOWMAP_BINDING } from '../define';
|
||||
import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { ForwardFlowPriority } from '../forward/enum';
|
||||
import { ShadowStage } from './shadow-stage';
|
||||
import { Framebuffer, RenderPass, LoadOp, StoreOp,
|
||||
import { RenderPass, LoadOp, StoreOp,
|
||||
TextureLayout, Format, Texture, TextureType, TextureUsageBit, Filter, Address,
|
||||
ColorAttachment, DepthStencilAttachment, RenderPassInfo, TextureInfo, FramebufferInfo } from '../../gfx';
|
||||
import { RenderFlowTag } from '../pipeline-serialization';
|
||||
@@ -41,6 +41,9 @@ import { ForwardPipeline } from '../forward/forward-pipeline';
|
||||
import { RenderView } from '../render-view';
|
||||
import { ShadowType } from '../../renderer/scene/shadows';
|
||||
import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib';
|
||||
import { Light } from '../../renderer/scene/light';
|
||||
import { lightCollecting, shadowCollecting } from '../forward/scene-culling';
|
||||
import { Vec2 } from '../../math';
|
||||
|
||||
const _samplerInfo = [
|
||||
Filter.LINEAR,
|
||||
@@ -58,14 +61,6 @@ const _samplerInfo = [
|
||||
@ccclass('ShadowFlow')
|
||||
export class ShadowFlow extends RenderFlow {
|
||||
|
||||
/**
|
||||
* @en Gets the frame buffer for shadow map
|
||||
* @zh 获取渲染阴影的 Frame Buffer
|
||||
*/
|
||||
public get shadowFrameBuffer () {
|
||||
return this._shadowFrameBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en A common initialization info for shadow map render flow
|
||||
* @zh 一个通用的 ShadowFlow 的初始化信息对象
|
||||
@@ -78,11 +73,6 @@ export class ShadowFlow extends RenderFlow {
|
||||
};
|
||||
|
||||
private _shadowRenderPass: RenderPass|null = null;
|
||||
private _shadowRenderTargets: Texture[] = [];
|
||||
private _shadowFrameBuffer: Framebuffer|null = null;
|
||||
private _depth: Texture|null = null;
|
||||
private _width: number = 0;
|
||||
private _height: number = 0;
|
||||
|
||||
public initialize (info: IRenderFlowInfo): boolean {
|
||||
super.initialize(info);
|
||||
@@ -95,16 +85,37 @@ export class ShadowFlow extends RenderFlow {
|
||||
return true;
|
||||
}
|
||||
|
||||
public activate (pipeline: ForwardPipeline) {
|
||||
super.activate(pipeline);
|
||||
public render (view: RenderView) {
|
||||
const pipeline = this._pipeline as ForwardPipeline;
|
||||
const shadowInfo = pipeline.shadows;
|
||||
if (shadowInfo.type !== ShadowType.ShadowMap) { return; }
|
||||
|
||||
const validLights = lightCollecting(view, shadowInfo.maxReceived);
|
||||
shadowCollecting(pipeline, view);
|
||||
|
||||
for (let l = 0; l < validLights.length; l++) {
|
||||
const light = validLights[l];
|
||||
|
||||
if (!pipeline.shadowFrameBufferMap.has(light)) {
|
||||
this._initShadowFrameBuffer(pipeline, light);
|
||||
}
|
||||
const shadowFrameBuffer = pipeline.shadowFrameBufferMap.get(light);
|
||||
if (shadowInfo.shadowMapDirty) { this.resizeShadowMap(light, shadowInfo.size); }
|
||||
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
const shadowStage = this._stages[i] as ShadowStage;
|
||||
shadowStage.setUsage(light, shadowFrameBuffer!);
|
||||
shadowStage.render(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public _initShadowFrameBuffer (pipeline: ForwardPipeline, light: Light) {
|
||||
const device = pipeline.device;
|
||||
const shadowMapSize = pipeline.shadows.size;
|
||||
this._width = shadowMapSize.x;
|
||||
this._height = shadowMapSize.y;
|
||||
|
||||
if(!this._shadowRenderPass) {
|
||||
|
||||
if (!this._shadowRenderPass) {
|
||||
const colorAttachment = new ColorAttachment();
|
||||
colorAttachment.format = Format.RGBA8;
|
||||
colorAttachment.loadOp = LoadOp.CLEAR; // should clear color attachment
|
||||
@@ -127,78 +138,64 @@ export class ShadowFlow extends RenderFlow {
|
||||
this._shadowRenderPass = device.createRenderPass(renderPassInfo);
|
||||
}
|
||||
|
||||
if(this._shadowRenderTargets.length < 1) {
|
||||
this._shadowRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
}
|
||||
const shadowRenderTargets: Texture[] = [];
|
||||
shadowRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.RGBA8,
|
||||
shadowMapSize.x,
|
||||
shadowMapSize.y,
|
||||
)));
|
||||
|
||||
if(!this._depth) {
|
||||
this._depth = device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
|
||||
device.depthStencilFormat,
|
||||
this._width,
|
||||
this._height,
|
||||
));
|
||||
}
|
||||
const depth = device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
|
||||
device.depthStencilFormat,
|
||||
shadowMapSize.x,
|
||||
shadowMapSize.y,
|
||||
));
|
||||
|
||||
if(!this._shadowFrameBuffer) {
|
||||
this._shadowFrameBuffer = device.createFramebuffer(new FramebufferInfo(
|
||||
this._shadowRenderPass,
|
||||
this._shadowRenderTargets,
|
||||
this._depth,
|
||||
));
|
||||
}
|
||||
const shadowFrameBuffer = device.createFramebuffer(new FramebufferInfo(
|
||||
this._shadowRenderPass,
|
||||
shadowRenderTargets,
|
||||
depth,
|
||||
));
|
||||
|
||||
for (let i = 0; i < this._stages.length; ++i) {
|
||||
(this._stages[i] as ShadowStage).setShadowFrameBuffer(this._shadowFrameBuffer);
|
||||
}
|
||||
// Cache frameBuffer
|
||||
pipeline.shadowFrameBufferMap.set(light, shadowFrameBuffer);
|
||||
|
||||
const shadowMapSamplerHash = genSamplerHash(_samplerInfo);
|
||||
const shadowMapSampler = samplerLib.getSampler(device, shadowMapSamplerHash);
|
||||
pipeline.descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, shadowMapSampler);
|
||||
pipeline.descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, this._shadowRenderTargets[0]);
|
||||
}
|
||||
|
||||
public render (view: RenderView) {
|
||||
private resizeShadowMap (light: Light, size: Vec2) {
|
||||
const width = size.x;
|
||||
const height = size.y;
|
||||
const pipeline = this._pipeline as ForwardPipeline;
|
||||
const shadowInfo = pipeline.shadows;
|
||||
if (shadowInfo.type !== ShadowType.ShadowMap) { return; }
|
||||
|
||||
const shadowMapSize = shadowInfo.size;
|
||||
if (this._width !== shadowMapSize.x || this._height !== shadowMapSize.y) {
|
||||
this.resizeShadowMap(shadowMapSize.x,shadowMapSize.y);
|
||||
this._width = shadowMapSize.x;
|
||||
this._height = shadowMapSize.y;
|
||||
}
|
||||
if (pipeline.shadowFrameBufferMap.has(light)) {
|
||||
const frameBuffer = pipeline.shadowFrameBufferMap.get(light);
|
||||
|
||||
pipeline.updateUBOs(view);
|
||||
super.render(view);
|
||||
}
|
||||
if (!frameBuffer) { return; }
|
||||
|
||||
private resizeShadowMap (width: number, height: number) {
|
||||
if (this._depth) {
|
||||
this._depth.resize(width, height);
|
||||
}
|
||||
|
||||
if (this._shadowRenderTargets.length > 0) {
|
||||
for (let i = 0; i< this._shadowRenderTargets.length; i++) {
|
||||
const renderTarget = this._shadowRenderTargets[i];
|
||||
if (renderTarget) { renderTarget.resize(width, height); }
|
||||
const renderTargets = frameBuffer.colorTextures;
|
||||
if (renderTargets && renderTargets.length > 0) {
|
||||
for (let j = 0; j < renderTargets.length; j++) {
|
||||
const renderTarget = renderTargets[j];
|
||||
if (renderTarget) { renderTarget.resize(width, height); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this._shadowFrameBuffer) {
|
||||
this._shadowFrameBuffer.destroy();
|
||||
this._shadowFrameBuffer.initialize(new FramebufferInfo(
|
||||
this._shadowRenderPass!,
|
||||
this._shadowRenderTargets,
|
||||
this._depth,
|
||||
const depth = frameBuffer.depthStencilTexture;
|
||||
if (depth) { depth.resize(width, height); }
|
||||
|
||||
const shadowRenderPass = frameBuffer.renderPass;
|
||||
frameBuffer.destroy();
|
||||
frameBuffer.initialize(new FramebufferInfo(
|
||||
shadowRenderPass,
|
||||
renderTargets,
|
||||
depth,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ import { RenderView } from '../render-view';
|
||||
import { ForwardStagePriority } from '../forward/enum';
|
||||
import { RenderShadowMapBatchedQueue } from '../render-shadow-map-batched-queue';
|
||||
import { ForwardPipeline } from '../forward/forward-pipeline';
|
||||
import { SetIndex, UBOShadow } from '../define';
|
||||
import { SetIndex } from '../define';
|
||||
import { Light } from '../../renderer/scene/light';
|
||||
import { ShadowFlow } from './shadow-flow';
|
||||
|
||||
const colors: Color[] = [ new Color(1, 1, 1, 1) ];
|
||||
|
||||
@@ -58,43 +60,29 @@ export class ShadowStage extends RenderStage {
|
||||
/**
|
||||
* @en Sets the frame buffer for shadow map
|
||||
* @zh 设置阴影渲染的 FrameBuffer
|
||||
* @param light
|
||||
* @param shadowFrameBuffer
|
||||
*/
|
||||
public setShadowFrameBuffer (shadowFrameBuffer: Framebuffer) {
|
||||
public setUsage (light: Light, shadowFrameBuffer: Framebuffer) {
|
||||
this._light = light;
|
||||
this._shadowFrameBuffer = shadowFrameBuffer;
|
||||
}
|
||||
|
||||
private _additiveShadowQueue: RenderShadowMapBatchedQueue;
|
||||
private _additiveShadowQueue!: RenderShadowMapBatchedQueue;
|
||||
private _shadowFrameBuffer: Framebuffer | null = null;
|
||||
private _renderArea = new Rect();
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
this._additiveShadowQueue = new RenderShadowMapBatchedQueue();
|
||||
}
|
||||
private _light: Light | null = null;
|
||||
|
||||
public destroy () {
|
||||
this._additiveShadowQueue.clear();
|
||||
}
|
||||
|
||||
public render (view: RenderView) {
|
||||
const pipeline = this._pipeline as ForwardPipeline;
|
||||
const shadowInfo = pipeline.shadows;
|
||||
this._additiveShadowQueue.clear(pipeline.descriptorSet.getBuffer(UBOShadow.BINDING));
|
||||
|
||||
if (view.camera.scene?.mainLight) {
|
||||
const shadowObjects = pipeline.shadowObjects;
|
||||
let m = 0; let p = 0;
|
||||
for (let i = 0; i < shadowObjects.length; ++i) {
|
||||
const ro = shadowObjects[i];
|
||||
const subModels = ro.model.subModels;
|
||||
for (m = 0; m < subModels.length; m++) {
|
||||
const passes = subModels[m].passes;
|
||||
for (p = 0; p < passes.length; p++) {
|
||||
this._additiveShadowQueue.add(ro, m, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this._light || !this._shadowFrameBuffer) { return; }
|
||||
this._additiveShadowQueue.gatherLightPasses(this._light);
|
||||
|
||||
const camera = view.camera;
|
||||
|
||||
@@ -115,8 +103,13 @@ export class ShadowStage extends RenderStage {
|
||||
|
||||
cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, pipeline.descriptorSet);
|
||||
|
||||
this._additiveShadowQueue.recordCommandBuffer(device, renderPass!, cmdBuff);
|
||||
this._additiveShadowQueue.recordCommandBuffer(device, renderPass, cmdBuff);
|
||||
|
||||
cmdBuff.endRenderPass();
|
||||
}
|
||||
|
||||
public activate (pipeline: ForwardPipeline, flow: ShadowFlow) {
|
||||
super.activate(pipeline, flow);
|
||||
this._additiveShadowQueue = new RenderShadowMapBatchedQueue(pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,17 +1118,19 @@ export enum ShadowsView {
|
||||
FAR,
|
||||
ASPECT,
|
||||
PCF_TYPE,
|
||||
SHADOW_MAP_DIRTY, // boolean
|
||||
BIAS,
|
||||
ORTHO_SIZE,
|
||||
AUTO_ADAPT, // boolean
|
||||
COLOR, // Vec4
|
||||
SIZE = 17, // Vec2
|
||||
NORMAL = 19, // Vec3
|
||||
MAT_LIGHT = 22, // Mat4
|
||||
COUNT = 38
|
||||
COLOR = 14, // Vec4
|
||||
SIZE = 18, // Vec2
|
||||
NORMAL = 20, // Vec3
|
||||
MAT_LIGHT = 23, // Mat4
|
||||
COUNT = 39
|
||||
}
|
||||
interface IShadowsViewType extends BufferTypeManifest<typeof ShadowsView> {
|
||||
[ShadowsView.ENABLE]: number;
|
||||
[ShadowsView.DIRTY]: number;
|
||||
[ShadowsView.TYPE]: number;
|
||||
[ShadowsView.DISTANCE]: number;
|
||||
[ShadowsView.INSTANCE_PASS]: PassHandle;
|
||||
@@ -1137,8 +1139,8 @@ interface IShadowsViewType extends BufferTypeManifest<typeof ShadowsView> {
|
||||
[ShadowsView.FAR]: number;
|
||||
[ShadowsView.ASPECT]: number;
|
||||
[ShadowsView.PCF_TYPE]: number;
|
||||
[ShadowsView.SHADOW_MAP_DIRTY]: number;
|
||||
[ShadowsView.BIAS]: number;
|
||||
[ShadowsView.DIRTY]: number;
|
||||
[ShadowsView.ORTHO_SIZE]: number;
|
||||
[ShadowsView.AUTO_ADAPT]: number;
|
||||
[ShadowsView.COLOR]: Color;
|
||||
@@ -1149,6 +1151,7 @@ interface IShadowsViewType extends BufferTypeManifest<typeof ShadowsView> {
|
||||
}
|
||||
const shadowsViewDataType: BufferDataTypeManifest<typeof ShadowsView> = {
|
||||
[ShadowsView.ENABLE]: BufferDataType.UINT32,
|
||||
[ShadowsView.DIRTY]: BufferDataType.UINT32,
|
||||
[ShadowsView.TYPE]: BufferDataType.UINT32,
|
||||
[ShadowsView.DISTANCE]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.INSTANCE_PASS]: BufferDataType.UINT32,
|
||||
@@ -1157,9 +1160,9 @@ const shadowsViewDataType: BufferDataTypeManifest<typeof ShadowsView> = {
|
||||
[ShadowsView.FAR]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.ASPECT]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.PCF_TYPE]: BufferDataType.UINT32,
|
||||
[ShadowsView.SHADOW_MAP_DIRTY]: BufferDataType.UINT32,
|
||||
[ShadowsView.BIAS]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.DIRTY]: BufferDataType.UINT32,
|
||||
[ShadowsView.ORTHO_SIZE]: BufferDataType.UINT32,
|
||||
[ShadowsView.ORTHO_SIZE]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.AUTO_ADAPT]: BufferDataType.UINT32,
|
||||
[ShadowsView.COLOR]: BufferDataType.FLOAT32,
|
||||
[ShadowsView.SIZE]: BufferDataType.FLOAT32,
|
||||
@@ -1186,22 +1189,24 @@ export enum LightView {
|
||||
FRUSTUM, // handle
|
||||
SIZE,
|
||||
SPOT_ANGLE,
|
||||
ASPECT,
|
||||
DIRECTION, // Vec3
|
||||
COLOR = 12, // Vec3
|
||||
COLOR_TEMPERATURE_RGB = 15, // Vec3
|
||||
POSITION = 18, // Vec3
|
||||
COUNT = 21
|
||||
COLOR = 13, // Vec3
|
||||
COLOR_TEMPERATURE_RGB = 16, // Vec3
|
||||
POSITION = 19, // Vec3
|
||||
COUNT = 22
|
||||
}
|
||||
interface ILightViewType extends BufferTypeManifest<typeof LightView> {
|
||||
[LightView.USE_COLOR_TEMPERATURE]: number;
|
||||
[LightView.ILLUMINANCE]: number;
|
||||
[LightView.NODE]: NodeHandle;
|
||||
[LightView.RANGE]: number;
|
||||
[LightView.TYPE]: number;
|
||||
[LightView.AABB]: AABBHandle;
|
||||
[LightView.FRUSTUM]: FrustumHandle;
|
||||
[LightView.SIZE]: number;
|
||||
[LightView.SPOT_ANGLE]: number;
|
||||
[LightView.NODE]:NodeHandle;
|
||||
[LightView.RANGE]:number;
|
||||
[LightView.TYPE]:number;
|
||||
[LightView.AABB]:AABBHandle;
|
||||
[LightView.FRUSTUM]:FrustumHandle;
|
||||
[LightView.SIZE]:number;
|
||||
[LightView.SPOT_ANGLE]:number;
|
||||
[LightView.ASPECT]: number;
|
||||
[LightView.DIRECTION]: Vec3;
|
||||
[LightView.COLOR]: Vec3;
|
||||
[LightView.COLOR_TEMPERATURE_RGB]: Vec3;
|
||||
@@ -1218,6 +1223,7 @@ const lightViewDataType: BufferDataTypeManifest<typeof LightView> = {
|
||||
[LightView.FRUSTUM]: BufferDataType.UINT32,
|
||||
[LightView.SIZE]: BufferDataType.FLOAT32,
|
||||
[LightView.SPOT_ANGLE]: BufferDataType.FLOAT32,
|
||||
[LightView.ASPECT]: BufferDataType.FLOAT32,
|
||||
[LightView.DIRECTION]: BufferDataType.FLOAT32,
|
||||
[LightView.COLOR]: BufferDataType.FLOAT32,
|
||||
[LightView.COLOR_TEMPERATURE_RGB]: BufferDataType.FLOAT32,
|
||||
|
||||
@@ -90,6 +90,7 @@ export const PCFType = Enum({
|
||||
});
|
||||
|
||||
export class Shadows {
|
||||
|
||||
/**
|
||||
* @en MAX_FAR. This is shadow camera max far.
|
||||
* @zh 阴影相机的最远视距。
|
||||
@@ -103,7 +104,7 @@ export class Shadows {
|
||||
public static readonly COEFFICIENT_OF_EXPANSION: number = 2.0 * Math.sqrt(3.0);
|
||||
|
||||
/**
|
||||
* @en Whether activate planar shadow
|
||||
* @en Whether activate planar shadow.
|
||||
* @zh 是否启用平面阴影?
|
||||
*/
|
||||
get enabled (): boolean {
|
||||
@@ -117,8 +118,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The normal of the plane which receives shadow
|
||||
* @zh 阴影接收平面的法线
|
||||
* @en The normal of the plane which receives shadow.
|
||||
* @zh 阴影接收平面的法线。
|
||||
*/
|
||||
get normal (): Vec3 {
|
||||
return this._normal;
|
||||
@@ -131,7 +132,7 @@ export class Shadows {
|
||||
|
||||
/**
|
||||
* @en The distance from coordinate origin to the receiving plane.
|
||||
* @zh 阴影接收平面与原点的距离
|
||||
* @zh 阴影接收平面与原点的距离。
|
||||
*/
|
||||
get distance (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.DISTANCE);
|
||||
@@ -142,8 +143,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Shadow color
|
||||
* @zh 阴影颜色
|
||||
* @en Shadow color.
|
||||
* @zh 阴影颜色。
|
||||
*/
|
||||
get shadowColor (): Color {
|
||||
return this._shadowColor;
|
||||
@@ -155,8 +156,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Shadow type
|
||||
* @zh 阴影类型
|
||||
* @en Shadow type.
|
||||
* @zh 阴影类型。
|
||||
*/
|
||||
get type (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.TYPE);
|
||||
@@ -168,8 +169,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera near
|
||||
* @zh 获取或者设置阴影相机近裁剪面
|
||||
* @en get or set shadow camera near.
|
||||
* @zh 获取或者设置阴影相机近裁剪面。
|
||||
*/
|
||||
public get near (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.NEAR);
|
||||
@@ -179,8 +180,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera far
|
||||
* @zh 获取或者设置阴影相机远裁剪面
|
||||
* @en get or set shadow camera far.
|
||||
* @zh 获取或者设置阴影相机远裁剪面。
|
||||
*/
|
||||
public get far (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.FAR);
|
||||
@@ -190,8 +191,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera aspect
|
||||
* @zh 获取或者设置阴影相机的宽高比
|
||||
* @en get or set shadow camera aspect.
|
||||
* @zh 获取或者设置阴影相机的宽高比。
|
||||
*/
|
||||
public get aspect (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.ASPECT);
|
||||
@@ -201,8 +202,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera orthoSize
|
||||
* @zh 获取或者设置阴影相机正交大小
|
||||
* @en get or set shadow camera orthoSize.
|
||||
* @zh 获取或者设置阴影相机正交大小。
|
||||
*/
|
||||
public get orthoSize (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.ORTHO_SIZE);
|
||||
@@ -212,8 +213,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera orthoSize
|
||||
* @zh 获取或者设置阴影纹理大小
|
||||
* @en get or set shadow camera orthoSize.
|
||||
* @zh 获取或者设置阴影纹理大小。
|
||||
*/
|
||||
public get size (): Vec2 {
|
||||
return this._size;
|
||||
@@ -224,8 +225,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow pcf
|
||||
* @zh 获取或者设置阴影pcf等级
|
||||
* @en get or set shadow pcf.
|
||||
* @zh 获取或者设置阴影pcf等级。
|
||||
*/
|
||||
public get pcf (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.PCF_TYPE);
|
||||
@@ -235,8 +236,20 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow bias
|
||||
* @zh 获取或者设置阴影偏移量
|
||||
* @en shadow Map size has been modified.
|
||||
* @zh 阴影贴图大小是否被修改。
|
||||
*/
|
||||
public get shadowMapDirty (): boolean {
|
||||
if (ShadowsPool.get(this._handle, ShadowsView.SHADOW_MAP_DIRTY)) { return true; }
|
||||
return false;
|
||||
}
|
||||
public set shadowMapDirty (val: boolean) {
|
||||
ShadowsPool.set(this._handle, ShadowsView.SHADOW_MAP_DIRTY, val ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow bias.
|
||||
* @zh 获取或者设置阴影偏移量。
|
||||
*/
|
||||
public get bias (): number {
|
||||
return ShadowsPool.get(this._handle, ShadowsView.BIAS);
|
||||
@@ -246,8 +259,8 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow auto control
|
||||
* @zh 获取或者设置阴影是否自动控制
|
||||
* @en get or set shadow auto control.
|
||||
* @zh 获取或者设置阴影是否自动控制。
|
||||
*/
|
||||
public get autoAdapt (): boolean {
|
||||
if (ShadowsPool.get(this._handle, ShadowsView.AUTO_ADAPT)) { return true; }
|
||||
@@ -274,11 +287,17 @@ export class Shadows {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The bounding sphere of the shadow map
|
||||
* @zh 用于计算阴影 Shadow map 的场景包围球
|
||||
* @en The bounding sphere of the shadow map.
|
||||
* @zh 用于计算阴影 Shadow map 的场景包围球.
|
||||
*/
|
||||
public sphere: sphere = new sphere(0.0, 0.0, 0.0, 0.01);
|
||||
|
||||
/**
|
||||
* @en get or set shadow max received.
|
||||
* @zh 阴影接收的最大灯光数量。
|
||||
*/
|
||||
public maxReceived: number = 4;
|
||||
|
||||
protected _normal = new Vec3(0, 1, 0);
|
||||
protected _shadowColor = new Color(0, 0, 0, 76);
|
||||
protected _matLight = new Mat4();
|
||||
|
||||
@@ -103,6 +103,15 @@ export class SpotLight extends Light {
|
||||
this._needUpdate = true;
|
||||
}
|
||||
|
||||
set aspect (val: number) {
|
||||
LightPool.set(this._handle, LightView.ASPECT, val);
|
||||
this._needUpdate = true;
|
||||
}
|
||||
|
||||
get aspect (): number {
|
||||
return LightPool.get(this._handle, LightView.ASPECT);
|
||||
}
|
||||
|
||||
get aabb () {
|
||||
return this._aabb;
|
||||
}
|
||||
@@ -127,8 +136,8 @@ export class SpotLight extends Light {
|
||||
LightPool.set(this._handle, LightView.SIZE, size);
|
||||
LightPool.set(this._handle, LightView.AABB, this._hAABB);
|
||||
LightPool.set(this._handle, LightView.ILLUMINANCE, 1700 / nt2lm(size));
|
||||
LightPool.set(this._handle, LightView.RANGE, 5.0);
|
||||
LightPool.set(this._handle, LightView.RANGE, Math.cos(Math.PI / 6));
|
||||
LightPool.set(this._handle, LightView.ASPECT, 1.0);
|
||||
LightPool.setVec3(this._handle, LightView.DIRECTION, this._dir);
|
||||
}
|
||||
|
||||
@@ -144,7 +153,7 @@ export class SpotLight extends Light {
|
||||
this._node.getWorldRT(_matView);
|
||||
Mat4.invert(_matView, _matView);
|
||||
|
||||
Mat4.perspective(_matProj, this._angle, 1, 0.001, this._range);
|
||||
Mat4.perspective(_matProj, this._angle, 1.0, 0.001, this._range);
|
||||
|
||||
// view-projection
|
||||
Mat4.multiply(_matViewProj, _matProj, _matView);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
import { TextureCube } from '../assets/texture-cube';
|
||||
import { ccclass, visible, type, displayOrder, slide, range, rangeStep, editable, serializable, rangeMin } from 'cc.decorator';
|
||||
import { CCFloat, CCBoolean } from '../data/utils/attribute';
|
||||
import { CCFloat, CCBoolean, CCInteger } from '../data/utils/attribute';
|
||||
import { Color, Quat, Vec3, Vec2 } from '../math';
|
||||
import { Ambient } from '../renderer/scene/ambient';
|
||||
import { Shadows, ShadowType, PCFType } from '../renderer/scene/shadows';
|
||||
@@ -407,6 +407,8 @@ export class ShadowsInfo {
|
||||
@serializable
|
||||
protected _orthoSize: number = 5;
|
||||
@serializable
|
||||
protected _maxReceived: number = 4;
|
||||
@serializable
|
||||
protected _size: Vec2 = new Vec2(512, 512);
|
||||
|
||||
protected _resource: Shadows | null = null;
|
||||
@@ -543,6 +545,20 @@ export class ShadowsInfo {
|
||||
return this._orthoSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow max received
|
||||
* @zh 获取或者设置阴影接收的最大光源数量
|
||||
*/
|
||||
@type(CCInteger)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set maxReceived (val: number) {
|
||||
this._maxReceived = val;
|
||||
if (this._resource) {this._resource.maxReceived = val;}
|
||||
}
|
||||
get maxReceived () {
|
||||
return this._maxReceived;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en get or set shadow camera orthoSize
|
||||
* @zh 获取或者设置阴影纹理大小
|
||||
@@ -550,7 +566,10 @@ export class ShadowsInfo {
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap && this._autoAdapt === false; })
|
||||
set shadowMapSize (val: Vec2) {
|
||||
this._size.set(val);
|
||||
if (this._resource) { this._resource.size = val; }
|
||||
if (this._resource) {
|
||||
this._resource.size = val;
|
||||
this._resource.shadowMapDirty = true;
|
||||
}
|
||||
}
|
||||
get shadowMapSize () {
|
||||
return this._size;
|
||||
@@ -611,6 +630,7 @@ export class ShadowsInfo {
|
||||
this._resource.pcf = this._pcf;
|
||||
this._resource.bias = this._bias;
|
||||
this._resource.enabled = this._enabled;
|
||||
this._resource.maxReceived = this._maxReceived;
|
||||
}
|
||||
}
|
||||
legacyCC.ShadowsInfo = ShadowsInfo;
|
||||
|
||||
@@ -7,6 +7,9 @@ in vec4 v_shadowPos;
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 2) uniform sampler2D cc_shadowMap;
|
||||
|
||||
#pragma builtin(local)
|
||||
layout(set = 2, binding = 11) uniform sampler2D cc_spotLightingMap;
|
||||
|
||||
float CCGetShadowFactorX1 () {
|
||||
vec3 clipPos = v_shadowPos.xyz / v_shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x < 0.0 || clipPos.x > 1.0 ||
|
||||
@@ -40,7 +43,7 @@ float CCGetShadowFactorX5 () {
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_shadowMap, vec2(clipPos.x + offsetx, clipPos.y + offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
|
||||
return shadow /= 5.0;
|
||||
return shadow / 5.0;
|
||||
}
|
||||
|
||||
float CCGetShadowFactorX9 () {
|
||||
@@ -59,7 +62,7 @@ float CCGetShadowFactorX9 () {
|
||||
}
|
||||
}
|
||||
|
||||
return shadow /= 9.0;
|
||||
return shadow / 9.0;
|
||||
}
|
||||
|
||||
float CCGetShadowFactorX25 () {
|
||||
@@ -78,9 +81,94 @@ float CCGetShadowFactorX25 () {
|
||||
}
|
||||
}
|
||||
|
||||
return shadow /= 25.0;
|
||||
return shadow / 25.0;
|
||||
}
|
||||
|
||||
float CCGetDirLightShadowFactorX1 () {
|
||||
vec3 clipPos = v_shadowPos.xyz / v_shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x < 0.0 || clipPos.x > 1.0 ||
|
||||
clipPos.y < 0.0 || clipPos.y > 1.0 ||
|
||||
clipPos.z <-1.0 || clipPos.z > 1.0) { return 0.0; }
|
||||
|
||||
float closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, clipPos.xy));
|
||||
float shadow = step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
float CCGetDirLightShadowFactorX5 () {
|
||||
vec3 clipPos = v_shadowPos.xyz / v_shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x < 0.0 || clipPos.x > 1.0 ||
|
||||
clipPos.y < 0.0 || clipPos.y > 1.0 ||
|
||||
clipPos.z <-1.0 || clipPos.z > 1.0) { return 0.0; }
|
||||
|
||||
float offsetx = 1.0 / cc_shadowInfo.x;
|
||||
float offsety = 1.0 / cc_shadowInfo.y;
|
||||
float shadow = 0.0;
|
||||
float closestDepth = 0.0;
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, vec2(clipPos.x - offsetx, clipPos.y - offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, vec2(clipPos.x - offsetx, clipPos.y + offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, vec2(clipPos.x + offsetx, clipPos.y - offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, vec2(clipPos.x + offsetx, clipPos.y + offsety)));
|
||||
|
||||
return shadow / 5.0;
|
||||
}
|
||||
|
||||
float CCGetDirLightShadowFactorX9 () {
|
||||
vec3 clipPos = v_shadowPos.xyz / v_shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x < 0.0 || clipPos.x > 1.0 ||
|
||||
clipPos.y < 0.0 || clipPos.y > 1.0 ||
|
||||
clipPos.z <-1.0 || clipPos.z > 1.0) { return 0.0; }
|
||||
|
||||
float offsetx = 1.0 / cc_shadowInfo.x;
|
||||
float offsety = 1.0 / cc_shadowInfo.y;
|
||||
float shadow = 0.0;
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
float closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, clipPos.xy + vec2(i, j) * vec2(offsetx, offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
}
|
||||
}
|
||||
|
||||
return shadow / 9.0;
|
||||
}
|
||||
|
||||
float CCGetDirLightShadowFactorX25 () {
|
||||
vec3 clipPos = v_shadowPos.xyz / v_shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x < 0.0 || clipPos.x > 1.0 ||
|
||||
clipPos.y < 0.0 || clipPos.y > 1.0 ||
|
||||
clipPos.z <-1.0 || clipPos.z > 1.0) { return 0.0; }
|
||||
|
||||
float offsetx = 1.0 / cc_shadowInfo.x;
|
||||
float offsety = 1.0 / cc_shadowInfo.y;
|
||||
float shadow = 0.0;
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
for (int j = -2; j <= 2; j++) {
|
||||
float closestDepth = unpackRGBAToDepth(texture(cc_spotLightingMap, clipPos.xy + vec2(i, j) * vec2(offsetx, offsety)));
|
||||
shadow += step(closestDepth, clipPos.z - cc_shadowInfo.w);
|
||||
}
|
||||
}
|
||||
|
||||
return shadow / 25.0;
|
||||
}
|
||||
|
||||
#define CC_DIR_SHADOW_FACTOR(finalColor) \
|
||||
{ \
|
||||
float pcf = cc_shadowInfo.z + 0.001; \
|
||||
float shadowAttenuation = 0.0; \
|
||||
if (pcf > 3.0) shadowAttenuation = CCGetDirLightShadowFactorX25(); \
|
||||
else if (3.0 > pcf && pcf > 2.0) shadowAttenuation = CCGetDirLightShadowFactorX9(); \
|
||||
else if (2.0 > pcf && pcf > 1.0) shadowAttenuation = CCGetDirLightShadowFactorX5(); \
|
||||
else shadowAttenuation = CCGetDirLightShadowFactorX1(); \
|
||||
finalColor *= 1.0 - shadowAttenuation; \
|
||||
} \
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
|
||||
#define CC_SHADOW_FACTOR(finalColor, atten) \
|
||||
{ \
|
||||
float pcf = cc_shadowInfo.z + 0.001; \
|
||||
@@ -92,4 +180,4 @@ float CCGetShadowFactorX25 () {
|
||||
vec3 shadowColor = cc_shadowColor.rgb * cc_shadowColor.a + finalColor.rgb * (1.0 - cc_shadowColor.a); \
|
||||
finalColor.rgb = shadowColor.rgb * shadowAttenuation * atten + finalColor.rgb * (1.0 - shadowAttenuation * atten); \
|
||||
} \
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
|
||||
@@ -4,4 +4,4 @@ out vec4 v_shadowPos;
|
||||
|
||||
#define CCPassShadowParams(worldPos) \
|
||||
v_shadowPos = cc_matLightViewProj * worldPos; \
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
layout(set = 0, binding = 1) uniform CCShadow {
|
||||
highp mat4 cc_matLightPlaneProj;
|
||||
highp mat4 cc_matLightViewProj;
|
||||
lowp vec4 cc_shadowColor;
|
||||
lowp vec4 cc_shadowInfo; //x -> width; y -> height; z -> pcf; w -> bais;
|
||||
lowp vec4 cc_shadowColor;
|
||||
lowp vec4 cc_shadowInfo; //x -> width; y -> height; z -> pcf; w -> bais;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#include <texture-lod>
|
||||
#endif
|
||||
|
||||
#if CC_RECEIVE_SHADOW
|
||||
#include <cc-shadow-map-fs>
|
||||
#endif
|
||||
|
||||
#include <common>
|
||||
#include <gamma>
|
||||
|
||||
@@ -90,7 +94,12 @@ struct StandardSurface {
|
||||
att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);
|
||||
}
|
||||
|
||||
finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);
|
||||
vec3 lightColor = cc_lightColor[i].rgb;
|
||||
#if CC_RECEIVE_SHADOW
|
||||
CC_DIR_SHADOW_FACTOR(lightColor);
|
||||
#endif
|
||||
|
||||
finalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);
|
||||
}
|
||||
|
||||
finalColor = finalColor * s.occlusion;
|
||||
@@ -98,10 +107,6 @@ struct StandardSurface {
|
||||
return vec4(finalColor, 0.0);
|
||||
}
|
||||
#else
|
||||
#if CC_RECEIVE_SHADOW
|
||||
#include <cc-shadow-map-fs>
|
||||
#endif
|
||||
|
||||
vec4 CCStandardShading (StandardSurface s) {
|
||||
// Calculate diffuse & specular
|
||||
vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);
|
||||
|
||||
@@ -283,7 +283,7 @@ CCProgram shadow-caster-vs %{
|
||||
out vec2 v_uv;
|
||||
out vec2 v_uv1;
|
||||
|
||||
out vec2 v_clip_depth;
|
||||
out float v_clip_depth;
|
||||
|
||||
vec4 vert () {
|
||||
StandardVertInput In;
|
||||
@@ -300,7 +300,7 @@ CCProgram shadow-caster-vs %{
|
||||
v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;
|
||||
#endif
|
||||
|
||||
v_clip_depth = clipPos.zw;
|
||||
v_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;
|
||||
|
||||
return clipPos;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ CCProgram shadow-caster-fs %{
|
||||
|
||||
in vec2 v_uv;
|
||||
in vec2 v_uv1;
|
||||
in vec2 v_clip_depth;
|
||||
in float v_clip_depth;
|
||||
|
||||
#if USE_ALBEDO_MAP
|
||||
uniform sampler2D albedoMap;
|
||||
@@ -335,6 +335,6 @@ CCProgram shadow-caster-fs %{
|
||||
if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
return packDepthToRGBA(v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5);
|
||||
return packDepthToRGBA(v_clip_depth);
|
||||
}
|
||||
}%
|
||||
|
||||
Reference in New Issue
Block a user