Support HDR/LDR Light Sources (#9439)

* Added base rendering logic

* Hide using decorators Diffuse reflection map control and ApplyDiffuseMap whenever IBL is disabled

* Added HDR toggle to scene globals

* Fix bug when ApplyDiffuseMap is left checked when envmap is deleted & disable IBL when envmap is deleted

* Add changes to allow rendering the diffuse convolution map

* Added functions to permit setting sky and ground color (hemispheric lighting) from irradiance calculated from a set envmap. That is, when a diffuse reflection irradiance convolution is not used. Also code to discern LDR from HDR

* Various mods

* Permit independent Hemispheric Lighting parameters to be serialized for LDR/HDR

* Add HDR normalization

* Set HDR shader macro

* Modify Illiminance based on global LDR/HDR setting

* Add LDR/HDR versions for luminous flux

* Add distinct LDR/HDR for SpotLight/SphereLight luminous flux

* Adding LDR as the new serialized value, as HDR is assumed by default in previous versions

* Modified hemisphericc ambient light to assume HDR as default removing the necesesity for migration code

* HDR is on by default

* Fix directional light constructor removal

* HDR/LDR fixes for sphere, spot, and directional lights

* Fix the HDR/LDR mode switching on UseHDR toggle

* Switch UI to and from LDR/HDR envmap depending on HDR toggle state

* Make LDR envmap and diffusemap's serializable

* Partial Float32Array->Vec4 conversion

* Fixed passed Vec4() into UBO for skycolor and groundalbedo

* Fixed copy/paste error

* Fix ambient illumination passing into global UBO

* Modify UBOs to call correct luminance functions

* Modification to punctual lights

* Add missing dependency

* Fix HDR/LDR envmap/diffuse map initialization bug

* Add support for native engine

* update_hdr_skybox (#9230)

* update material preview when custom panel change (#9340)

* update material preview when custom panel change

fixed https://github.com/cocos-creator/3d-tasks/issues/8663

* update material preview when custom panel change

fixed https://github.com/cocos-creator/3d-tasks/issues/8663

* Update material.js

* Fix native light function invoke error

* Unify API naming in light

* Improve scene-globals code organization

* Update jsb apis

* Reverse getter setter for spotLight luminance

* Fix unexpectable result of toggle HDR and ApplyDiffuseMap options

* Remove fpScale, make deferred and forward uniform

* Fix skybox macro recompiling error

* Fix shader compiling errors
Fix unlit shader in HDR/LDR output

Co-authored-by: Jamie Anthony Morris <Jamie.Morris@cocos.com>
Co-authored-by: Jamie Anthony Morris <47879963+Jacksparrow2525@users.noreply.github.com>
Co-authored-by: jk20012001 <jkregister@163.com>
Co-authored-by: linshunjun <49218738+linshunjun@users.noreply.github.com>
Co-authored-by: zhangxin <59186205+chichinohaha@users.noreply.github.com>
This commit is contained in:
pandamicro
2021-10-12 10:50:03 +08:00
parent bb815aa024
commit 8e3eb9db05
29 changed files with 875 additions and 308 deletions
+30 -9
View File
@@ -28,17 +28,25 @@
* @module component/light
*/
import { ccclass, help, executeInEditMode, menu, tooltip, unit, serializable } from 'cc.decorator';
import { scene } from '../../core/renderer';
import { ccclass, help, executeInEditMode, menu, tooltip, serializable, formerlySerializedAs } from 'cc.decorator';
import { Light } from './light-component';
import { scene } from '../../core/renderer';
import { legacyCC } from '../../core/global-exports';
import { Camera } from '../../core/renderer/scene';
import { Root } from '../../core/root';
import { property } from '../../core/data/class-decorator';
@ccclass('cc.DirectionalLight')
@help('i18n:cc.DirectionalLight')
@menu('Light/DirectionalLight')
@executeInEditMode
export class DirectionalLight extends Light {
@property
@formerlySerializedAs('_illuminance')
protected _illuminanceHDR = 65000;
@serializable
protected _illuminance = 65000;
protected _illuminanceLDR = 1.0;
protected _type = scene.LightType.DIRECTIONAL;
protected _light: scene.DirectionalLight | null = null;
@@ -49,14 +57,24 @@ export class DirectionalLight extends Light {
* @zh
* 光源强度。
*/
@unit('lx')
@tooltip('i18n:lights.illuminance')
get illuminance () {
return this._illuminance;
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._illuminanceHDR;
} else {
return this._illuminanceLDR;
}
}
set illuminance (val) {
this._illuminance = val;
if (this._light) { this._light.illuminance = this._illuminance; }
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._illuminanceHDR = val;
this._light && (this._light.illuminanceHDR = this._illuminanceHDR);
} else {
this._illuminanceLDR = val;
this._light && (this._light.illuminanceLDR = this._illuminanceLDR);
}
}
constructor () {
@@ -66,7 +84,10 @@ export class DirectionalLight extends Light {
protected _createLight () {
super._createLight();
if (!this._light) { return; }
this.illuminance = this._illuminance;
this._illuminanceLDR = this._illuminanceHDR * Camera.standardExposureValue;
if (this._light) {
this._light.illuminanceHDR = this._illuminanceHDR;
this._light.illuminanceLDR = this._illuminanceLDR;
}
}
}
+48 -12
View File
@@ -27,9 +27,12 @@
* @module component/light
*/
import { ccclass, help, executeInEditMode, menu, tooltip, type, unit, serializable } from 'cc.decorator';
import { ccclass, help, executeInEditMode, menu, tooltip, type, unit, serializable, formerlySerializedAs } from 'cc.decorator';
import { scene } from '../../core/renderer';
import { Light, PhotometricTerm } from './light-component';
import { legacyCC } from '../../core/global-exports';
import { Camera } from '../../core/renderer/scene';
import { Root } from '../../core/root';
@ccclass('cc.SphereLight')
@help('i18n:cc.SphereLight')
@@ -39,7 +42,10 @@ export class SphereLight extends Light {
@serializable
protected _size = 0.15;
@serializable
protected _luminance = 1700 / scene.nt2lm(0.15);
@formerlySerializedAs('_luminance')
protected _luminanceHDR = 1700 / scene.nt2lm(0.15);
@serializable
protected _luminanceLDR = 1.0;
@serializable
protected _term = PhotometricTerm.LUMINOUS_FLUX;
@serializable
@@ -52,28 +58,50 @@ export class SphereLight extends Light {
* @en Luminous flux of the light.
* @zh 光通量。
*/
@unit('lm')
@tooltip('i18n:lights.luminous_flux')
get luminousFlux () {
return this._luminance * scene.nt2lm(this._size);
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR * scene.nt2lm(this._size);
} else {
return this._luminanceLDR;
}
}
set luminousFlux (val) {
this._luminance = val / scene.nt2lm(this._size);
if (this._light) { this._light.luminance = this._luminance; }
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
let result = 0;
if (isHDR) {
this._luminanceHDR = val / scene.nt2lm(this._size);
result = this._luminanceHDR;
} else {
this._luminanceLDR = val;
result = this._luminanceLDR;
}
this._light && (this._light.luminance = result);
}
/**
* @en Luminance of the light.
* @zh 光亮度。
*/
@unit('cd/m²')
@tooltip('i18n:lights.luminance')
get luminance () {
return this._luminance;
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (val) {
this._luminance = val;
if (this._light) { this._light.luminance = val; }
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._luminanceHDR = val;
this._light && (this._light.luminanceHDR = this._luminanceHDR);
} else {
this._luminanceLDR = val;
this._light && (this._light.luminanceLDR = this._luminanceLDR);
}
}
/**
@@ -126,9 +154,17 @@ export class SphereLight extends Light {
protected _createLight () {
super._createLight();
if (!this._light) { return; }
this.luminance = this._luminance;
this.size = this._size;
this.range = this._range;
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._luminanceLDR = this._luminanceHDR * Camera.standardExposureValue * Camera.standardLightMeterScale;
} else {
this._luminanceHDR = this._luminanceLDR / Camera.standardExposureValue / Camera.standardLightMeterScale;
}
if (this._light) {
this._light.luminanceHDR = this._luminanceHDR;
this._light.luminanceLDR = this._luminanceLDR;
}
}
}
+52 -15
View File
@@ -29,11 +29,14 @@
*/
import {
ccclass, help, executeInEditMode, menu, tooltip, type, slide, range, unit, serializable,
ccclass, help, executeInEditMode, menu, tooltip, type, slide, range, serializable, formerlySerializedAs,
} from 'cc.decorator';
import { toRadian } from '../../core/math';
import { scene } from '../../core/renderer';
import { Light, PhotometricTerm } from './light-component';
import { legacyCC } from '../../core/global-exports';
import { Root } from '../../core/root';
import { Camera } from '../../core/renderer/scene';
@ccclass('cc.SpotLight')
@help('i18n:cc.SpotLight')
@@ -44,7 +47,11 @@ export class SpotLight extends Light {
protected _size = 0.15;
@serializable
protected _luminance = 1700 / scene.nt2lm(0.15);
@formerlySerializedAs('_luminance')
protected _luminanceHDR = 1700 / scene.nt2lm(0.15);
@serializable
protected _luminanceLDR = 1.0;
@serializable
protected _term = PhotometricTerm.LUMINOUS_FLUX;
@@ -63,30 +70,52 @@ export class SpotLight extends Light {
* @en Luminous flux of the light.
* @zh 光通量。
*/
@unit('lm')
@tooltip('i18n:lights.luminous_flux')
get luminousFlux () {
return this._luminance * scene.nt2lm(this._size);
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR * scene.nt2lm(this._size);
} else {
return this._luminanceLDR;
}
}
set luminousFlux (val) {
this._luminance = val / scene.nt2lm(this._size);
if (this._light) { this._light.luminance = this._luminance; }
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
let result = 0;
if (isHDR) {
this._luminanceHDR = val / scene.nt2lm(this._size);
result = this._luminanceHDR;
} else {
this._luminanceLDR = val;
result = this._luminanceLDR;
}
this._light && (this._light.luminance = result);
}
/**
* @en Luminance of the light.
* @zh 光亮度。
*/
@unit('cd/m²')
* @en Luminance of the light.
* @zh 光亮度。
*/
@tooltip('i18n:lights.luminance')
get luminance () {
return this._luminance;
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (val) {
this._luminance = val;
if (this._light) { this._light.luminance = val; }
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._luminanceHDR = val;
this._light && (this._light.luminanceHDR = this._luminanceHDR);
} else {
this._luminanceLDR = val;
this._light && (this._light.luminanceLDR = this._luminanceLDR);
}
}
/**
@@ -160,10 +189,18 @@ export class SpotLight extends Light {
protected _createLight () {
super._createLight();
if (!this._light) { return; }
this.luminance = this._luminance;
this.size = this._size;
this.range = this._range;
this.spotAngle = this._spotAngle;
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._luminanceLDR = this._luminanceHDR * Camera.standardExposureValue * Camera.standardLightMeterScale;
} else {
this._luminanceHDR = this._luminanceLDR / Camera.standardExposureValue / Camera.standardLightMeterScale;
}
if (this._light) {
this._light.luminanceHDR = this._luminanceHDR;
this._light.luminanceLDR = this._luminanceLDR;
}
}
}
+24 -29
View File
@@ -9,15 +9,13 @@ export const effects = [
"shaders": [
{
"name": "billboard|vert:vs_main|tinted-fs:add",
"hash": 1225516189,
"hash": 2909832090,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 53, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
"locals": { "blocks": [{ "name": "CCLocal", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }
},
"defines": [
{ "name": "CC_USE_HDR", "type": "boolean" }
],
"defines": [],
"attributes": [
{ "name": "a_position", "defines": [], "format": 32, "location": 0 },
{ "name": "a_texCoord", "defines": [], "format": 21, "location": 1 },
@@ -114,7 +112,7 @@ export const effects = [
"shaders": [
{
"name": "particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add",
"hash": 1985652451,
"hash": 1706693542,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 63, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
@@ -128,8 +126,7 @@ export const effects = [
{ "name": "FORCE_OVER_TIME_MODULE_ENABLE", "type": "boolean" },
{ "name": "VELOCITY_OVER_TIME_MODULE_ENABLE", "type": "boolean" },
{ "name": "TEXTURE_ANIMATION_MODULE_ENABLE", "type": "boolean" },
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" }
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" }
],
"attributes": [
{ "name": "a_position_starttime", "defines": [], "format": 44, "location": 0 },
@@ -206,7 +203,7 @@ export const effects = [
"shaders": [
{
"name": "particle-trail|particle-trail:vs_main|tinted-fs:add",
"hash": 2996796714,
"hash": 1437790364,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 52, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
@@ -215,8 +212,7 @@ export const effects = [
"defines": [
{ "name": "CC_RENDER_MODE", "type": "number", "range": [0, 4] },
{ "name": "CC_DRAW_WIRE_FRAME", "type": "boolean" },
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" }
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" }
],
"attributes": [
{ "name": "a_position", "defines": [], "format": 32, "location": 0 },
@@ -255,7 +251,7 @@ export const effects = [
"shaders": [
{
"name": "particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
"hash": 3024088451,
"hash": 2766437914,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 52, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
@@ -264,8 +260,7 @@ export const effects = [
"defines": [
{ "name": "CC_RENDER_MODE", "type": "number", "range": [0, 4] },
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" },
{ "name": "ROTATION_OVER_TIME_MODULE_ENABLE", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" }
{ "name": "ROTATION_OVER_TIME_MODULE_ENABLE", "type": "boolean" }
],
"attributes": [
{ "name": "a_position", "defines": [], "format": 32, "location": 0 },
@@ -424,10 +419,10 @@ export const effects = [
"shaders": [
{
"name": "standard|standard-vs|standard-fs",
"hash": 2408467665,
"hash": 328927443,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 222, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 65 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }], "buffers": [], "images": [] },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
"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", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "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"] }], "buffers": [], "images": [] }
},
"defines": [
@@ -451,6 +446,7 @@ export const effects = [
{ "name": "USE_TWOSIDE", "type": "boolean" },
{ "name": "SAMPLE_FROM_RT", "type": "boolean" },
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
{ "name": "CC_ENABLE_DIR_SHADOW", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" },
{ "name": "USE_ALBEDO_MAP", "type": "boolean" },
@@ -586,10 +582,10 @@ export const effects = [
"shaders": [
{
"name": "terrain|terrain-vs|terrain-fs",
"hash": 1718228362,
"hash": 1796906081,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 69, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 60 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }], "buffers": [], "images": [] },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
"locals": { "blocks": [{ "name": "CCLocal", "defines": [] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "name": "cc_lightingMap", "defines": ["USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }], "buffers": [], "images": [] }
},
"defines": [
@@ -599,6 +595,7 @@ export const effects = [
{ "name": "USE_NORMALMAP", "type": "boolean" },
{ "name": "USE_LIGHTMAP", "type": "boolean" },
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
{ "name": "USE_BATCHING", "type": "boolean" },
{ "name": "CC_ENABLE_DIR_SHADOW", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" },
@@ -676,7 +673,7 @@ export const effects = [
"shaders": [
{
"name": "unlit|unlit-vs:vert|unlit-fs:frag",
"hash": 1297800256,
"hash": 1144231057,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 197, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
@@ -920,22 +917,23 @@ export const effects = [
"shaders": [
{
"name": "deferred-lighting|lighting-vs|lighting-fs",
"hash": 3768251103,
"hash": 2618924412,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 39, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 58 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }], "buffers": [], "images": [] },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
"locals": { "blocks": [{ "name": "CCForwardLight", "defines": ["CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [], "buffers": [], "images": [] }
},
"defines": [
{ "name": "CC_RECEIVE_SHADOW", "type": "boolean" },
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
{ "name": "USE_LIGHTMAP", "type": "boolean" },
{ "name": "USE_BATCHING", "type": "boolean" },
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
{ "name": "CC_ENABLE_DIR_SHADOW", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" },
{ "name": "CC_PIPELINE_TYPE", "type": "number", "range": [0, 1] },
{ "name": "CC_FORCE_FORWARD_SHADING", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" },
{ "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }
],
"attributes": [
@@ -971,7 +969,7 @@ export const effects = [
"shaders": [
{
"name": "planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag",
"hash": 469017946,
"hash": 2954155677,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 215, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 58 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
@@ -988,8 +986,7 @@ export const effects = [
{ "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" },
{ "name": "USE_INSTANCING", "type": "boolean" },
{ "name": "USE_BATCHING", "type": "boolean" },
{ "name": "USE_LIGHTMAP", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" }
{ "name": "USE_LIGHTMAP", "type": "boolean" }
],
"attributes": [
{ "name": "a_position", "defines": [], "format": 32, "location": 0 },
@@ -1072,7 +1069,7 @@ export const effects = [
"shaders": [
{
"name": "skybox|sky-vs:vert|sky-fs:frag",
"hash": 3341302509,
"hash": 3653711100,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 39, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 39 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [{ "name": "cc_environment", "defines": [] }], "buffers": [], "images": [] },
@@ -1107,15 +1104,13 @@ export const effects = [
"shaders": [
{
"name": "profiler|profiler-vs:vert|profiler-fs:frag",
"hash": 3709831752,
"hash": 179162168,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 60, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 39 },
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
"locals": { "blocks": [], "samplerTextures": [], "buffers": [], "images": [] }
},
"defines": [
{ "name": "CC_USE_HDR", "type": "boolean" }
],
"defines": [],
"attributes": [
{ "name": "a_position", "defines": [], "format": 32, "location": 0 },
{ "name": "a_color", "defines": [], "format": 44, "location": 1 }
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
@@ -157,10 +157,6 @@ export class GbufferStage extends RenderStage {
if (camera.clearFlag & ClearFlagBit.COLOR) {
if (pipeline.pipelineSceneData.isHDR) {
SRGBToLinear(colors[0], camera.clearColor);
const scale = pipeline.pipelineSceneData.fpScale / camera.exposure;
colors[0].x *= scale;
colors[0].y *= scale;
colors[0].z *= scale;
} else {
colors[0].x = camera.clearColor.x;
colors[0].y = camera.clearColor.y;
@@ -126,9 +126,9 @@ export class LightingStage extends RenderStage {
}
if (pipeline.pipelineSceneData.isHDR) {
_vec4Array[3] = light.luminance * pipeline.pipelineSceneData.fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = light.luminance * exposure * this._lightMeterScale;
} else {
_vec4Array[3] = light.luminance;
}
this._lightBufferData.set(_vec4Array, idx * elementLen + fieldLen * 1);
@@ -159,9 +159,9 @@ export class LightingStage extends RenderStage {
_vec4Array[2] *= tempRGB.z;
}
if (pipeline.pipelineSceneData.isHDR) {
_vec4Array[3] = light.luminance * pipeline.pipelineSceneData.fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = light.luminance * exposure * this._lightMeterScale;
} else {
_vec4Array[3] = light.luminance;
}
this._lightBufferData.set(_vec4Array, idx * elementLen + fieldLen * 1);
@@ -244,10 +244,6 @@ export class LightingStage extends RenderStage {
if (camera.clearFlag & ClearFlagBit.COLOR) {
if (sceneData.isHDR) {
SRGBToLinear(colors[0], camera.clearColor);
const scale = sceneData.fpScale / camera.exposure;
colors[0].x *= scale;
colors[0].y *= scale;
colors[0].z *= scale;
} else {
colors[0].x = camera.clearColor.x;
colors[0].y = camera.clearColor.y;
+8
View File
@@ -121,6 +121,7 @@ export enum PipelineGlobalBindings {
SAMPLER_SHADOWMAP,
SAMPLER_ENVIRONMENT, // don't put this as the first sampler binding due to Mac GL driver issues: cubemap at texture unit 0 causes rendering issues
SAMPLER_SPOT_LIGHTING_MAP,
SAMPLER_DIFFUSEMAP,
COUNT,
}
@@ -292,6 +293,13 @@ const UNIFORM_ENVIRONMENT_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UN
globalDescriptorSetLayout.layouts[UNIFORM_ENVIRONMENT_NAME] = UNIFORM_ENVIRONMENT_LAYOUT;
globalDescriptorSetLayout.bindings[UNIFORM_ENVIRONMENT_BINDING] = UNIFORM_ENVIRONMENT_DESCRIPTOR;
const UNIFORM_DIFFUSEMAP_NAME = 'cc_diffuseMap';
export const UNIFORM_DIFFUSEMAP_BINDING = PipelineGlobalBindings.SAMPLER_DIFFUSEMAP;
const UNIFORM_DIFFUSEMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_DIFFUSEMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, 1, ShaderStageFlagBit.FRAGMENT);
const UNIFORM_DIFFUSEMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_DIFFUSEMAP_BINDING, UNIFORM_DIFFUSEMAP_NAME, Type.SAMPLER_CUBE, 1);
globalDescriptorSetLayout.layouts[UNIFORM_DIFFUSEMAP_NAME] = UNIFORM_DIFFUSEMAP_LAYOUT;
globalDescriptorSetLayout.bindings[UNIFORM_DIFFUSEMAP_BINDING] = UNIFORM_DIFFUSEMAP_DESCRIPTOR;
/**
* @en The sampler for spot light shadow map
* @zn 聚光灯阴影纹理采样器
@@ -171,10 +171,6 @@ export class ForwardStage extends RenderStage {
if (camera.clearFlag & ClearFlagBit.COLOR) {
if (sceneData.isHDR) {
SRGBToLinear(colors[0], camera.clearColor);
const scale = sceneData.fpScale / camera.exposure;
colors[0].x *= scale;
colors[0].y *= scale;
colors[0].z *= scale;
} else {
colors[0].x = camera.clearColor.x;
colors[0].y = camera.clearColor.y;
@@ -74,15 +74,6 @@ export class PipelineSceneData {
this._nativeObj!.shadingScale = val;
}
}
public get fpScale () {
return this._fpScale;
}
public set fpScale (val: number) {
this._fpScale = val;
if (JSB) {
this._fpScale = val;
}
}
public fog: Fog = new Fog();
public ambient: Ambient = new Ambient();
@@ -101,12 +92,10 @@ export class PipelineSceneData {
protected declare _nativeObj: NativePipelineSharedSceneData | null;
protected _isHDR = false;
protected _shadingScale = 1.0;
protected _fpScale = 1.0 / 1024.0;
constructor () {
this._init();
this.shadingScale = 1.0;
this.fpScale = 1.0 / 1024.0;
}
public activate (device: Device, pipeline: RenderPipeline) {
+14 -9
View File
@@ -78,7 +78,6 @@ export class PipelineUBO {
const exposure = camera.exposure;
const isHDR = sceneData.isHDR;
const shadingScale = sceneData.shadingScale;
const fpScale = sceneData.fpScale;
// update camera ubo
cv[UBOCamera.SCREEN_SCALE_OFFSET] = camera.width / shadingWidth * shadingScale;
@@ -89,7 +88,7 @@ export class PipelineUBO {
cv[UBOCamera.EXPOSURE_OFFSET] = exposure;
cv[UBOCamera.EXPOSURE_OFFSET + 1] = 1.0 / exposure;
cv[UBOCamera.EXPOSURE_OFFSET + 2] = isHDR ? 1.0 : 0.0;
cv[UBOCamera.EXPOSURE_OFFSET + 3] = fpScale / exposure;
cv[UBOCamera.EXPOSURE_OFFSET + 3] = 0.0;
if (mainLight) {
Vec3.toArray(cv, mainLight.direction, UBOCamera.MAIN_LIT_DIR_OFFSET);
@@ -102,23 +101,29 @@ export class PipelineUBO {
}
if (isHDR) {
cv[UBOCamera.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance * fpScale;
} else {
cv[UBOCamera.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance * exposure;
} else {
cv[UBOCamera.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance;
}
} else {
Vec3.toArray(cv, Vec3.UNIT_Z, UBOCamera.MAIN_LIT_DIR_OFFSET);
Vec4.toArray(cv, Vec4.ZERO, UBOCamera.MAIN_LIT_COLOR_OFFSET);
}
const skyColor = ambient.colorArray;
const skyColor = ambient.skyColor;
if (isHDR) {
skyColor[3] = ambient.skyIllum * fpScale;
skyColor.w = ambient.skyIllum * exposure;
} else {
skyColor[3] = ambient.skyIllum * exposure;
skyColor.w = ambient.skyIllum;
}
cv.set(skyColor, UBOCamera.AMBIENT_SKY_OFFSET);
cv.set(ambient.albedoArray, UBOCamera.AMBIENT_GROUND_OFFSET);
cv[UBOCamera.AMBIENT_SKY_OFFSET + 0] = skyColor.x;
cv[UBOCamera.AMBIENT_SKY_OFFSET + 1] = skyColor.y;
cv[UBOCamera.AMBIENT_SKY_OFFSET + 2] = skyColor.z;
cv[UBOCamera.AMBIENT_SKY_OFFSET + 3] = skyColor.w;
cv[UBOCamera.AMBIENT_GROUND_OFFSET + 0] = ambient.groundAlbedo.x;
cv[UBOCamera.AMBIENT_GROUND_OFFSET + 1] = ambient.groundAlbedo.y;
cv[UBOCamera.AMBIENT_GROUND_OFFSET + 2] = ambient.groundAlbedo.z;
cv[UBOCamera.AMBIENT_GROUND_OFFSET + 3] = ambient.groundAlbedo.w;
Mat4.toArray(cv, camera.matView, UBOCamera.MAT_VIEW_OFFSET);
Mat4.toArray(cv, camera.node.worldMatrix, UBOCamera.MAT_VIEW_INV_OFFSET);
@@ -51,6 +51,7 @@ import { SetIndex, UBOForwardLight, UBOGlobal, UBOShadow, UNIFORM_SHADOWMAP_BIND
import { updatePlanarPROJ } from './scene-culling';
import { Camera, ShadowType } from '../renderer/scene';
import { GlobalDSManager } from './global-descriptor-set-manager';
import { legacyCC } from '../global-exports';
interface IAdditiveLightPass {
subModel: SubModel;
@@ -425,7 +426,7 @@ export class RenderAdditiveLightQueue {
const { exposure } = camera;
const sceneData = this._pipeline.pipelineSceneData;
const isHDR = sceneData.isHDR;
const fpScale = sceneData.fpScale;
const root = legacyCC.director.root;
const shadowInfo = sceneData.shadows;
if (this._validLights.length > this._lightBufferCount) {
@@ -462,9 +463,9 @@ export class RenderAdditiveLightQueue {
_vec4Array[2] *= tempRGB.z;
}
if (isHDR) {
_vec4Array[3] = (light as SphereLight).luminance * fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = (light as SphereLight).luminance * exposure * this._lightMeterScale;
} else {
_vec4Array[3] = (light as SphereLight).luminance;
}
this._lightBufferData.set(_vec4Array, offset + UBOForwardLight.LIGHT_COLOR_OFFSET);
break;
@@ -491,9 +492,9 @@ export class RenderAdditiveLightQueue {
_vec4Array[2] *= tempRGB.z;
}
if (isHDR) {
_vec4Array[3] = (light as SpotLight).luminance * fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = (light as SpotLight).luminance * exposure * this._lightMeterScale;
} else {
_vec4Array[3] = (light as SpotLight).luminance;
}
this._lightBufferData.set(_vec4Array, offset + UBOForwardLight.LIGHT_COLOR_OFFSET);
break;
+73 -33
View File
@@ -24,7 +24,7 @@
*/
import { JSB } from 'internal:constants';
import { Color, Vec3 } from '../../math';
import { Color, Vec3, Vec4 } from '../../math';
import { legacyCC } from '../../global-exports';
import { AmbientInfo } from '../../scene-graph/scene-globals';
import { NativeAmbient } from './native-scene';
@@ -33,14 +33,6 @@ export class Ambient {
public static SUN_ILLUM = 65000.0;
public static SKY_ILLUM = 20000.0;
get colorArray (): Float32Array {
return this._colorArray;
}
get albedoArray (): Float32Array {
return this._albedoArray;
}
/**
* @en Enable ambient
* @zh 是否开启环境光
@@ -58,15 +50,28 @@ export class Ambient {
* @en Sky color
* @zh 天空颜色
*/
get skyColor (): Color {
return this._skyColor;
get skyColor (): Vec4 {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._skyColorHDR;
} else {
return this._skyColorLDR;
}
}
set skyColor (color: Color) {
this._skyColor.set(color);
Color.toArray(this._colorArray, this._skyColor);
set skyColor (color: Vec4) {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._skyColorHDR.x = color.x;
this._skyColorHDR.y = color.y;
this._skyColorHDR.z = color.z;
} else {
this._skyColorLDR.x = color.x;
this._skyColorLDR.y = color.y;
this._skyColorLDR.z = color.z;
}
if (JSB) {
this._nativeObj!.skyColor = this._skyColor;
this._nativeObj!.skyColor = this.skyColor;
}
}
@@ -75,11 +80,21 @@ export class Ambient {
* @zh 天空亮度
*/
get skyIllum (): number {
return this._skyIllum;
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._skyIllumHDR;
} else {
return this._skyIllumLDR;
}
}
set skyIllum (illum: number) {
this._skyIllum = illum;
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._skyIllumHDR = illum;
} else {
this._skyIllumLDR = illum;
}
if (JSB) {
this._nativeObj!.skyIllum = illum;
}
@@ -88,23 +103,41 @@ export class Ambient {
* @en Ground color
* @zh 地面颜色
*/
get groundAlbedo (): Color {
return this._groundAlbedo;
}
set groundAlbedo (color: Color) {
this._groundAlbedo.set(color);
Color.toArray(this._albedoArray, this._groundAlbedo);
if (JSB) {
this._nativeObj!.groundAlbedo = this._groundAlbedo;
get groundAlbedo (): Vec4 {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._groundAlbedoHDR;
} else {
return this._groundAlbedoLDR;
}
}
protected _skyColor = new Color(51, 128, 204, 1.0);
protected _groundAlbedo = new Color(51, 51, 51, 255);
protected _albedoArray = Float32Array.from([0.2, 0.2, 0.2, 1.0]);
protected _colorArray = Float32Array.from([0.2, 0.5, 0.8, 1.0]);
set groundAlbedo (color: Vec4) {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._groundAlbedoHDR.x = color.x;
this._groundAlbedoHDR.y = color.y;
this._groundAlbedoHDR.z = color.z;
} else {
this._groundAlbedoLDR.x = color.x;
this._groundAlbedoLDR.y = color.y;
this._groundAlbedoLDR.z = color.z;
}
if (JSB) {
this._nativeObj!.groundAlbedo = this.groundAlbedo;
}
}
protected _groundAlbedoHDR = new Vec4(0.2, 0.2, 0.2, 1.0);
protected _skyColorHDR = new Vec4(0.2, 0.5, 0.8, 1.0);
protected _skyIllumHDR = 0;
protected _groundAlbedoLDR = new Vec4(0.2, 0.2, 0.2, 1.0);
protected _skyColorLDR = new Vec4(0.2, 0.5, 0.8, 1.0);
protected _skyIllumLDR = 0;
protected _enabled = false;
protected _skyIllum = 0;
protected declare _nativeObj: NativeAmbient | null;
get native (): NativeAmbient {
@@ -118,9 +151,16 @@ export class Ambient {
}
public initialize (ambientInfo: AmbientInfo) {
this.skyColor = ambientInfo.skyColor;
this.groundAlbedo = ambientInfo.groundAlbedo;
this.skyIllum = ambientInfo.skyIllum;
// Init HDR/LDR from serialized data on load
this._skyColorHDR = ambientInfo.skyColorHDR;
this._groundAlbedoHDR = ambientInfo.groundAlbedoHDR;
this._skyIllumHDR = ambientInfo.skyIllumHDR;
this._skyColorLDR = ambientInfo.skyColorLDR;
this._groundAlbedoLDR = ambientInfo.groundAlbedoLDR;
this._skyIllumLDR = ambientInfo.skyIllumLDR;
}
protected _destroy () {
+14
View File
@@ -211,6 +211,20 @@ export class Camera {
}
}
/**
* this exposure value corresponding to default standard camera exposure parameters
*/
public static get standardExposureValue () {
return 1.0 / 38400.0;
}
/**
* luminance unit scale used by area lights
*/
public static get standardLightMeterScale () {
return 10000.0;
}
public initialize (info: ICameraInfo) {
this._init(info);
this.node = info.node;
+35 -7
View File
@@ -24,6 +24,7 @@
*/
import { JSB } from 'internal:constants';
import { legacyCC } from '../../global-exports';
import { Vec3 } from '../../math';
import { Ambient } from './ambient';
import { Light, LightType } from './light';
@@ -34,7 +35,8 @@ const _v3 = new Vec3();
export class DirectionalLight extends Light {
protected _dir: Vec3 = new Vec3(1.0, -1.0, -1.0);
protected _illuminance: number = Ambient.SUN_ILLUM;
protected _illuminanceHDR: number = Ambient.SUN_ILLUM;
protected _illuminanceLDR = 1.0;
set direction (dir: Vec3) {
Vec3.normalize(this._dir, dir);
@@ -48,15 +50,41 @@ export class DirectionalLight extends Light {
}
// in Lux(lx)
set illuminance (illum: number) {
this._illuminance = illum;
if (JSB) {
(this._nativeObj as NativeDirectionalLight).setIlluminance(illum);
get illuminance (): number {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._illuminanceHDR;
} else {
return this._illuminanceLDR;
}
}
set illuminance (value: number) {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this.illuminanceHDR = value;
} else {
this.illuminanceLDR = value;
}
}
get illuminance (): number {
return this._illuminance;
get illuminanceHDR () {
return this._illuminanceHDR;
}
set illuminanceHDR (value: number) {
this._illuminanceHDR = value;
if (JSB) {
(this._nativeObj as NativeDirectionalLight).setIlluminanceHDR(value);
}
}
get illuminanceLDR () {
return this._illuminanceLDR;
}
set illuminanceLDR (value: number) {
this._illuminanceLDR = value;
if (JSB) {
(this._nativeObj as NativeDirectionalLight).setIlluminanceLDR(value);
}
}
constructor () {
+11 -7
View File
@@ -3,7 +3,7 @@ import { IFlatBuffer } from '../../assets/rendering-sub-mesh';
import { Frustum } from '../../geometry';
import { Attribute, BlendState, Buffer, ClearFlags, Color as GFXColor, DepthStencilState,
DescriptorSet, DrawInfo, Framebuffer, InputAssembler, RasterizerState, Shader, Swapchain } from '../../gfx';
import { Color, Mat4, Rect, Vec2 } from '../../math';
import { Color, Mat4, Rect, Vec2, Vec3, Vec4 } from '../../math';
import { RenderPriority } from '../../pipeline/define';
import { LightType } from './light';
@@ -105,7 +105,8 @@ export type NativeLight = InstanceType<typeof NativeLight>;
export const NativeDirectionalLight: Constructor<{
setDirection (dir: Vec3): void;
setIlluminance (lum: number): void;
setIlluminanceHDR (lum: number): void;
setIlluminanceLDR(lum: number): void;
} & NativeLight> = null!;
export type NativeDirectionalLight = InstanceType<typeof NativeDirectionalLight>;
@@ -114,7 +115,8 @@ export const NativeSphereLight: Constructor<{
setAABB (aabb: NativeAABB): void;
setSize (size: number): void;
setRange (range: number): void;
setIlluminance (lum: number): void;
setLuminanceHDR (lum: number): void;
setLuminanceLDR(lum: number): void;
} & NativeLight> = null!;
export type NativeSphereLight = InstanceType<typeof NativeSphereLight>;
@@ -127,7 +129,8 @@ export const NativeSpotLight: Constructor<{
setRange (range: number): void;
setAspect (aspect: number): void;
setAngle (angle: number): void;
setIlluminance (lum: number): void;
setLuminanceHDR (lum: number): void;
setLuminanceLDR(lum: number): void;
} & NativeLight> = null!;
export type NativeSpotLight = InstanceType<typeof NativeSpotLight>;
@@ -135,6 +138,8 @@ export const NaitveSkybox: Constructor<{
enabled: boolean;
useIBL: boolean;
isRGBE: boolean;
useHDR: boolean;
useDiffuseMap: boolean;
model: NativeModel | null;
}> = null!;
export type NaitveSkybox = InstanceType<typeof NaitveSkybox>;
@@ -266,9 +271,9 @@ export type NativeRenderScene = InstanceType<typeof NativeRenderScene>;
export const NativeAmbient: Constructor<{
enabled: boolean;
skyColor: Color;
skyColor: Vec4;
skyIllum: number;
groundAlbedo: Color;
groundAlbedo: Vec4;
}> = null!;
export type NativeAmbient = InstanceType<typeof NativeAmbient>;
@@ -323,7 +328,6 @@ export type NativeJointInfo = InstanceType<typeof NativeJointInfo>;
export const NativePipelineSharedSceneData: Constructor<{
isHDR: boolean;
shadingScale: number;
fpScale: number;
fog: NativeFog;
ambient: NativeAmbient;
skybox: NaitveSkybox;
+171 -48
View File
@@ -28,7 +28,7 @@ import { builtinResMgr } from '../../builtin';
import { Material } from '../../assets/material';
import { Mesh } from '../../../3d/assets/mesh';
import { TextureCube } from '../../assets/texture-cube';
import { UNIFORM_ENVIRONMENT_BINDING } from '../../pipeline/define';
import { UNIFORM_ENVIRONMENT_BINDING, UNIFORM_DIFFUSEMAP_BINDING } from '../../pipeline/define';
import { MaterialInstance } from '../core/material-instance';
import { Model } from './model';
import { legacyCC } from '../../global-exports';
@@ -59,8 +59,21 @@ export class Skybox {
if (val) this.activate(); else this._updatePipeline();
}
/**
* @en Whether use environment lighting
* @zh 是否启用环境光照?
* @en HDR
* @zh 是否启用HDR?
*/
get useHDR (): boolean {
return this._useHDR;
}
set useHDR (val: boolean) {
this._setUseHDR(val);
this.setEnvMaps(this._envmapHDR, this._envmapLDR);
}
/**
* @en Whether use IBL
* @zh 是否启用IBL?
*/
get useIBL (): boolean {
return this._useIBL;
@@ -71,26 +84,30 @@ export class Skybox {
this._updatePipeline();
}
/**
* @en Whether use diffuse convolution map lighting
* @zh 是否为IBL启用漫反射卷积图?
*/
get useDiffuseMap (): boolean {
return this._useDiffuseMap;
}
set useDiffuseMap (val: boolean) {
this._useDiffuseMap = val;
this._updateGlobalBinding();
this._updatePipeline();
}
/**
* @en Whether enable RGBE data support in skybox shader
* @zh 是否需要开启 shader 内的 RGBE 数据支持?
*/
get isRGBE (): boolean {
return this._isRGBE;
}
set isRGBE (val: boolean) {
if (val) {
if (skybox_material) {
skybox_material.recompileShaders({ USE_RGBE_CUBEMAP: val });
}
if (this._model) {
this._model.setSubModelMaterial(0, skybox_material!);
}
if (this.envmap) {
return this.envmap.isRGBE;
} else {
return false;
}
this._setIsRGBE(val);
this._updatePipeline();
}
/**
@@ -98,24 +115,55 @@ export class Skybox {
* @zh 使用的立方体贴图
*/
get envmap (): TextureCube | null {
return this._envmap;
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._envmapHDR;
} else {
return this._envmapLDR;
}
}
set envmap (val: TextureCube | null) {
this._envmap = val || this._default;
if (this._envmap) {
(legacyCC.director.root as Root).pipeline.pipelineSceneData.ambient.albedoArray[3] = this._envmap.mipmapLevel;
this._updateGlobalBinding();
const root = legacyCC.director.root as Root;
const isHDR = root.pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this.setEnvMaps(val, this._envmapLDR);
} else {
this.setEnvMaps(this._envmapHDR, val);
}
}
protected _envmap: TextureCube | null = null;
/**
* @en The texture cube used diffuse convolution map
* @zh 使用的漫反射卷积图
*/
get diffuseMap (): TextureCube | null {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._diffuseMapHDR;
} else {
return this._diffuseMapLDR;
}
}
set diffuseMap (val: TextureCube | null) {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this.setDiffuseMaps(val, this._diffuseMapLDR);
} else {
this.setDiffuseMaps(this._diffuseMapHDR, val);
}
}
protected _envmapLDR: TextureCube | null = null;
protected _envmapHDR: TextureCube | null = null;
protected _diffuseMapLDR: TextureCube | null = null;
protected _diffuseMapHDR: TextureCube | null = null;
protected _globalDSManager: GlobalDSManager | null = null;
protected _model: Model | null = null;
protected _default: TextureCube | null = null;
protected _enabled = false;
protected _useIBL = false;
protected _isRGBE = false;
protected _useHDR = false;
protected _useDiffuseMap = false;
protected declare _nativeObj: NaitveSkybox | null;
get native (): NaitveSkybox {
@@ -142,23 +190,54 @@ export class Skybox {
}
}
private _setIsRGBE (val) {
this._isRGBE = val;
private _setUseHDR (val) {
this._useHDR = val;
if (JSB) {
this._nativeObj!.isRGBE = val;
this._nativeObj!.useHDR = val;
}
}
private _setUseDiffuseMap (val) {
this._useDiffuseMap = val;
if (JSB) {
this._nativeObj!.useDiffuseMap = val;
}
}
public initialize (skyboxInfo: SkyboxInfo) {
this._setEnabled(skyboxInfo.enabled);
this._setUseIBL(skyboxInfo.useIBL);
this._setIsRGBE(skyboxInfo.isRGBE);
this._envmap = skyboxInfo.envmap;
this._setUseDiffuseMap(skyboxInfo.applyDiffuseMap);
this._setUseHDR(skyboxInfo.useHDR);
}
public setEnvMaps (envmapHDR: TextureCube | null, envmapLDR: TextureCube | null) {
this._envmapHDR = envmapHDR || this._default;
this._envmapLDR = envmapLDR || this._default;
const root = legacyCC.director.root as Root;
const isHDR = root.pipeline.pipelineSceneData.isHDR;
if (isHDR) {
if (envmapHDR) {
root.pipeline.pipelineSceneData.ambient.groundAlbedo.w = envmapHDR.mipmapLevel;
}
} else if (envmapLDR) {
root.pipeline.pipelineSceneData.ambient.groundAlbedo.w = envmapLDR.mipmapLevel;
}
this._updateGlobalBinding();
this._updatePipeline();
}
public setDiffuseMaps (diffuseMapHDR: TextureCube | null, diffuseMapLDR: TextureCube | null) {
this._diffuseMapHDR = diffuseMapHDR;
this._diffuseMapLDR = diffuseMapLDR;
this._updateGlobalBinding();
this._updatePipeline();
}
public activate () {
const pipeline = legacyCC.director.root.pipeline;
const ambient = pipeline.pipelineSceneData.ambient;
this._globalDSManager = pipeline.globalDSManager;
this._default = builtinResMgr.get<TextureCube>('default-cube-texture');
@@ -170,44 +249,88 @@ export class Skybox {
this._nativeObj!.model = this._model.native;
}
}
if (!this._envmap) {
this._envmap = this._default;
let isRGBE = this._default.isRGBE;
if (this.envmap) {
isRGBE = this.envmap.isRGBE;
}
ambient.albedoArray[3] = this._envmap.mipmapLevel;
if (!skybox_material) {
const mat = new Material();
mat.initialize({ effectName: 'skybox', defines: { USE_RGBE_CUBEMAP: this.isRGBE } });
mat.initialize({ effectName: 'skybox', defines: { USE_RGBE_CUBEMAP: isRGBE } });
skybox_material = new MaterialInstance({ parent: mat });
} else {
skybox_material.recompileShaders({ USE_RGBE_CUBEMAP: this.isRGBE });
}
if (this.enabled) {
if (!skybox_mesh) { skybox_mesh = legacyCC.utils.createMesh(legacyCC.primitives.box({ width: 2, height: 2, length: 2 })) as Mesh; }
if (!skybox_mesh) {
skybox_mesh = legacyCC.utils.createMesh(legacyCC.primitives.box({ width: 2, height: 2, length: 2 })) as Mesh;
}
this._model.initSubModel(0, skybox_mesh.renderingSubMeshes[0], skybox_material);
}
if (!this.envmap) {
this.envmap = this._default;
}
if (!this.diffuseMap) {
this.diffuseMap = this._default;
}
this._updateGlobalBinding();
this._updatePipeline();
}
protected _updatePipeline () {
const value = this.useIBL ? (this.isRGBE ? 2 : 1) : 0;
const root = legacyCC.director.root as Root;
const pipeline = root.pipeline;
const current = pipeline.macros.CC_USE_IBL;
if (current === value) { return; }
pipeline.macros.CC_USE_IBL = value;
const useIBLValue = this.useIBL ? (this.isRGBE ? 2 : 1) : 0;
const useDiffuseMapValue = (this.useIBL && this.useDiffuseMap && this.diffuseMap) ? (this.isRGBE ? 2 : 1) : 0;
const useHDRValue = this.useHDR;
if (pipeline.macros.CC_USE_IBL === useIBLValue
&& pipeline.macros.CC_USE_DIFFUSEMAP === useDiffuseMapValue
&& pipeline.macros.CC_USE_HDR === useHDRValue) {
return;
}
pipeline.macros.CC_USE_IBL = useIBLValue;
pipeline.macros.CC_USE_DIFFUSEMAP = useDiffuseMapValue;
pipeline.macros.CC_USE_HDR = useHDRValue;
if (JSB) {
this._nativeObj!.isRGBE = this.isRGBE;
}
if (skybox_material) {
skybox_material.recompileShaders({ USE_RGBE_CUBEMAP: this.isRGBE });
}
if (this._model) {
this._model.setSubModelMaterial(0, skybox_material!);
}
root.onGlobalPipelineStateChanged();
}
protected _updateGlobalBinding () {
const texture = this.envmap!.getGFXTexture()!;
const device = legacyCC.director.root.device as Device;
const sampler = device.getSampler(this.envmap!.getSamplerInfo());
this._globalDSManager!.bindSampler(UNIFORM_ENVIRONMENT_BINDING, sampler);
this._globalDSManager!.bindTexture(UNIFORM_ENVIRONMENT_BINDING, texture);
this._globalDSManager!.update();
if (this._globalDSManager) {
const device = legacyCC.director.root.device as Device;
if (this.envmap) {
const texture = this.envmap.getGFXTexture()!;
const sampler = device.getSampler(this.envmap.getSamplerInfo());
this._globalDSManager.bindSampler(UNIFORM_ENVIRONMENT_BINDING, sampler);
this._globalDSManager.bindTexture(UNIFORM_ENVIRONMENT_BINDING, texture);
}
if (this.diffuseMap) {
const textureDiffuseMap = this.diffuseMap.getGFXTexture()!;
const samplerDiffuseMap = device.getSampler(this.diffuseMap.getSamplerInfo());
this._globalDSManager.bindSampler(UNIFORM_DIFFUSEMAP_BINDING, samplerDiffuseMap);
this._globalDSManager.bindTexture(UNIFORM_DIFFUSEMAP_BINDING, textureDiffuseMap);
}
this._globalDSManager.update();
}
}
protected _destroy () {
+35 -7
View File
@@ -25,6 +25,7 @@
import { JSB } from 'internal:constants';
import { AABB } from '../../geometry';
import { legacyCC } from '../../global-exports';
import { Vec3 } from '../../math';
import { Light, LightType, nt2lm } from './light';
import { NativeSphereLight } from './native-scene';
@@ -70,15 +71,40 @@ export class SphereLight extends Light {
return this._range;
}
set luminance (lum: number) {
this._luminance = lum;
if (JSB) {
(this._nativeObj! as NativeSphereLight).setIlluminance(lum);
get luminance (): number {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (value: number) {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this.luminanceHDR = value;
} else {
this.luminanceLDR = value;
}
}
get luminance (): number {
return this._luminance;
get luminanceHDR () {
return this._luminanceHDR;
}
set luminanceHDR (value: number) {
this._luminanceHDR = value;
if (JSB) {
(this._nativeObj! as NativeSphereLight).setLuminanceHDR(value);
}
}
set luminanceLDR (value: number) {
this._luminanceLDR = value;
if (JSB) {
(this._nativeObj! as NativeSphereLight).setLuminanceLDR(value);
}
}
get aabb () {
@@ -88,7 +114,8 @@ export class SphereLight extends Light {
protected _needUpdate = false;
protected _size = 0.15;
protected _range = 1.0;
protected _luminance = 0;
protected _luminanceHDR = 0;
protected _luminanceLDR = 0;
protected _pos: Vec3;
protected _aabb: AABB;
@@ -106,6 +133,7 @@ export class SphereLight extends Light {
this.size = size;
this.range = 1.0;
this.luminance = 1700 / nt2lm(size);
this.luminanceLDR = 1.0;
}
public update () {
+39 -7
View File
@@ -25,6 +25,7 @@
import { JSB } from 'internal:constants';
import { AABB, Frustum } from '../../geometry';
import { legacyCC } from '../../global-exports';
import { Mat4, Quat, Vec3 } from '../../math';
import { Light, LightType, nt2lm } from './light';
import { NativeSpotLight } from './native-scene';
@@ -63,7 +64,9 @@ export class SpotLight extends Light {
protected _size = 0.15;
protected _luminance = 0;
protected _luminanceHDR = 0;
protected _luminanceLDR = 0;
protected _aspect = 0;
@@ -117,15 +120,43 @@ export class SpotLight extends Light {
return this._range;
}
set luminance (lum: number) {
this._luminance = lum;
if (JSB) {
(this._nativeObj! as NativeSpotLight).setIlluminance(lum);
get luminance (): number {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._luminanceHDR;
} else {
return this._luminanceLDR;
}
}
set luminance (value: number) {
const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this.luminanceHDR = value;
} else {
this.luminanceLDR = value;
}
}
get luminance (): number {
return this._luminance;
get luminanceHDR () {
return this._luminanceHDR;
}
set luminanceHDR (value: number) {
this._luminanceHDR = value;
if (JSB) {
(this._nativeObj! as NativeSpotLight).setLuminanceHDR(value);
}
}
get luminanceLDR () {
return this._luminanceLDR;
}
set luminanceLDR (value: number) {
this._luminanceLDR = value;
if (JSB) {
(this._nativeObj! as NativeSpotLight).setLuminanceLDR(value);
}
}
get direction (): Vec3 {
@@ -188,6 +219,7 @@ export class SpotLight extends Light {
this.size = size;
this.aspect = 1.0;
this.luminance = 1700 / nt2lm(size);
this.luminanceLDR = 1.0;
this.range = Math.cos(Math.PI / 6);
this._setDirection(new Vec3(1.0, -1.0, -1.0));
}
+245 -44
View File
@@ -24,22 +24,32 @@
* @module scene-graph
*/
import { ccclass, visible, type, displayOrder, slide, range, rangeStep, editable, serializable, rangeMin, tooltip } from 'cc.decorator';
import { ccclass, visible, type, displayOrder, readOnly, slide, range, rangeStep, editable, serializable, rangeMin, tooltip, formerlySerializedAs } from 'cc.decorator';
import { EDITOR } from 'internal:constants';
import { TextureCube } from '../assets/texture-cube';
import { CCFloat, CCBoolean, CCInteger } from '../data/utils/attribute';
import { Color, Quat, Vec3, Vec2, color } from '../math';
import { Color, Quat, Vec3, Vec2, Vec4 } from '../math';
import { Ambient } from '../renderer/scene/ambient';
import { Shadows, ShadowType, PCFType, ShadowSize } from '../renderer/scene/shadows';
import { Skybox } from '../renderer/scene/skybox';
import { Fog, FogType } from '../renderer/scene/fog';
import { Node } from './node';
import { legacyCC } from '../global-exports';
import { Root } from '../root';
const _up = new Vec3(0, 1, 0);
const _v3 = new Vec3();
const _qt = new Quat();
// Normalize HDR color
const normalizeHDRColor = (color : Vec4) => {
const intensity = 1.0 / Math.max(Math.max(color[0], color[1]), color[2]);
if (intensity < 1.0) {
for (let i = 0; i < 3; ++i) {
color[i] *= intensity;
}
}
};
/**
* @en Environment lighting information in the Scene
* @zh 场景的环境光照相关信息
@@ -47,25 +57,79 @@ const _qt = new Quat();
@ccclass('cc.AmbientInfo')
export class AmbientInfo {
@serializable
protected _skyColor = new Color(51, 128, 204, 1.0);
@formerlySerializedAs('_skyColor')
protected _skyColorHDR = new Vec4(0.2, 0.2, 0.2, 1.0);
@serializable
protected _skyIllum = Ambient.SKY_ILLUM;
@formerlySerializedAs('_skyIllum')
protected _skyIllumHDR = Ambient.SKY_ILLUM;
@serializable
protected _groundAlbedo = new Color(51, 51, 51, 255);
@formerlySerializedAs('_groundAlbedo')
protected _groundAlbedoHDR = new Vec4(0.2, 0.5, 0.8, 1.0);
@serializable
protected _skyColorLDR = new Vec4(0.2, 0.2, 0.2, 1.0);
@serializable
protected _skyIllumLDR = Ambient.SKY_ILLUM;
@serializable
protected _groundAlbedoLDR = new Vec4(0.2, 0.5, 0.8, 1.0);
protected _resource: Ambient | null = null;
get skyColorHDR () {
return this._skyColorHDR;
}
get groundAlbedoHDR () {
return this._groundAlbedoHDR;
}
get skyIllumHDR () {
return this._skyIllumHDR;
}
get skyColorLDR () {
return this._skyColorLDR;
}
get groundAlbedoLDR () {
return this._groundAlbedoLDR;
}
get skyIllumLDR () {
return this._skyIllumLDR;
}
/**
* @en Sky color
* @zh 天空颜色
* @en Sky lighting color configurable in editor with color picker
* @zh 编辑器中可配置的天空光照颜色(通过颜色拾取器)
*/
@editable
set skyColor (val: Color) {
this._skyColor.set(val);
if (this._resource) { this._resource.skyColor = this._skyColor; }
set skyLightingColor (val: Color) {
let result;
const color = new Vec4(val.x, val.y, val.z, val.w);
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._skyColorHDR = color;
(result as Vec4) = this._skyColorHDR;
} else {
this._skyColorLDR = color;
(result as Vec4) = this._skyColorLDR;
}
if (this._resource) { this._resource.skyColor = _v3.set(color.x, color.y, color.z); }
}
get skyColor () {
return this._skyColor;
get skyLightingColor () {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
const color = isHDR ? this._skyColorHDR.clone() : this._skyColorLDR.clone();
normalizeHDRColor(color);
return new Color(color.x * 255, color.y * 255, color.z * 255, 255);
}
set skyColor (val: Vec4) {
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._skyColorHDR = val;
} else {
this._skyColorLDR = val;
}
if (this._resource) { this._resource.skyColor = val; }
}
/**
@@ -75,29 +139,56 @@ export class AmbientInfo {
@editable
@type(CCFloat)
set skyIllum (val: number) {
this._skyIllum = val;
if (this._resource) { this._resource.skyIllum = this.skyIllum; }
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._skyIllumHDR = val;
} else {
this._skyIllumLDR = val;
}
if (this._resource) { this._resource.skyIllum = val; }
}
get skyIllum () {
return this._skyIllum;
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
return this._skyIllumHDR;
} else {
return this._skyIllumLDR;
}
}
/**
* @en Ground color
* @zh 地面颜色
* @en Ground lighting color configurable in editor with color picker
* @zh 编辑器中可配置的地面光照颜色(通过颜色拾取器)
*/
@editable
set groundAlbedo (val: Color) {
this._groundAlbedo.set(val);
// only RGB channels are used, alpha channel are intensionally left unchanged here
if (this._resource) { this._resource.groundAlbedo = this._groundAlbedo; }
set groundLightingColor (val: Color) {
let result;
const color = new Vec4(val.x, val.y, val.z, val.w);
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._groundAlbedoHDR = color;
(result as Vec4) = this._groundAlbedoHDR;
} else {
this._groundAlbedoLDR = color;
(result as Vec4) = this._groundAlbedoLDR;
}
if (this._resource) { this._resource.groundAlbedo = _v3.set(color.x, color.y, color.z); }
}
get groundAlbedo () {
return this._groundAlbedo;
get groundLightingColor () {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
const color = isHDR ? this._groundAlbedoHDR : this._groundAlbedoLDR;
normalizeHDRColor(color);
return new Color(color.x * 255, color.y * 255, color.z * 255, 255);
}
set groundAlbedo (val: Vec4) {
if ((legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR) {
this._groundAlbedoHDR = val;
} else {
this._groundAlbedoLDR = val;
}
if (this._resource) { this._resource.groundAlbedo = val; }
}
public activate (resource: Ambient) {
const aa :Ambient = resource;
this._resource = resource;
this._resource.initialize(this);
}
@@ -110,17 +201,52 @@ legacyCC.AmbientInfo = AmbientInfo;
*/
@ccclass('cc.SkyboxInfo')
export class SkyboxInfo {
@type(TextureCube)
protected _envmap: TextureCube | null = null;
@serializable
protected _isRGBE = false;
protected _applyDiffuseMap = false;
@serializable
@type(TextureCube)
@formerlySerializedAs('_envmap')
protected _envmapHDR: TextureCube | null = null;
@serializable
@type(TextureCube)
protected _envmapLDR: TextureCube | null = null;
@serializable
@type(TextureCube)
protected _diffuseMapHDR: TextureCube | null = null;
@serializable
@type(TextureCube)
protected _diffuseMapLDR: TextureCube | null = null;
@serializable
protected _enabled = false;
@serializable
protected _useIBL = false;
@serializable
protected _useHDR = false;
protected _resource: Skybox | null = null;
/**
* @en Whether to use diffuse convolution map. Enabled -> Will use map specified. Disabled -> Will revert to hemispheric lighting
* @zh 是否为IBL启用漫反射卷积图?不启用的话将使用默认的半球光照
*/
@visible(function (this : SkyboxInfo) {
if (this.useIBL) {
return true;
}
return false;
})
@editable
set applyDiffuseMap (val) {
this._applyDiffuseMap = val;
if (this._resource) {
this._resource.useDiffuseMap = val;
}
}
get applyDiffuseMap () {
return this._applyDiffuseMap;
}
/**
* @en Whether activate skybox in the scene
* @zh 是否启用天空盒?
@@ -129,6 +255,7 @@ export class SkyboxInfo {
set enabled (val) {
if (this._enabled === val) return;
this._enabled = val;
if (this._resource) {
this._resource.enabled = this._enabled;
}
@@ -144,43 +271,116 @@ export class SkyboxInfo {
@editable
set useIBL (val) {
this._useIBL = val;
if (this._resource) { this._resource.useIBL = this._useIBL; }
if (this._resource) {
this._resource.useIBL = this._useIBL;
}
}
get useIBL () {
return this._useIBL;
}
/**
* @en The texture cube used for the skybox
* @zh 使用的立方体贴图
* @en Toggle HDR (TODO: This SHOULD be moved into it's own subgroup away from skybox)
* @zh 是否启用HDR?
*/
@editable
@type(TextureCube)
set envmap (val) {
this._envmap = val;
if (this._resource) { this._resource.envmap = this._envmap; }
set useHDR (val) {
(legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR = val;
this._useHDR = val;
// Switch UI to and from LDR/HDR textures depends on HDR state
if (this._resource) {
this.envmap = this._resource.envmap;
this.diffuseMap = this._resource.diffuseMap;
if (this.diffuseMap == null) {
this.applyDiffuseMap = false;
}
}
if (this._resource) { this._resource.useHDR = this._useHDR; }
}
get envmap () {
return this._envmap;
get useHDR () {
(legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR = this._useHDR;
return this._useHDR;
}
/**
* @en Whether enable RGBE data support in skybox shader
* @zh 是否需要开启 shader 内的 RGBE 数据支持?
* @en The texture cube used for the skybox
* @zh 使用的立方体贴图
*/
@editable
set isRGBE (val) {
this._isRGBE = val;
if (this._resource) { this._resource.isRGBE = this._isRGBE; }
@type(TextureCube)
set envmap (val) {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._envmapHDR = val;
} else {
this._envmapLDR = val;
}
if (!this._envmapHDR) {
this._diffuseMapHDR = null;
this._applyDiffuseMap = false;
this.useIBL = false;
}
if (this._resource) {
this._resource.setEnvMaps(this._envmapHDR, this._envmapLDR);
this._resource.setDiffuseMaps(this._diffuseMapHDR, this._diffuseMapLDR);
this._resource.useDiffuseMap = this._applyDiffuseMap;
this._resource.envmap = val;
}
}
get isRGBE () {
return this._isRGBE;
get envmap () {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._envmapHDR;
} else {
return this._envmapLDR;
}
}
/**
* @en The optional diffusion convolution map used in tandem with IBL
* @zh 使用的漫反射卷积图
*/
@visible(function (this : SkyboxInfo) {
if (this.useIBL) {
return true;
}
return false;
})
@editable
@readOnly
@type(TextureCube)
set diffuseMap (val : TextureCube | null) {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
this._diffuseMapHDR = val;
} else {
this._diffuseMapLDR = val;
}
if (this._resource) {
this._resource.setDiffuseMaps(this._diffuseMapHDR, this._diffuseMapLDR);
}
}
get diffuseMap () {
const isHDR = (legacyCC.director.root as Root).pipeline.pipelineSceneData.isHDR;
if (isHDR) {
return this._diffuseMapHDR;
} else {
return this._diffuseMapLDR;
}
}
public activate (resource: Skybox) {
this._resource = resource;
this._resource.initialize(this);
this._resource.setEnvMaps(this._envmapHDR, this._envmapLDR);
this._resource.setDiffuseMaps(this._diffuseMapHDR, this._diffuseMapLDR);
this._resource.activate(); // update global DS first
}
}
@@ -759,6 +959,7 @@ export class SceneGlobals {
const sceneData = legacyCC.director.root.pipeline.pipelineSceneData;
this.ambient.activate(sceneData.ambient);
this.skybox.activate(sceneData.skybox);
this.shadows.activate(sceneData.shadows);
this.fog.activate(sceneData.fog);
}
+6
View File
@@ -0,0 +1,6 @@
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
#pragma define CC_USE_DIFFUSEMAP range([0, 2])
#pragma builtin(global)
layout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;
+1 -1
View File
@@ -19,7 +19,7 @@ layout(set = 0, binding = 1) uniform CCCamera {
highp mat4 cc_matViewProjInv; // inverse view-projection matrix
highp vec4 cc_cameraPos; // xyz: camera position
mediump vec4 cc_screenScale; // xy: screen scale, zw: inverse screen scale
mediump vec4 cc_exposure; // x: exposure, y: inverse exposure, z: HDR flag, w: exposure scale
mediump vec4 cc_exposure; // x: exposure, y: inverse exposure, z: HDR flag, w: unused
mediump vec4 cc_mainLitDir; // xyz: main direcitonal light direction
mediump vec4 cc_mainLitColor; // xyz: main direcitonal light color, w: intensity
mediump vec4 cc_ambientSky; //xyz: sky illumination color, w: intensity
+3 -2
View File
@@ -3,8 +3,9 @@
#include <gamma>
vec4 CCFragOutput (vec4 color) {
#if !CC_USE_HDR
color.rgb = LinearToSRGB(ACESToneMap(color.rgb));
#if CC_USE_HDR
color.rgb = ACESToneMap(color.rgb);
#endif
color.rgb = LinearToSRGB(color.rgb);
return color;
}
-3
View File
@@ -3,8 +3,5 @@
#include <gamma>
vec4 CCFragOutput (vec4 color) {
#if CC_USE_HDR
color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));
#endif
return color;
}
@@ -8,8 +8,12 @@
#if CC_USE_IBL
#include <cc-environment>
#include <unpack>
#include <texture-lod>
#include <unpack>
#if CC_USE_DIFFUSEMAP
#include <cc-diffusemap>
#endif
#endif
float GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {
@@ -94,23 +98,35 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {
finalColor *= dirlightContrib;
float fAmb = 0.5 - N.y * 0.5;
vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;
finalColor += (ambDiff.rgb * diffuse) * s.occlusion;
vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);
#if CC_USE_IBL
#if CC_USE_DIFFUSEMAP
// Diffuse reflection irradiance
vec4 diffuseMap = texture(cc_diffuseMap, N);
#if CC_USE_DIFFUSEMAP == IBL_RGBE
ambDiff = unpackRGBE(diffuseMap);
#else
ambDiff = SRGBToLinear(diffuseMap.rgb);
#endif
#endif
vec3 R = normalize(reflect(-V, N));
vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);
#if CC_USE_IBL == IBL_RGBE
vec3 env = unpackRGBE(envmap);
#else
vec3 env = SRGBToLinear(envmap.rgb);
#endif
finalColor += env * cc_ambientSky.w * specular * s.occlusion;
#endif
#if CC_USE_HDR
s.emissive *= cc_exposure.w;
#endif
finalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;
finalColor += s.emissive;
return vec4(finalColor, s.albedo.a);
-3
View File
@@ -99,9 +99,6 @@ struct ToonSurface {
// TODO: no ambient, no IBL for now
#if CC_USE_HDR
s.emissive *= cc_exposure.w;
#endif
finalColor += s.emissive;
return vec4(finalColor, s.baseColor.a);
+1 -1
View File
@@ -107,7 +107,7 @@ CCProgram unlit-vs %{
CCProgram unlit-fs %{
precision highp float;
#include <output>
#include <output-standard>
#include <cc-fog-fs>
#if USE_ALPHA_TEST