mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Vendored
+55
-1
@@ -62,6 +62,7 @@ declare module 'pal/input' {
|
||||
public static _on (eventType: import('cocos/input/types/event-enum').InputEventType, cb: GamepadCallback, target?: any);
|
||||
|
||||
public static all: GamepadInputDevice[];
|
||||
public static xr: (GamepadInputDevice | null);
|
||||
/**
|
||||
* @en The gamepad device id
|
||||
* @zh 手柄设备 id
|
||||
@@ -159,6 +160,59 @@ declare module 'pal/input' {
|
||||
* @zh 开始按键
|
||||
*/
|
||||
public get buttonStart (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The grab Left Grip
|
||||
* @zh 左手柄握住
|
||||
*/
|
||||
public get gripLeft (): InputSourceButton;
|
||||
/**
|
||||
* @en The grab Right Grip
|
||||
* @zh 右手柄握住
|
||||
*/
|
||||
public get gripRight (): InputSourceButton;
|
||||
|
||||
/**
|
||||
* @en The position Left hand
|
||||
* @zh 左手位置
|
||||
*/
|
||||
public get handLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left hand
|
||||
* @zh 左手方向
|
||||
*/
|
||||
public get handLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right hand
|
||||
* @zh 右手位置
|
||||
*/
|
||||
public get handRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right hand
|
||||
* @zh 右手方向
|
||||
*/
|
||||
public get handRightOrientation (): InputSourceOrientation;
|
||||
|
||||
/**
|
||||
* @en The position Left aim
|
||||
* @zh 左射线位置
|
||||
*/
|
||||
public get aimLeftPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Left aim
|
||||
* @zh 左射线方向
|
||||
*/
|
||||
public get aimLeftOrientation (): InputSourceOrientation;
|
||||
/**
|
||||
* @en The position Right aim
|
||||
* @zh 右射线位置
|
||||
*/
|
||||
public get aimRightPosition (): InputSourcePosition;
|
||||
/**
|
||||
* @en The orientation Right aim
|
||||
* @zh 右射线方向
|
||||
*/
|
||||
public get aimRightOrientation (): InputSourceOrientation;
|
||||
}
|
||||
|
||||
type AccelerometerCallback = (res: import('cocos/input/types').EventAcceleration) => void;
|
||||
@@ -374,7 +428,7 @@ declare module 'pal/input' {
|
||||
/**
|
||||
* Class designed for Handheld input.
|
||||
*/
|
||||
export class HandheldInputDevice {
|
||||
export class HandheldInputDevice {
|
||||
/**
|
||||
* Register the handheld event callback.
|
||||
* @engineInternal
|
||||
|
||||
@@ -319,7 +319,7 @@ export const bmfontUtils = {
|
||||
this._recordLetterInfo(letterPosition, character, letterIndex, lineIndex);
|
||||
|
||||
if (letterIndex + 1 < _horizontalKerning.length && letterIndex < textLen - 1) {
|
||||
nextLetterX += _horizontalKerning[letterIndex + 1];
|
||||
nextLetterX += _horizontalKerning[letterIndex + 1] * _bmfontScale;
|
||||
}
|
||||
|
||||
nextLetterX += letterDef.xAdvance * _bmfontScale + _spacingX;
|
||||
|
||||
@@ -618,7 +618,7 @@ export class Mask extends Component {
|
||||
public getMaterial (idx: number): any {
|
||||
warnID(9007);
|
||||
if (this.subComp) {
|
||||
return this.subComp.getMaterial(idx);
|
||||
return this.subComp.getSharedMaterial(idx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, multil
|
||||
import { DEBUG, DEV, EDITOR } from 'internal:constants';
|
||||
import { Font, SpriteAtlas, TTFFont, SpriteFrame } from '../assets';
|
||||
import { EventTouch } from '../../input/types';
|
||||
import { assert, warnID, Color, Vec2, CCObject, cclegacy, js } from '../../core';
|
||||
import { assert, warnID, Color, Vec2, CCObject, cclegacy, js, Size } from '../../core';
|
||||
import { BASELINE_RATIO, fragmentText, isUnicodeCJK, isUnicodeSpace, getEnglishWordPartAtFirst, getEnglishWordPartAtLast } from '../utils/text-utils';
|
||||
import { HtmlTextParser, IHtmlTextParserResultObj, IHtmlTextParserStack } from '../utils/html-text-parser';
|
||||
import { Node } from '../../scene-graph';
|
||||
@@ -42,6 +42,9 @@ const _htmlTextParser = new HtmlTextParser();
|
||||
const RichTextChildName = 'RICHTEXT_CHILD';
|
||||
const RichTextChildImageName = 'RICHTEXT_Image_CHILD';
|
||||
|
||||
const _tempSize = new Vec2();
|
||||
const _tempSizeLeft = new Vec2();
|
||||
|
||||
/**
|
||||
* 富文本池。<br/>
|
||||
*/
|
||||
@@ -582,14 +585,14 @@ export class RichText extends Component {
|
||||
return partStringArr;
|
||||
}
|
||||
|
||||
const labelSize = this._calculateSize(styleIndex, text);
|
||||
if (labelSize.x < 2048) {
|
||||
this._calculateSize(_tempSize, styleIndex, text);
|
||||
if (_tempSize.x < 2048) {
|
||||
partStringArr.push(text);
|
||||
} else {
|
||||
const multilineTexts = text.split('\n');
|
||||
for (let i = 0; i < multilineTexts.length; i++) {
|
||||
const thisPartSize = this._calculateSize(styleIndex, multilineTexts[i]);
|
||||
if (thisPartSize.x < 2048) {
|
||||
this._calculateSize(_tempSize, styleIndex, multilineTexts[i]);
|
||||
if (_tempSize.x < 2048) {
|
||||
partStringArr.push(multilineTexts[i]);
|
||||
} else {
|
||||
const thisPartSplitResultArr = this.splitLongStringOver2048(multilineTexts[i], styleIndex);
|
||||
@@ -611,12 +614,16 @@ export class RichText extends Component {
|
||||
let curEnd = longStr.length / 2;
|
||||
let curString = longStr.substring(curStart, curEnd);
|
||||
let leftString = longStr.substring(curEnd);
|
||||
let curStringSize = this._calculateSize(styleIndex, curString);
|
||||
let leftStringSize = this._calculateSize(styleIndex, leftString);
|
||||
const curStringSize = this._calculateSize(_tempSize, styleIndex, curString);
|
||||
const leftStringSize = this._calculateSize(_tempSizeLeft, styleIndex, leftString);
|
||||
let maxWidth = this._maxWidth;
|
||||
if (this._maxWidth === 0) {
|
||||
maxWidth = 2047.9; // Callback when maxWidth is 0
|
||||
}
|
||||
|
||||
// a line should be an unit to split long string
|
||||
const lineCountForOnePart = 1;
|
||||
const sizeForOnePart = lineCountForOnePart * this.maxWidth;
|
||||
const sizeForOnePart = lineCountForOnePart * maxWidth;
|
||||
|
||||
// divide text into some pieces of which the size is less than sizeForOnePart
|
||||
while (curStringSize.x > sizeForOnePart) {
|
||||
@@ -629,7 +636,7 @@ export class RichText extends Component {
|
||||
|
||||
curString = curString.substring(curStart, curEnd);
|
||||
leftString = longStr.substring(curEnd);
|
||||
curStringSize = this._calculateSize(styleIndex, curString);
|
||||
this._calculateSize(curStringSize, styleIndex, curString);
|
||||
}
|
||||
|
||||
// avoid too many loops
|
||||
@@ -647,7 +654,7 @@ export class RichText extends Component {
|
||||
|
||||
curString = longStr.substring(curStart, curEnd);
|
||||
leftString = longStr.substring(curEnd);
|
||||
curStringSize = this._calculateSize(styleIndex, curString);
|
||||
this._calculateSize(curStringSize, styleIndex, curString);
|
||||
|
||||
leftTryTimes--;
|
||||
}
|
||||
@@ -656,7 +663,7 @@ export class RichText extends Component {
|
||||
while (leftTryTimes && curString.length >= 2 && curStringSize.x > sizeForOnePart) {
|
||||
curEnd -= curWordStep;
|
||||
curString = longStr.substring(curStart, curEnd);
|
||||
curStringSize = this._calculateSize(styleIndex, curString);
|
||||
this._calculateSize(curStringSize, styleIndex, curString);
|
||||
// after the first reduction, the step should be 1.
|
||||
curWordStep = 1;
|
||||
|
||||
@@ -684,19 +691,21 @@ export class RichText extends Component {
|
||||
|
||||
curString = longStr.substring(curStart, curEnd);
|
||||
leftString = longStr.substring(curEnd);
|
||||
leftStringSize = this._calculateSize(styleIndex, leftString);
|
||||
this._calculateSize(leftStringSize, styleIndex, leftString);
|
||||
this._calculateSize(curStringSize, styleIndex, curString);
|
||||
|
||||
leftTryTimes--;
|
||||
|
||||
// Exit: If the left part string size is less than 2048, the method will finish.
|
||||
if (leftStringSize.x < 2048) {
|
||||
if (leftStringSize.x < 2048 && curStringSize.x < sizeForOnePart) {
|
||||
partStringArr.push(curString);
|
||||
curStart = text.length;
|
||||
curEnd = text.length;
|
||||
curString = leftString;
|
||||
partStringArr.push(curString);
|
||||
if (leftString !== '') {
|
||||
partStringArr.push(curString);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
curStringSize = this._calculateSize(styleIndex, curString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,8 +714,8 @@ export class RichText extends Component {
|
||||
|
||||
protected _measureText (styleIndex: number, string?: string) {
|
||||
const func = (s: string) => {
|
||||
const labelSize = this._calculateSize(styleIndex, s);
|
||||
return labelSize.width;
|
||||
const width = this._calculateSize(_tempSize, styleIndex, s).x;
|
||||
return width;
|
||||
};
|
||||
if (string) {
|
||||
return func(string);
|
||||
@@ -718,7 +727,7 @@ export class RichText extends Component {
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
protected _calculateSize (styleIndex: number, s: string) {
|
||||
protected _calculateSize (out: Vec2, styleIndex: number, s: string) {
|
||||
let label: ISegment;
|
||||
if (this._labelSegmentsCache.length === 0) {
|
||||
label = this._createFontLabel(s);
|
||||
@@ -729,8 +738,9 @@ export class RichText extends Component {
|
||||
}
|
||||
label.styleIndex = styleIndex;
|
||||
this._applyTextAttribute(label);
|
||||
const labelSize = label.node._uiProps.uiTransformComp!.contentSize;
|
||||
return labelSize;
|
||||
const size = label.node._uiProps.uiTransformComp!.contentSize;
|
||||
Vec2.set(out, size.x, size.y);
|
||||
return out;
|
||||
}
|
||||
|
||||
protected _onTouchEnded (event: EventTouch) {
|
||||
|
||||
@@ -119,6 +119,7 @@ export class SpriteRenderer extends ModelRenderer {
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
super.onEnable();
|
||||
if (!this._model) {
|
||||
this._updateModels();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
import { Color, assert, ccenum, cclegacy } from '../../core';
|
||||
import { builtinResMgr } from '../../asset/asset-manager';
|
||||
import { Material } from '../../asset/assets';
|
||||
import { BlendFactor } from '../../gfx';
|
||||
import { BlendFactor, BlendOp, ColorMask } from '../../gfx';
|
||||
import { IAssembler, IAssemblerManager } from '../renderer/base';
|
||||
import { RenderData } from '../renderer/render-data';
|
||||
import { IBatcher } from '../renderer/i-batcher';
|
||||
@@ -47,6 +47,8 @@ import { director } from '../../game';
|
||||
|
||||
// hack
|
||||
ccenum(BlendFactor);
|
||||
ccenum(BlendOp);
|
||||
ccenum(ColorMask);
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -434,7 +436,7 @@ export class UIRenderer extends Renderer {
|
||||
if (DEBUG) {
|
||||
assert(this.isValid, 'this component should not be invalid!');
|
||||
}
|
||||
return this.getMaterial(0) !== null
|
||||
return this.getSharedMaterial(0) !== null
|
||||
&& this._enabled
|
||||
&& this._color.a > 0;
|
||||
}
|
||||
@@ -446,7 +448,7 @@ export class UIRenderer extends Renderer {
|
||||
*/
|
||||
public updateMaterial () {
|
||||
if (this._customMaterial) {
|
||||
if (this.getMaterial(0) !== this._customMaterial) {
|
||||
if (this.getSharedMaterial(0) !== this._customMaterial) {
|
||||
this.setMaterial(this._customMaterial, 0);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -53,10 +53,8 @@ const _dsInfo = new DescriptorSetInfo(null!);
|
||||
const m4_1 = new Mat4();
|
||||
|
||||
/**
|
||||
* @en
|
||||
* UI render flow
|
||||
* @zh
|
||||
* UI 渲染流程
|
||||
* @en UI rendering process
|
||||
* @zh UI 渲染流程
|
||||
*/
|
||||
export class Batcher2D implements IBatcher {
|
||||
protected declare _nativeObj: NativeBatcher2d;
|
||||
|
||||
@@ -28,6 +28,17 @@ import { Filter } from '../../../asset/assets/asset-enum';
|
||||
import { Atlas } from './atlas';
|
||||
import { director } from '../../../game';
|
||||
|
||||
/**
|
||||
* @en The dynamic atlas manager which manages all runtime dynamic packed atlas texture for UI rendering.
|
||||
* It generates a maximum of [[maxAtlasCount]] atlas texture, all atlas texture have the size of [[textureSize]].
|
||||
* Normally the [[Root.batcher2D]] is in charge of submitting sprite frames to the dynamic atlas manager, the process is transparent to user.
|
||||
* Note that the first committed sprite frame will define the filter settings of the atlas textures,
|
||||
* only sprite frame with the same setting will be accepted afterward.
|
||||
* @zh 动态合图的管理器,管理所有运行时动态合成的图集,主要用于 UI 渲染。
|
||||
* 该管理器支持生成 [[maxAtlasCount]] 张动态合图,并且所有合图都有同样的 [[textureSize]] 像素尺寸。
|
||||
* 一般来说 [[Root.batcher2D]] 负责提交 [[SpriteFrame]] 到动态合图管理器中,这个过程对于开发者是透明的。
|
||||
* 需要注意的是,第一个提交的 [[SpriteFrame]] 会决定图集的过滤器参数,在此之后只有同样参数的贴图才会被管理器接受。
|
||||
*/
|
||||
export class DynamicAtlasManager extends System {
|
||||
public static instance: DynamicAtlasManager;
|
||||
|
||||
@@ -274,8 +285,9 @@ export class DynamicAtlasManager extends System {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Dynamic Atlas Manager,use to auto merge sprite frame.
|
||||
* @zh 动态合图管理器,用于引擎的自动合图功能。
|
||||
* @en The singleton instance of [[DynamicAtlasManager]], please use [[DynamicAtlasManager.instance]] instead.
|
||||
* @zh [[DynamicAtlasManager]] 的单例对象,请直接使用 [[DynamicAtlasManager.instance]]。
|
||||
* @deprecated since v3.7
|
||||
*/
|
||||
export const dynamicAtlasManager: DynamicAtlasManager = DynamicAtlasManager.instance = new DynamicAtlasManager();
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ import './font-loader';
|
||||
|
||||
export * from './html-text-parser';
|
||||
export * from './text-utils';
|
||||
export { dynamicAtlasManager } from './dynamic-atlas/atlas-manager';
|
||||
export * from './dynamic-atlas/atlas-manager';
|
||||
|
||||
@@ -48,6 +48,7 @@ bakedSkinningModelProto._ctor = function () {
|
||||
this._jointsMedium = { buffer: null, jointTextureInfo, animInfo, texture: null, boundsInfo: null };
|
||||
this._skeleton = null;
|
||||
this._mesh = null;
|
||||
this._registerOnDestroy();
|
||||
};
|
||||
|
||||
const oldDestroy = bakedSkinningModelProto.destroy;
|
||||
@@ -59,6 +60,11 @@ bakedSkinningModelProto.destroy = function () {
|
||||
oldDestroy.call(this);
|
||||
};
|
||||
|
||||
// tips:for native platform need call jointTexturePool.releaseHandle(oldTex)
|
||||
bakedSkinningModelProto._onDestroy = function () {
|
||||
this._applyJointTexture();
|
||||
}
|
||||
|
||||
const oldBindSkeleton = bakedSkinningModelProto.bindSkeleton;
|
||||
bakedSkinningModelProto.bindSkeleton = function (skeleton: Skeleton | null = null, skinningRoot: Node | null = null, mesh: Mesh | null = null) {
|
||||
this._skeleton = skeleton;
|
||||
|
||||
@@ -248,6 +248,7 @@ export class ReflectionProbe extends Component {
|
||||
* @en fast bake no convolution.
|
||||
* @zh 快速烘焙不会进行卷积。
|
||||
*/
|
||||
@visible(function (this: ReflectionProbe) { return this.probeType === ProbeType.CUBE; })
|
||||
@type(CCBoolean)
|
||||
@tooltip('i18n:reflection_probe.fastBake')
|
||||
get fastBake () {
|
||||
|
||||
@@ -183,6 +183,7 @@ export class SkeletalAnimationState extends AnimationState {
|
||||
users.forEach((user) => {
|
||||
user.uploadAnimation(clip);
|
||||
});
|
||||
info.data[0] = -1; // reset frame index to -1. sampleCurves will calculate frame to 0.
|
||||
}
|
||||
|
||||
const curFrame = (ratio * this._frames + 0.5) | 0;
|
||||
|
||||
@@ -179,7 +179,11 @@ export class JointTexturePool {
|
||||
public registerCustomTextureLayouts (layouts: ICustomJointTextureLayout[]) {
|
||||
for (let i = 0; i < layouts.length; i++) {
|
||||
const layout = layouts[i];
|
||||
const chunkIdx = this._customPool.createChunk(layout.textureLength);
|
||||
let textureLength = layout.textureLength;
|
||||
if (!(this._device.getFormatFeatures(Format.RGBA32F) & FormatFeatureBit.SAMPLED_TEXTURE)) {
|
||||
textureLength *= 2; // RGBA8 format textures need 4 times the memory.
|
||||
}
|
||||
const chunkIdx = this._customPool.createChunk(textureLength);
|
||||
for (let j = 0; j < layout.contents.length; j++) {
|
||||
const content = layout.contents[j];
|
||||
const { skeleton } = content;
|
||||
@@ -489,7 +493,6 @@ export class JointAnimationInfo {
|
||||
info.currentClip = clip;
|
||||
info.data[0] = 0; // reset default frame 0
|
||||
info.buffer.update(info.data);
|
||||
info.data[0] = -1; // reset frame index to -1. sampleCurves will calculate frame to 0.
|
||||
info.dirty = false;
|
||||
if (JSB) {
|
||||
info.dirtyForJSB[0] = 0;
|
||||
|
||||
@@ -114,7 +114,7 @@ export class SkinnedMeshUnit {
|
||||
if (!comp) { return; }
|
||||
this.mesh = comp.mesh;
|
||||
this.skeleton = comp.skeleton;
|
||||
this.material = comp.getMaterial(0);
|
||||
this.material = comp.getSharedMaterial(0);
|
||||
if (comp.skinningRoot) { getWorldTransformUntilRoot(comp.node, comp.skinningRoot, this._localTransform); }
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ export class SkinnedMeshBatchRenderer extends SkinnedMeshRenderer {
|
||||
|
||||
public cookMaterials () {
|
||||
if (!this._batchMaterial) {
|
||||
this._batchMaterial = this.getMaterial(0);
|
||||
this._batchMaterial = this.getSharedMaterial(0);
|
||||
}
|
||||
const mat = this.getMaterialInstance(0);
|
||||
if (!mat || !this._batchMaterial || !this._batchMaterial.effectAsset) {
|
||||
|
||||
@@ -80,9 +80,9 @@ export class SkinnedMeshRenderer extends MeshRenderer {
|
||||
}
|
||||
|
||||
set skinningRoot (value) {
|
||||
if (value === this._skinningRoot) { return; }
|
||||
this._skinningRoot = value;
|
||||
this._tryBindAnimation();
|
||||
if (value === this._skinningRoot) { return; }
|
||||
this._update();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import { Asset } from '../assets';
|
||||
import { js, cclegacy } from '../../core';
|
||||
import Cache from './cache';
|
||||
import { decodeUuid, normalize } from './helper';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
|
||||
export interface IConfigOption {
|
||||
importBase: string;
|
||||
@@ -147,7 +148,7 @@ const isMatchByWord = (path: string, test: string): boolean => {
|
||||
};
|
||||
|
||||
const processOptions = (options: IConfigOption) => {
|
||||
if (EDITOR || TEST) { return; }
|
||||
if ((EDITOR && !legacyCC.GAME_VIEW) || TEST) { return; }
|
||||
let uuids = options.uuids;
|
||||
const paths = options.paths;
|
||||
const types = options.types;
|
||||
|
||||
@@ -32,6 +32,7 @@ import { files } from './shared';
|
||||
import { retry, RetryFunction, urlAppendTimestamp } from './utilities';
|
||||
import { IConfigOption } from './config';
|
||||
import { CCON, parseCCONJson, decodeCCONBinary } from '../../serialization/ccon';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
|
||||
export type DownloadHandler = (url: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: any | null) => void)) => void;
|
||||
|
||||
@@ -122,7 +123,7 @@ const downloadBundle = (nameOrUrl: string, options: Record<string, any>, onCompl
|
||||
url = `assets/${bundleName}`;
|
||||
}
|
||||
}
|
||||
const version = options.version || downloader.bundleVers![bundleName];
|
||||
const version = options.version || downloader.bundleVers[bundleName];
|
||||
let count = 0;
|
||||
const config = `${url}/config.${version ? `${version}.` : ''}json`;
|
||||
let out: IConfigOption | null = null;
|
||||
@@ -213,12 +214,12 @@ export class Downloader {
|
||||
* You don't need to change it at runtime.
|
||||
* @internal
|
||||
*/
|
||||
public appendTimeStamp = !!EDITOR;
|
||||
public appendTimeStamp = !!(EDITOR && !legacyCC.GAME_VIEW);
|
||||
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
public limited = !EDITOR;
|
||||
public limited = !(EDITOR && !legacyCC.GAME_VIEW);
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -231,14 +232,14 @@ export class Downloader {
|
||||
public retryInterval = 2000;
|
||||
|
||||
/**
|
||||
* Version information of all bundles.
|
||||
* @engineInternal
|
||||
* @en Version information of all bundles.
|
||||
* @zh 所有包的版本信息。
|
||||
*/
|
||||
public bundleVers: Record<string, string> | null = null;
|
||||
public bundleVers: Record<string, string> = {};
|
||||
|
||||
/**
|
||||
* Remote bundle list.
|
||||
* @engineInternal
|
||||
* @en The names of remote bundles.
|
||||
* @zh 远程包名列表。
|
||||
*/
|
||||
public remoteBundles: ReadonlyArray<string> = [];
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
import { ccclass } from 'cc.decorator';
|
||||
import { EDITOR, TEST } from 'internal:constants';
|
||||
import { clamp, cclegacy, errorID } from '../../core';
|
||||
import { Texture, ColorAttachment, DepthStencilAttachment, GeneralBarrierInfo, AccessFlagBit, RenderPassInfo, Format, deviceManager, BufferTextureCopy } from '../../gfx';
|
||||
import { Texture, ColorAttachment, DepthStencilAttachment, GeneralBarrierInfo, AccessFlagBit, RenderPassInfo, Format, deviceManager,
|
||||
BufferTextureCopy, TextureFlags, TextureFlagBit } from '../../gfx';
|
||||
import { RenderWindow, IRenderWindowInfo } from '../../render-scene/core/render-window';
|
||||
import { Root } from '../../root';
|
||||
import { TextureBase } from './texture-base';
|
||||
@@ -35,6 +36,9 @@ export interface IRenderTextureCreateInfo {
|
||||
width: number;
|
||||
height: number;
|
||||
passInfo?: RenderPassInfo;
|
||||
externalResLow?: number; // for vulkan vkImage/opengl es texture created from external
|
||||
externalResHigh?: number; // for vulkan vkImage created from external
|
||||
externalFlag?: TextureFlags; // external texture type normal or oes
|
||||
}
|
||||
|
||||
const _colorAttachment = new ColorAttachment();
|
||||
@@ -168,6 +172,9 @@ export class RenderTexture extends TextureBase {
|
||||
_windowInfo.width = this._width;
|
||||
_windowInfo.height = this._height;
|
||||
_windowInfo.renderPassInfo = info && info.passInfo ? info.passInfo : passInfo;
|
||||
_windowInfo.externalResLow = info && info.externalResLow ? info.externalResLow : 0;
|
||||
_windowInfo.externalResHigh = info && info.externalResHigh ? info.externalResHigh : 0;
|
||||
_windowInfo.externalFlag = info && info.externalFlag ? info.externalFlag : TextureFlagBit.NONE;
|
||||
|
||||
_colorAttachment.barrier = deviceManager.gfxDevice.getGeneralBarrier(new GeneralBarrierInfo(
|
||||
AccessFlagBit.FRAGMENT_SHADER_READ_TEXTURE,
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { EDITOR, TEST, VIVO, WECHAT, WECHAT_MINI_PROGRAM } from 'internal:constants';
|
||||
import { EDITOR, OPPO, TEST, VIVO, WECHAT, WECHAT_MINI_PROGRAM } from 'internal:constants';
|
||||
import { ccclass, serializable } from 'cc.decorator';
|
||||
import { TextureType, TextureInfo, TextureViewInfo, BufferTextureCopy } from '../../gfx';
|
||||
import { ImageAsset } from './image-asset';
|
||||
@@ -190,7 +190,7 @@ export class TextureCube extends SimpleTexture {
|
||||
}
|
||||
//In ios wechat mini-game platform drawImage and getImageData can not get correct data,so upload to gfxTexture than use readPixels to get data
|
||||
//The performance of upload to gfxTexture and readPixels is not good, so only use this way in the ios wechat mini-game platform
|
||||
if (((WECHAT || WECHAT_MINI_PROGRAM) && sys.os === OS.IOS) || VIVO) {
|
||||
if (((WECHAT || WECHAT_MINI_PROGRAM) && sys.os === OS.IOS) || VIVO || OPPO) {
|
||||
this._uploadAtlas();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import { getClassName, getset, isEmptyObject } from './js';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { warnID } from '../platform/debug';
|
||||
import { macro } from '../platform/macro';
|
||||
import { setTimeoutRAF } from '../../../pal/utils';
|
||||
|
||||
export const BUILTIN_CLASSID_RE = /^(?:cc|dragonBones|sp|ccsg)\..+/;
|
||||
|
||||
@@ -163,7 +164,7 @@ export function isDomNode (node) {
|
||||
*/
|
||||
export function callInNextTick (callback, p1?: any, p2?: any) {
|
||||
if (callback) {
|
||||
setTimeout(() => {
|
||||
setTimeoutRAF(() => {
|
||||
callback(p1, p2);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@@ -107,16 +107,35 @@ BitMask.getList = (BitMaskDef) => {
|
||||
return BitMaskDef.__bitmask__;
|
||||
}
|
||||
|
||||
const bitlist: any[] = BitMaskDef.__bitmask__ = [];
|
||||
return BitMask.update(BitMaskDef);
|
||||
};
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Update BitMask object properties.
|
||||
* @zh
|
||||
* 更新 BitMask 对象的属性列表。
|
||||
*
|
||||
* @param BitMaskDef
|
||||
* @returns @en A sorted array with integer values. @zh 存储整型属性值的数组。该数组已排序。
|
||||
*/
|
||||
BitMask.update = (BitMaskDef) => {
|
||||
if (!Array.isArray(BitMaskDef.__bitmask__)) {
|
||||
BitMaskDef.__bitmask__ = [];
|
||||
}
|
||||
|
||||
const bitList = BitMaskDef.__bitmask__;
|
||||
bitList.length = 0;
|
||||
|
||||
for (const name in BitMaskDef) {
|
||||
const v = BitMaskDef[name];
|
||||
if (Number.isInteger(v)) {
|
||||
bitlist.push({ name, value: v });
|
||||
bitList.push({ name, value: v });
|
||||
}
|
||||
}
|
||||
bitlist.sort((a, b) => a.value - b.value);
|
||||
return bitlist;
|
||||
bitList.sort((a, b) => a.value - b.value);
|
||||
|
||||
return bitList;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,6 @@ const { ccclass } = _decorator;
|
||||
* DragonBones factory
|
||||
* @class CCFactory
|
||||
* @extends BaseFactory
|
||||
* @engineInternal
|
||||
* @en Usually only one global factory instance is needed. The factory creates
|
||||
* Armature object by parsing DragonBonesData and TextureAtlasData instances,
|
||||
* and is responsible for global updating the Dragonbones component animation
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
} from '../gfx';
|
||||
import { PipelineStateManager } from '../rendering';
|
||||
import { SetIndex } from '../rendering/define';
|
||||
import { ccwindow } from '../core/global-exports';
|
||||
import { ccwindow, legacyCC } from '../core/global-exports';
|
||||
import { XREye } from '../xr/xr-enums';
|
||||
|
||||
const v2_0 = new Vec2();
|
||||
@@ -502,7 +502,7 @@ export class SplashScreen {
|
||||
device.flushCommands([cmdBuff]);
|
||||
device.queue.submit([cmdBuff]);
|
||||
device.present();
|
||||
device.enableAutoBarrier(false);
|
||||
device.enableAutoBarrier(!legacyCC.rendering);
|
||||
|
||||
if (sys.isXR) {
|
||||
xr.entry.renderLoopEnd(xrEye);
|
||||
|
||||
@@ -400,6 +400,8 @@ export enum TextureFlagBit {
|
||||
NONE = 0,
|
||||
GEN_MIPMAP = 0x1, // Generate mipmaps using bilinear filter
|
||||
GENERAL_LAYOUT = 0x2, // For inout framebuffer attachments
|
||||
EXTERNAL_OES = 0x4, // External oes texture
|
||||
EXTERNAL_NORMAL = 0x8, // External normal texture
|
||||
}
|
||||
|
||||
export enum FormatFeatureBit {
|
||||
|
||||
@@ -2756,6 +2756,20 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2Device, cmdPackage: WebG
|
||||
} // for
|
||||
}
|
||||
|
||||
function toUseTexImage2D (texImages: Readonly<TexImageSource[]>, regions: Readonly<BufferTextureCopy[]>) {
|
||||
if (texImages.length > 1 || regions.length > 1) return false;
|
||||
const isVideoElement = texImages[0] instanceof HTMLVideoElement;
|
||||
if (isVideoElement) {
|
||||
const videoElement = texImages[0] as HTMLVideoElement;
|
||||
const isSameSize = regions[0].texOffset.x === 0
|
||||
&& regions[0].texOffset.y === 0
|
||||
&& regions[0].texExtent.width === videoElement.videoWidth
|
||||
&& regions[0].texExtent.height === videoElement.videoHeight;
|
||||
return isSameSize;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function WebGL2CmdFuncCopyTexImagesToTexture (
|
||||
device: WebGL2Device,
|
||||
texImages: Readonly<TexImageSource[]>,
|
||||
@@ -2774,11 +2788,16 @@ export function WebGL2CmdFuncCopyTexImagesToTexture (
|
||||
|
||||
switch (gpuTexture.glTarget) {
|
||||
case gl.TEXTURE_2D: {
|
||||
for (let k = 0; k < regions.length; k++) {
|
||||
const region = regions[k];
|
||||
gl.texSubImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y,
|
||||
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
|
||||
if (toUseTexImage2D(texImages, regions)) {
|
||||
gl.texImage2D(gl.TEXTURE_2D, regions[0].texSubres.mipLevel, gpuTexture.glInternalFmt, regions[0].texExtent.width,
|
||||
regions[0].texExtent.height, 0, gpuTexture.glFormat, gpuTexture.glType, texImages[0]);
|
||||
} else {
|
||||
for (let k = 0; k < regions.length; k++) {
|
||||
const region = regions[k];
|
||||
gl.texSubImage2D(gl.TEXTURE_2D, region.texSubres.mipLevel,
|
||||
region.texOffset.x, region.texOffset.y,
|
||||
gpuTexture.glFormat, gpuTexture.glType, texImages[n++]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export function getExtensions (gl: WebGL2RenderingContext) {
|
||||
export function getContext (canvas: HTMLCanvasElement): WebGL2RenderingContext | null {
|
||||
let context: WebGL2RenderingContext | null = null;
|
||||
try {
|
||||
if (globalThis.__globalXR.webxrCompatible) {
|
||||
if (globalThis.__globalXR?.webxrCompatible) {
|
||||
const glAttribs = {
|
||||
alpha: macro.ENABLE_TRANSPARENT_CANVAS,
|
||||
antialias: EDITOR || macro.ENABLE_WEBGL_ANTIALIAS,
|
||||
|
||||
@@ -347,6 +347,7 @@ export class Input {
|
||||
const eventGamepadList = this._eventGamepadList;
|
||||
GamepadInputDevice._on(InputEventType.GAMEPAD_CHANGE, (event) => { this._dispatchOrPushEvent(event, eventGamepadList); });
|
||||
GamepadInputDevice._on(InputEventType.GAMEPAD_INPUT, (event) => { this._dispatchOrPushEvent(event, eventGamepadList); });
|
||||
GamepadInputDevice._on(InputEventType.HANDLE_POSE_INPUT, (event) => { this._dispatchOrPushEvent(event, eventGamepadList); });
|
||||
}
|
||||
|
||||
if (sys.hasFeature(sys.Feature.EVENT_HANDLE)) {
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
|
||||
import { Camera } from './camera-component';
|
||||
import { replaceProperty, cclegacy, js } from '../core';
|
||||
import { replaceProperty, cclegacy, js, markAsWarning } from '../core';
|
||||
import { ModelRenderer } from './model-renderer';
|
||||
import { Renderer } from './renderer';
|
||||
|
||||
replaceProperty(Camera, 'Camera', [
|
||||
{
|
||||
@@ -51,6 +52,14 @@ replaceProperty(Camera.prototype, 'Camera.prototype', [
|
||||
},
|
||||
]);
|
||||
|
||||
// deprecate Renderer API
|
||||
markAsWarning(Renderer.prototype, 'Renderer.prototype', [
|
||||
{
|
||||
name: 'getMaterial',
|
||||
suggest: 'please use renderer.getSharedMaterial instead.',
|
||||
},
|
||||
]);
|
||||
|
||||
/**
|
||||
* Alias of [[Camera]]
|
||||
* @deprecated Since v1.2
|
||||
|
||||
@@ -60,7 +60,7 @@ export class Renderer extends Component {
|
||||
* @zh 获取默认的共享材质
|
||||
*/
|
||||
get sharedMaterial () {
|
||||
return this.getMaterial(0);
|
||||
return this.getSharedMaterial(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,11 +138,18 @@ export class Renderer extends Component {
|
||||
|
||||
protected _materialInstances: (MaterialInstance | null)[] = [];
|
||||
|
||||
/**
|
||||
* @deprecated Since v3.7.3, please use [[getSharedMaterial]] instead.
|
||||
*/
|
||||
public getMaterial (idx: number): Material | null {
|
||||
return this.getSharedMaterial(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get the shared material asset of the specified sub-model.
|
||||
* @zh 获取指定子模型的共享材质资源。
|
||||
*/
|
||||
public getMaterial (idx: number): Material | null {
|
||||
public getSharedMaterial (idx: number): Material | null {
|
||||
if (idx < 0 || idx >= this._materials.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ export function packGradientRange (tex: Texture2D | null, data: Uint8Array | nul
|
||||
if (data === null || data.length !== len) {
|
||||
data = new Uint8Array(samples * height * 4);
|
||||
}
|
||||
const interval = 1.0 / (samples);
|
||||
const interval = 1.0 / (samples - 1);
|
||||
let offset = 0;
|
||||
|
||||
for (let h = 0; h < height; h++) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { CCClass, Color, lerp, repeat, Enum } from '../../core';
|
||||
import { CCClass, Color, lerp, repeat, Enum, EPSILON, approx } from '../../core';
|
||||
|
||||
const Mode = Enum({
|
||||
Blend: 0,
|
||||
@@ -161,7 +161,7 @@ export default class Gradient {
|
||||
|
||||
private getRGB (time: number) {
|
||||
if (this.colorKeys.length > 1) {
|
||||
time = repeat(time, 1);
|
||||
time = repeat(time, 1.0 + EPSILON);
|
||||
for (let i = 1; i < this.colorKeys.length; ++i) {
|
||||
const preTime = this.colorKeys[i - 1].time;
|
||||
const curTime = this.colorKeys[i].time;
|
||||
@@ -175,7 +175,9 @@ export default class Gradient {
|
||||
}
|
||||
}
|
||||
const lastIndex = this.colorKeys.length - 1;
|
||||
if (time < this.colorKeys[0].time) {
|
||||
if (approx(time, this.colorKeys[lastIndex].time, EPSILON)) {
|
||||
this._color.set(this.colorKeys[lastIndex].color);
|
||||
} else if (time < this.colorKeys[0].time) {
|
||||
Color.lerp(this._color, Color.BLACK, this.colorKeys[0].color, time / this.colorKeys[0].time);
|
||||
} else if (time > this.colorKeys[lastIndex].time) {
|
||||
Color.lerp(this._color, this.colorKeys[lastIndex].color, Color.BLACK, (time - this.colorKeys[lastIndex].time) / (1 - this.colorKeys[lastIndex].time));
|
||||
@@ -194,7 +196,7 @@ export default class Gradient {
|
||||
private getAlpha (time: number) {
|
||||
const basicAlpha = 0; // default alpha is 0
|
||||
if (this.alphaKeys.length > 1) {
|
||||
time = repeat(time, 1);
|
||||
time = repeat(time, 1.0 + EPSILON);
|
||||
for (let i = 1; i < this.alphaKeys.length; ++i) {
|
||||
const preTime = this.alphaKeys[i - 1].time;
|
||||
const curTime = this.alphaKeys[i].time;
|
||||
@@ -207,7 +209,9 @@ export default class Gradient {
|
||||
}
|
||||
}
|
||||
const lastIndex = this.alphaKeys.length - 1;
|
||||
if (time < this.alphaKeys[0].time) {
|
||||
if (approx(time, this.alphaKeys[lastIndex].time, EPSILON)) {
|
||||
return this.alphaKeys[lastIndex].alpha;
|
||||
} else if (time < this.alphaKeys[0].time) {
|
||||
return lerp(basicAlpha, this.alphaKeys[0].alpha, time / this.alphaKeys[0].time);
|
||||
} else if (time > this.alphaKeys[lastIndex].time) {
|
||||
return lerp(this.alphaKeys[lastIndex].alpha, basicAlpha, (time - this.alphaKeys[lastIndex].time) / (1 - this.alphaKeys[lastIndex].time));
|
||||
|
||||
@@ -69,7 +69,7 @@ export class Line extends ModelRenderer {
|
||||
@tooltip('i18n:line.material')
|
||||
@displayName('Material')
|
||||
get lineMaterial () {
|
||||
return this.getMaterial(0);
|
||||
return this.getSharedMaterial(0);
|
||||
}
|
||||
|
||||
set lineMaterial (val) {
|
||||
|
||||
@@ -1041,7 +1041,11 @@ export class ParticleSystem extends ModelRenderer {
|
||||
* @zh 获取当前粒子数量。
|
||||
*/
|
||||
public getParticleCount () {
|
||||
return this.processor.getParticleCount();
|
||||
if (this.processor) {
|
||||
return this.processor.getParticleCount();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,7 +141,7 @@ export default class ParticleSystemRenderer {
|
||||
if (!this._particleSystem) {
|
||||
return null;
|
||||
}
|
||||
return this._particleSystem.getMaterial(0) as Material;
|
||||
return this._particleSystem.getSharedMaterial(0) as Material;
|
||||
}
|
||||
|
||||
public set particleMaterial (val: Material | null) {
|
||||
@@ -221,7 +221,7 @@ export default class ParticleSystemRenderer {
|
||||
if (!this._particleSystem) {
|
||||
return null;
|
||||
}
|
||||
return this._particleSystem.getMaterial(1) as Material;
|
||||
return this._particleSystem.getSharedMaterial(1) as Material;
|
||||
}
|
||||
|
||||
public set trailMaterial (val: Material | null) {
|
||||
|
||||
@@ -94,9 +94,16 @@ export class BuiltinPhysicsWorld implements IPhysicsWorld {
|
||||
}
|
||||
|
||||
js.array.fastRemoveAt(contacts, i);
|
||||
|
||||
const other = contact.shape1 === shape ? contact.shape2 : contact.shape1;
|
||||
const contactIndex = other!._contacts.indexOf(contact);
|
||||
if (contactIndex >= 0) {
|
||||
js.array.fastRemoveAt(other!._contacts, contactIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
shape._contacts.length = 0;
|
||||
}
|
||||
|
||||
updateShapeGroup (shape: BuiltinShape2D) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import { screenAdapter } from 'pal/screen-adapter';
|
||||
import { Orientation } from '../../../pal/screen-adapter/enum-type';
|
||||
import {
|
||||
TextureType, TextureUsageBit, Format, RenderPass, Texture, Framebuffer,
|
||||
RenderPassInfo, Device, TextureInfo, FramebufferInfo, Swapchain, SurfaceTransform,
|
||||
RenderPassInfo, Device, TextureInfo, FramebufferInfo, Swapchain, SurfaceTransform, TextureFlagBit, TextureFlags,
|
||||
} from '../../gfx';
|
||||
import { Root } from '../../root';
|
||||
import { Camera } from '../scene';
|
||||
@@ -36,6 +36,9 @@ export interface IRenderWindowInfo {
|
||||
height: number;
|
||||
renderPassInfo: RenderPassInfo;
|
||||
swapchain?: Swapchain;
|
||||
externalResLow?: number; // for vulkan vkImage/opengl es texture created from external
|
||||
externalResHigh?: number; // for vulkan vkImage created from external
|
||||
externalFlag?: TextureFlags; // external texture type normal or oes
|
||||
}
|
||||
|
||||
const orientationMap: Record<Orientation, SurfaceTransform> = {
|
||||
@@ -130,13 +133,19 @@ export class RenderWindow {
|
||||
this._depthStencilTexture = info.swapchain.depthStencilTexture;
|
||||
} else {
|
||||
for (let i = 0; i < info.renderPassInfo.colorAttachments.length; i++) {
|
||||
this._colorTextures.push(device.createTexture(new TextureInfo(
|
||||
const textureInfo = new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED | TextureUsageBit.TRANSFER_SRC,
|
||||
info.renderPassInfo.colorAttachments[i].format,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
);
|
||||
|
||||
if (info.externalFlag && (info.externalFlag & TextureFlagBit.EXTERNAL_NORMAL || info.externalFlag & TextureFlagBit.EXTERNAL_OES)) {
|
||||
textureInfo.flags |= info.externalFlag;
|
||||
textureInfo.externalRes = info.externalResLow ? info.externalResLow : 0;
|
||||
}
|
||||
this._colorTextures.push(device.createTexture(textureInfo));
|
||||
}
|
||||
if (info.renderPassInfo.depthStencilAttachment.format !== Format.UNKNOWN) {
|
||||
this._depthStencilTexture = device.createTexture(new TextureInfo(
|
||||
|
||||
@@ -996,6 +996,12 @@ export class Camera {
|
||||
if (!this._node) return;
|
||||
|
||||
let viewProjDirty = false;
|
||||
const xr = globalThis.__globalXR;
|
||||
if (xr && xr.isWebXR && xr.webXRWindowMap && xr.webXRMatProjs) {
|
||||
const wndXREye = xr.webXRWindowMap.get(this._window);
|
||||
const x = 1 / xr.webXRMatProjs.length;
|
||||
this.setViewportInOrientedSpace(new Rect(x * wndXREye, 0, x, 1));
|
||||
}
|
||||
// view matrix
|
||||
if (this._node.hasChangedFlags || forceUpdate) {
|
||||
Mat4.invert(this._matView, this._node.worldMatrix);
|
||||
@@ -1016,8 +1022,13 @@ export class Camera {
|
||||
const projectionSignY = this._device.capabilities.clipSpaceSignY;
|
||||
// Only for rendertexture processing
|
||||
if (this._proj === CameraProjection.PERSPECTIVE) {
|
||||
Mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip,
|
||||
this._fovAxis === CameraFOVAxis.VERTICAL, this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation);
|
||||
if (xr && xr.isWebXR && xr.webXRWindowMap && xr.webXRMatProjs && xr.webXRMatProjs.length === 2) {
|
||||
const wndXREye = xr.webXRWindowMap.get(this._window);
|
||||
this._matProj.set(xr.webXRMatProjs[wndXREye]);
|
||||
} else {
|
||||
Mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip,
|
||||
this._fovAxis === CameraFOVAxis.VERTICAL, this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation);
|
||||
}
|
||||
} else {
|
||||
const x = this._orthoHeight * this._aspect;
|
||||
const y = this._orthoHeight;
|
||||
|
||||
@@ -234,16 +234,9 @@ export function buildFxaaPass (camera: Camera,
|
||||
fxaaPass.name = `CameraFxaaPass${cameraID}`;
|
||||
fxaaPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
if (ppl.containsResource(inputRT)) {
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'sceneColorMap';
|
||||
fxaaPass.addComputeView(inputRT, computeView);
|
||||
fxaaPass.addTexture(inputRT, 'sceneColorMap');
|
||||
}
|
||||
const fxaaPassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
clearColor);
|
||||
fxaaPass.addRasterView(fxaaPassRTName, fxaaPassView);
|
||||
fxaaPass.addRenderTarget(fxaaPassRTName, '_', LoadOp.CLEAR, StoreOp.STORE, clearColor);
|
||||
fxaaData.fxaaMaterial.setProperty('texSize', new Vec4(width, height, 1.0 / width, 1.0 / height), fxaaPassIdx);
|
||||
fxaaPass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, fxaaData.fxaaMaterial, fxaaPassIdx,
|
||||
@@ -345,16 +338,9 @@ export function buildBloomPass (camera: Camera,
|
||||
bloomPrefilterPass.name = `CameraBloomPrefilterPass${cameraID}`;
|
||||
bloomPrefilterPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
if (ppl.containsResource(inputRT)) {
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'outputResultMap';
|
||||
bloomPrefilterPass.addComputeView(inputRT, computeView);
|
||||
bloomPrefilterPass.addTexture(inputRT, 'outputResultMap');
|
||||
}
|
||||
const prefilterPassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
bloomClearColor);
|
||||
bloomPrefilterPass.addRasterView(bloomPassPrefilterRTName, prefilterPassView);
|
||||
bloomPrefilterPass.addRenderTarget(bloomPassPrefilterRTName, '_', LoadOp.CLEAR, StoreOp.STORE, bloomClearColor);
|
||||
bloomData.bloomMaterial.setProperty('texSize', new Vec4(0, 0, bloomData.threshold, 0), 0);
|
||||
bloomPrefilterPass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, bloomData.bloomMaterial, 0,
|
||||
@@ -376,19 +362,12 @@ export function buildBloomPass (camera: Camera,
|
||||
const bloomDownSamplePass = ppl.addRasterPass(width, height, `bloom-downsample${i}`);
|
||||
bloomDownSamplePass.name = `CameraBloomDownSamplePass${cameraID}${i}`;
|
||||
bloomDownSamplePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'bloomTexture';
|
||||
if (i === 0) {
|
||||
bloomDownSamplePass.addComputeView(bloomPassPrefilterRTName, computeView);
|
||||
bloomDownSamplePass.addTexture(bloomPassPrefilterRTName, 'bloomTexture');
|
||||
} else {
|
||||
bloomDownSamplePass.addComputeView(`dsBloomPassDownSampleColor${cameraName}${i - 1}`, computeView);
|
||||
bloomDownSamplePass.addTexture(`dsBloomPassDownSampleColor${cameraName}${i - 1}`, 'bloomTexture');
|
||||
}
|
||||
const downSamplePassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
bloomClearColor);
|
||||
bloomDownSamplePass.addRasterView(bloomPassDownSampleRTName, downSamplePassView);
|
||||
bloomDownSamplePass.addRenderTarget(bloomPassDownSampleRTName, '_', LoadOp.CLEAR, StoreOp.STORE, bloomClearColor);
|
||||
bloomData.bloomMaterial.setProperty('texSize', texSize, BLOOM_DOWNSAMPLEPASS_INDEX + i);
|
||||
bloomDownSamplePass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, bloomData.bloomMaterial, BLOOM_DOWNSAMPLEPASS_INDEX + i,
|
||||
@@ -411,19 +390,12 @@ export function buildBloomPass (camera: Camera,
|
||||
const bloomUpSamplePass = ppl.addRasterPass(width, height, `bloom-upsample${i}`);
|
||||
bloomUpSamplePass.name = `CameraBloomUpSamplePass${cameraID}${bloomData.iterations - 1 - i}`;
|
||||
bloomUpSamplePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'bloomTexture';
|
||||
if (i === 0) {
|
||||
bloomUpSamplePass.addComputeView(`dsBloomPassDownSampleColor${cameraName}${bloomData.iterations - 1}`, computeView);
|
||||
bloomUpSamplePass.addTexture(`dsBloomPassDownSampleColor${cameraName}${bloomData.iterations - 1}`, 'bloomTexture');
|
||||
} else {
|
||||
bloomUpSamplePass.addComputeView(`dsBloomPassUpSampleColor${cameraName}${bloomData.iterations - i}`, computeView);
|
||||
bloomUpSamplePass.addTexture(`dsBloomPassUpSampleColor${cameraName}${bloomData.iterations - i}`, 'bloomTexture');
|
||||
}
|
||||
const upSamplePassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
bloomClearColor);
|
||||
bloomUpSamplePass.addRasterView(bloomPassUpSampleRTName, upSamplePassView);
|
||||
bloomUpSamplePass.addRenderTarget(bloomPassUpSampleRTName, '_', LoadOp.CLEAR, StoreOp.STORE, bloomClearColor);
|
||||
bloomData.bloomMaterial.setProperty('texSize', texSize, BLOOM_UPSAMPLEPASS_INDEX + i);
|
||||
bloomUpSamplePass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, bloomData.bloomMaterial, BLOOM_UPSAMPLEPASS_INDEX + i,
|
||||
@@ -445,18 +417,9 @@ export function buildBloomPass (camera: Camera,
|
||||
const bloomCombinePass = ppl.addRasterPass(width, height, 'bloom-combine');
|
||||
bloomCombinePass.name = `CameraBloomCombinePass${cameraID}`;
|
||||
bloomCombinePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeViewOut = new ComputeView();
|
||||
computeViewOut.name = 'outputResultMap';
|
||||
bloomCombinePass.addComputeView(inputRT, computeViewOut);
|
||||
const computeViewBt = new ComputeView();
|
||||
computeViewBt.name = 'bloomTexture';
|
||||
bloomCombinePass.addComputeView(`dsBloomPassUpSampleColor${cameraName}${0}`, computeViewBt);
|
||||
const combinePassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
bloomClearColor);
|
||||
bloomCombinePass.addRasterView(bloomPassCombineRTName, combinePassView);
|
||||
bloomCombinePass.addTexture(inputRT, 'outputResultMap');
|
||||
bloomCombinePass.addTexture(`dsBloomPassUpSampleColor${cameraName}${0}`, 'bloomTexture');
|
||||
bloomCombinePass.addRenderTarget(bloomPassCombineRTName, '_', LoadOp.CLEAR, StoreOp.STORE, bloomClearColor);
|
||||
bloomData.bloomMaterial.setProperty('texSize', new Vec4(0, 0, 0, bloomData.intensity), BLOOM_COMBINEPASS_INDEX);
|
||||
bloomCombinePass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, bloomData.bloomMaterial, BLOOM_COMBINEPASS_INDEX,
|
||||
@@ -507,7 +470,7 @@ export function buildPostprocessPass (camera: Camera,
|
||||
const postprocessPassRTName = `postprocessPassRTName${cameraID}`;
|
||||
const postprocessPassDS = `postprocessPassDS${cameraID}`;
|
||||
if (!ppl.containsResource(postprocessPassRTName)) {
|
||||
ppl.addRenderTexture(postprocessPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addRenderWindow(postprocessPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addDepthStencil(postprocessPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
ppl.updateRenderWindow(postprocessPassRTName, camera.window);
|
||||
@@ -516,9 +479,7 @@ export function buildPostprocessPass (camera: Camera,
|
||||
postprocessPass.name = `CameraPostprocessPass${cameraID}`;
|
||||
postprocessPass.setViewport(new Viewport(area.x, area.y, area.width, area.height));
|
||||
if (ppl.containsResource(inputTex)) {
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'outputResultMap';
|
||||
postprocessPass.addComputeView(inputTex, computeView);
|
||||
postprocessPass.addTexture(inputTex, 'outputResultMap');
|
||||
}
|
||||
const postClearColor = new Color(0, 0, 0, camera.clearColor.w);
|
||||
if (camera.clearFlag & ClearFlagBit.COLOR) {
|
||||
@@ -526,25 +487,14 @@ export function buildPostprocessPass (camera: Camera,
|
||||
postClearColor.y = camera.clearColor.y;
|
||||
postClearColor.z = camera.clearColor.z;
|
||||
}
|
||||
const postprocessPassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
postClearColor);
|
||||
const postprocessPassDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
postprocessPass.addRenderTarget(postprocessPassRTName, '_',
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET), StoreOp.STORE, postClearColor);
|
||||
postprocessPass.addDepthStencil(postprocessPassDS, '_',
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
postprocessPass.addRasterView(postprocessPassRTName, postprocessPassView);
|
||||
postprocessPass.addRasterView(postprocessPassDS, postprocessPassDSView);
|
||||
StoreOp.STORE, camera.clearDepth, camera.clearStencil, camera.clearFlag);
|
||||
postprocessPass.addQueue(QueueHint.NONE).addFullscreenQuad(
|
||||
postInfo.postMaterial, 0, SceneFlags.NONE,
|
||||
);
|
||||
postprocessPass.addQueue(QueueHint.RENDER_TRANSPARENT).addSceneOfCamera(camera, new LightInfo(),
|
||||
SceneFlags.UI);
|
||||
if (getProfilerCamera() === camera) {
|
||||
postprocessPass.showStatistics = true;
|
||||
}
|
||||
@@ -568,7 +518,7 @@ export function buildForwardPass (camera: Camera,
|
||||
const forwardPassDSName = `dsForwardPassDS${cameraName}`;
|
||||
if (!ppl.containsResource(forwardPassRTName)) {
|
||||
if (!isOffScreen) {
|
||||
ppl.addRenderTexture(forwardPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addRenderWindow(forwardPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
} else {
|
||||
ppl.addRenderTarget(forwardPassRTName, Format.RGBA16F, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
@@ -586,30 +536,24 @@ export function buildForwardPass (camera: Camera,
|
||||
forwardPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
for (const dirShadowName of cameraInfo.mainLightShadowNames) {
|
||||
if (ppl.containsResource(dirShadowName)) {
|
||||
const computeView = new ComputeView('cc_shadowMap');
|
||||
forwardPass.addComputeView(dirShadowName, computeView);
|
||||
forwardPass.addTexture(dirShadowName, 'cc_shadowMap');
|
||||
}
|
||||
}
|
||||
for (const spotShadowName of cameraInfo.spotLightShadowNames) {
|
||||
if (ppl.containsResource(spotShadowName)) {
|
||||
const computeView = new ComputeView('cc_spotShadowMap');
|
||||
forwardPass.addComputeView(spotShadowName, computeView);
|
||||
forwardPass.addTexture(spotShadowName, 'cc_spotShadowMap');
|
||||
}
|
||||
}
|
||||
const passView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
forwardPass.addRenderTarget(forwardPassRTName, '_',
|
||||
isOffScreen ? LoadOp.CLEAR : getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
forwardPass.addDepthStencil(forwardPassDSName, '_',
|
||||
isOffScreen ? LoadOp.CLEAR : getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
forwardPass.addRasterView(forwardPassRTName, passView);
|
||||
forwardPass.addRasterView(forwardPassDSName, passDSView);
|
||||
camera.clearDepth,
|
||||
camera.clearStencil,
|
||||
camera.clearFlag);
|
||||
forwardPass
|
||||
.addQueue(QueueHint.RENDER_OPAQUE)
|
||||
.addSceneOfCamera(camera, new LightInfo(),
|
||||
@@ -647,16 +591,9 @@ export function buildShadowPass (passName: Readonly<string>,
|
||||
const pass = ppl.addRasterPass(width, height, 'default');
|
||||
pass.name = passName;
|
||||
pass.setViewport(new Viewport(area.x, area.y, area.width, area.height));
|
||||
pass.addRasterView(shadowMapName, new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
ClearFlagBit.COLOR,
|
||||
new Color(1, 1, 1, camera.clearColor.w)));
|
||||
pass.addRasterView(`${shadowMapName}Depth`, new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
LoadOp.CLEAR, StoreOp.DISCARD,
|
||||
ClearFlagBit.DEPTH_STENCIL,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0)));
|
||||
pass.addRenderTarget(shadowMapName, '_', LoadOp.CLEAR, StoreOp.STORE, new Color(1, 1, 1, camera.clearColor.w));
|
||||
pass.addDepthStencil(`${shadowMapName}Depth`, '_', LoadOp.CLEAR, StoreOp.DISCARD,
|
||||
camera.clearDepth, camera.clearStencil, ClearFlagBit.DEPTH_STENCIL);
|
||||
const queue = pass.addQueue(QueueHint.RENDER_OPAQUE);
|
||||
queue.addSceneOfCamera(camera, new LightInfo(light, level),
|
||||
SceneFlags.SHADOW_CASTER);
|
||||
@@ -694,7 +631,7 @@ export function buildReflectionProbePass (camera: Camera,
|
||||
probe.updateCameraDir(faceIdx);
|
||||
|
||||
if (!ppl.containsResource(probePassRTName)) {
|
||||
ppl.addRenderTexture(probePassRTName, Format.RGBA8, width, height, renderWindow);
|
||||
ppl.addRenderWindow(probePassRTName, Format.RGBA8, width, height, renderWindow);
|
||||
ppl.addDepthStencil(probePassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
ppl.updateRenderWindow(probePassRTName, renderWindow);
|
||||
@@ -703,21 +640,10 @@ export function buildReflectionProbePass (camera: Camera,
|
||||
const probePass = ppl.addRasterPass(width, height, 'default');
|
||||
probePass.name = `ReflectionProbePass${faceIdx}`;
|
||||
probePass.setViewport(new Viewport(0, 0, width, height));
|
||||
|
||||
const passView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
getLoadOpOfClearFlag(probeCamera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
probeCamera.clearFlag,
|
||||
new Color(probeCamera.clearColor.x, probeCamera.clearColor.y, probeCamera.clearColor.z, probeCamera.clearColor.w));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
getLoadOpOfClearFlag(probeCamera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
probeCamera.clearFlag,
|
||||
new Color(probeCamera.clearDepth, probeCamera.clearStencil, 0, 0));
|
||||
probePass.addRasterView(probePassRTName, passView);
|
||||
probePass.addRasterView(probePassDSName, passDSView);
|
||||
probePass.addRenderTarget(probePassRTName, '_', getLoadOpOfClearFlag(probeCamera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE, new Color(probeCamera.clearColor.x, probeCamera.clearColor.y, probeCamera.clearColor.z, probeCamera.clearColor.w));
|
||||
probePass.addDepthStencil(probePassDSName, '_', getLoadOpOfClearFlag(probeCamera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE, probeCamera.clearDepth, probeCamera.clearStencil, probeCamera.clearFlag);
|
||||
const passBuilder = probePass.addQueue(QueueHint.RENDER_OPAQUE);
|
||||
passBuilder.addSceneOfCamera(camera, new LightInfo(), SceneFlags.REFLECTION_PROBE);
|
||||
updateCameraUBO(passBuilder as unknown as any, probeCamera, ppl);
|
||||
@@ -824,30 +750,10 @@ export function buildGBufferPass (camera: Camera,
|
||||
rtColor.z = camera.clearColor.z;
|
||||
}
|
||||
}
|
||||
const passColorView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
rtColor);
|
||||
const passNormalView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(0, 0, 0, 0));
|
||||
const passEmissiveView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(0, 0, 0, 0));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
gBufferPass.addRasterView(gBufferPassRTName, passColorView);
|
||||
gBufferPass.addRasterView(gBufferPassNormal, passNormalView);
|
||||
gBufferPass.addRasterView(gBufferPassEmissive, passEmissiveView);
|
||||
gBufferPass.addRasterView(gBufferPassDSName, passDSView);
|
||||
gBufferPass.addRenderTarget(gBufferPassRTName, '_', LoadOp.CLEAR, StoreOp.STORE, rtColor);
|
||||
gBufferPass.addRenderTarget(gBufferPassNormal, '_', LoadOp.CLEAR, StoreOp.STORE, new Color(0, 0, 0, 0));
|
||||
gBufferPass.addRenderTarget(gBufferPassEmissive, '_', LoadOp.CLEAR, StoreOp.STORE, new Color(0, 0, 0, 0));
|
||||
gBufferPass.addDepthStencil(gBufferPassDSName, '_', LoadOp.CLEAR, StoreOp.STORE, camera.clearDepth, camera.clearStencil, camera.clearFlag);
|
||||
gBufferPass
|
||||
.addQueue(QueueHint.RENDER_OPAQUE)
|
||||
.addSceneOfCamera(camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT);
|
||||
@@ -905,32 +811,19 @@ export function buildLightingPass (camera: Camera, ppl: Pipeline, gBuffer: GBuff
|
||||
lightingPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
for (const dirShadowName of cameraInfo.mainLightShadowNames) {
|
||||
if (ppl.containsResource(dirShadowName)) {
|
||||
const computeView = new ComputeView('cc_shadowMap');
|
||||
lightingPass.addComputeView(dirShadowName, computeView);
|
||||
lightingPass.addTexture(dirShadowName, 'cc_shadowMap');
|
||||
}
|
||||
}
|
||||
for (const spotShadowName of cameraInfo.spotLightShadowNames) {
|
||||
if (ppl.containsResource(spotShadowName)) {
|
||||
const computeView = new ComputeView('cc_spotShadowMap');
|
||||
lightingPass.addComputeView(spotShadowName, computeView);
|
||||
lightingPass.addTexture(spotShadowName, 'cc_spotShadowMap');
|
||||
}
|
||||
}
|
||||
if (ppl.containsResource(gBuffer.color)) {
|
||||
const computeView = new ComputeView();
|
||||
computeView.name = 'gbuffer_albedoMap';
|
||||
lightingPass.addComputeView(gBuffer.color, computeView);
|
||||
|
||||
const computeNormalView = new ComputeView();
|
||||
computeNormalView.name = 'gbuffer_normalMap';
|
||||
lightingPass.addComputeView(gBuffer.normal, computeNormalView);
|
||||
|
||||
const computeEmissiveView = new ComputeView();
|
||||
computeEmissiveView.name = 'gbuffer_emissiveMap';
|
||||
lightingPass.addComputeView(gBuffer.emissive, computeEmissiveView);
|
||||
|
||||
const computeDepthView = new ComputeView();
|
||||
computeDepthView.name = 'depth_stencil';
|
||||
lightingPass.addComputeView(gBuffer.ds, computeDepthView);
|
||||
lightingPass.addTexture(gBuffer.color, 'gbuffer_albedoMap');
|
||||
lightingPass.addTexture(gBuffer.normal, 'gbuffer_normalMap');
|
||||
lightingPass.addTexture(gBuffer.emissive, 'gbuffer_emissiveMap');
|
||||
lightingPass.addTexture(gBuffer.ds, 'depth_stencil');
|
||||
}
|
||||
const lightingClearColor = new Color(0, 0, 0, 0);
|
||||
if (camera.clearFlag & ClearFlagBit.COLOR) {
|
||||
@@ -939,12 +832,7 @@ export function buildLightingPass (camera: Camera, ppl: Pipeline, gBuffer: GBuff
|
||||
lightingClearColor.z = camera.clearColor.z;
|
||||
}
|
||||
lightingClearColor.w = 0;
|
||||
const lightingPassView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
LoadOp.CLEAR, StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
lightingClearColor);
|
||||
lightingPass.addRasterView(deferredLightingPassRTName, lightingPassView);
|
||||
lightingPass.addRenderTarget(deferredLightingPassRTName, '_', LoadOp.CLEAR, StoreOp.STORE, lightingClearColor);
|
||||
lightingPass.addQueue(QueueHint.RENDER_TRANSPARENT).addCameraQuad(
|
||||
camera, lightingInfo.deferredLightingMaterial, 0,
|
||||
SceneFlags.VOLUMETRIC_LIGHTING,
|
||||
@@ -987,34 +875,28 @@ export function buildUIPass (camera: Camera,
|
||||
const dsUIAndProfilerPassRTName = `dsUIAndProfilerPassColor${cameraName}`;
|
||||
const dsUIAndProfilerPassDSName = `dsUIAndProfilerPassDS${cameraName}`;
|
||||
if (!ppl.containsResource(dsUIAndProfilerPassRTName)) {
|
||||
ppl.addRenderTexture(dsUIAndProfilerPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addRenderWindow(dsUIAndProfilerPassRTName, Format.BGRA8, width, height, camera.window);
|
||||
ppl.addDepthStencil(dsUIAndProfilerPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
|
||||
}
|
||||
ppl.updateRenderWindow(dsUIAndProfilerPassRTName, camera.window);
|
||||
ppl.updateDepthStencil(dsUIAndProfilerPassDSName, width, height);
|
||||
const uIAndProfilerPass = ppl.addRasterPass(width, height, 'default');
|
||||
uIAndProfilerPass.name = `CameraUIAndProfilerPass${cameraID}`;
|
||||
uIAndProfilerPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const passView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.RENDER_TARGET,
|
||||
const uiAndProfilerPass = ppl.addRasterPass(width, height, 'default');
|
||||
uiAndProfilerPass.name = `CameraUIAndProfilerPass${cameraID}`;
|
||||
uiAndProfilerPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
uiAndProfilerPass.addRenderTarget(dsUIAndProfilerPassRTName, '_',
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.RENDER_TARGET),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearColor.x, camera.clearColor.y, camera.clearColor.z, camera.clearColor.w));
|
||||
const passDSView = new RasterView('_',
|
||||
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
|
||||
uiAndProfilerPass.addDepthStencil(dsUIAndProfilerPassDSName, '_',
|
||||
getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL),
|
||||
StoreOp.STORE,
|
||||
camera.clearFlag,
|
||||
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
|
||||
uIAndProfilerPass.addRasterView(dsUIAndProfilerPassRTName, passView);
|
||||
uIAndProfilerPass.addRasterView(dsUIAndProfilerPassDSName, passDSView);
|
||||
camera.clearDepth, camera.clearStencil, camera.clearFlag);
|
||||
const sceneFlags = SceneFlags.UI;
|
||||
uIAndProfilerPass
|
||||
uiAndProfilerPass
|
||||
.addQueue(QueueHint.RENDER_TRANSPARENT)
|
||||
.addSceneOfCamera(camera, new LightInfo(), sceneFlags);
|
||||
if (getProfilerCamera() === camera) {
|
||||
uIAndProfilerPass.showStatistics = true;
|
||||
uiAndProfilerPass.showStatistics = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,11 +93,26 @@ class DeviceTexture extends DeviceResource {
|
||||
get description () { return this._desc; }
|
||||
get trait () { return this._trait; }
|
||||
get swapchain () { return this._swapchain; }
|
||||
private _setDesc (desc: ResourceDesc) {
|
||||
if (!this._desc) {
|
||||
this._desc = new ResourceDesc();
|
||||
}
|
||||
this._desc.alignment = desc.alignment;
|
||||
this._desc.depthOrArraySize = desc.depthOrArraySize;
|
||||
this._desc.dimension = desc.dimension;
|
||||
this._desc.flags = desc.flags;
|
||||
this._desc.format = desc.format;
|
||||
this._desc.height = desc.height;
|
||||
this._desc.mipLevels = desc.mipLevels;
|
||||
this._desc.sampleCount = desc.sampleCount;
|
||||
this._desc.textureFlags = desc.textureFlags;
|
||||
this._desc.width = desc.width;
|
||||
}
|
||||
constructor (name: string, tex: Texture | Framebuffer | RenderSwapchain | ManagedResource) {
|
||||
super(name);
|
||||
const resGraph = context.resourceGraph;
|
||||
const verID = resGraph.vertex(name);
|
||||
this._desc = resGraph.getDesc(verID);
|
||||
this._setDesc(resGraph.getDesc(verID));
|
||||
this._trait = resGraph.getTraits(verID);
|
||||
if (tex instanceof Texture) {
|
||||
this._texture = tex;
|
||||
@@ -112,7 +127,7 @@ class DeviceTexture extends DeviceResource {
|
||||
return;
|
||||
}
|
||||
|
||||
const info = this._desc;
|
||||
const info = this._desc!;
|
||||
let type = TextureType.TEX2D;
|
||||
|
||||
switch (info.dimension) {
|
||||
@@ -441,7 +456,7 @@ class DeviceRenderQueue {
|
||||
this.queueHint = queueHint;
|
||||
this.queueId = id;
|
||||
this._devicePass = devicePass;
|
||||
if (isEnableEffect()) this._phaseID = cclegacy.rendering.getPhaseID(devicePass.passID, 'default');
|
||||
if (isEnableEffect()) this._phaseID = cclegacy.rendering.getPhaseID(devicePass.passID, context.renderGraph.getLayout(id) || 'default');
|
||||
if (!this._sceneVisitor) {
|
||||
this._sceneVisitor = new WebSceneVisitor(context.commandBuffer,
|
||||
context.pipeline.pipelineSceneData);
|
||||
@@ -514,11 +529,7 @@ class SubmitInfo {
|
||||
public shadowMap: RenderShadowMapBatchedQueue | null = null;
|
||||
public additiveLight: RenderAdditiveLightQueue | null = null;
|
||||
public reflectionProbe: RenderReflectionProbeQueue | null = null;
|
||||
private _isInit = false;
|
||||
get isInit () { return this._isInit; }
|
||||
set isInit (val: boolean) { this._isInit = val; }
|
||||
reset () {
|
||||
this._isInit = false;
|
||||
this.instances.clear();
|
||||
this.renderInstanceQueue.length = 0;
|
||||
this.batches.clear();
|
||||
@@ -649,13 +660,15 @@ class DeviceRenderPass {
|
||||
protected _clearDepth = 1;
|
||||
protected _clearStencil = 0;
|
||||
protected _passID: number;
|
||||
protected _layoutName: string;
|
||||
protected _viewport: Viewport | null = null;
|
||||
private _rasterInfo: RasterPassInfo;
|
||||
private _layout: RenderPassLayoutInfo | null = null;
|
||||
constructor (passInfo: RasterPassInfo) {
|
||||
this._rasterInfo = passInfo;
|
||||
const device = context.device;
|
||||
this._passID = cclegacy.rendering.getPassID(context.renderGraph.getLayout(passInfo.id));
|
||||
this._layoutName = context.renderGraph.getLayout(passInfo.id);
|
||||
this._passID = cclegacy.rendering.getPassID(this._layoutName);
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
depthStencilAttachment.format = Format.DEPTH_STENCIL;
|
||||
depthStencilAttachment.depthLoadOp = LoadOp.DISCARD;
|
||||
@@ -752,6 +765,7 @@ class DeviceRenderPass {
|
||||
swapchain ? [swapchain.colorTexture] : colorTexs,
|
||||
swapchain ? swapchain.depthStencilTexture : depthTex));
|
||||
}
|
||||
get layoutName (): string { return this._layoutName; }
|
||||
get passID (): number { return this._passID; }
|
||||
get renderLayout () { return this._layout; }
|
||||
get renderPass () { return this._renderPass; }
|
||||
@@ -852,15 +866,17 @@ class DeviceRenderPass {
|
||||
}
|
||||
|
||||
private _clear () {
|
||||
for (const [cam, info] of context.submitMap) {
|
||||
info.additiveLight?.clear();
|
||||
const it = info.instances.values(); let res = it.next();
|
||||
while (!res.done) {
|
||||
res.value.clear();
|
||||
res = it.next();
|
||||
for (const [cam, infoMap] of context.submitMap) {
|
||||
for (const [id, info] of infoMap) {
|
||||
info.additiveLight?.clear();
|
||||
const it = info.instances.values(); let res = it.next();
|
||||
while (!res.done) {
|
||||
res.value.clear();
|
||||
res = it.next();
|
||||
}
|
||||
info.renderInstanceQueue = [];
|
||||
info.instances.clear();
|
||||
}
|
||||
info.renderInstanceQueue = [];
|
||||
info.instances.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1038,15 +1054,23 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
}
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = context.submitMap;
|
||||
if (submitMap.has(this.camera)) {
|
||||
this._submitInfo = submitMap.get(this.camera)!;
|
||||
let submitInfoMap = submitMap.get(this.camera);
|
||||
if (submitInfoMap && submitInfoMap.has(this._currentQueue.phaseID)) {
|
||||
this._submitInfo = submitInfoMap.get(this._currentQueue.phaseID)!;
|
||||
} else {
|
||||
if (!submitInfoMap) {
|
||||
submitInfoMap = new Map();
|
||||
submitMap.set(this.camera, submitInfoMap);
|
||||
}
|
||||
this._submitInfo = new SubmitInfo();
|
||||
submitMap.set(this.camera, this._submitInfo);
|
||||
submitInfoMap.set(this._currentQueue.phaseID, this._submitInfo);
|
||||
}
|
||||
// culling
|
||||
if ((!this._isShadowMap() || (this._isShadowMap() && this.graphScene.scene!.light.level === 0))
|
||||
&& !this._submitInfo.isInit) { super.start(); this._submitInfo.isInit = true; }
|
||||
&& this.camera !== context.cullCamera) {
|
||||
super.start();
|
||||
context.cullCamera = this.camera;
|
||||
}
|
||||
|
||||
// shadowmap
|
||||
if (this._isShadowMap()) {
|
||||
@@ -1078,7 +1102,6 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
&& !this._submitInfo.instances.size
|
||||
&& !this._submitInfo.batches.size;
|
||||
if (isEmpty) {
|
||||
context.pools.resetPassInfo();
|
||||
for (const ro of this.sceneData.renderObjects) {
|
||||
const subModels = ro.model.subModels;
|
||||
for (const subModel of subModels) {
|
||||
@@ -1105,7 +1128,7 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
}
|
||||
if (sceneFlag & SceneFlags.DEFAULT_LIGHTING) {
|
||||
this._submitInfo.additiveLight = context.additiveLight;
|
||||
this._submitInfo.additiveLight.gatherLightPasses(this.camera, this._cmdBuff);
|
||||
this._submitInfo.additiveLight.gatherLightPasses(this.camera, this._cmdBuff, this._currentQueue.devicePass.layoutName);
|
||||
}
|
||||
if (sceneFlag & SceneFlags.PLANAR_SHADOW) {
|
||||
this._submitInfo.planarQueue = context.planarShadow;
|
||||
@@ -1141,7 +1164,7 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
const currTransparent = pass.blendState.targets[0].blend;
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const passId = devicePass.passID;
|
||||
const phase = isEnableEffect() ? cclegacy.rendering.getPhaseID(passId, 'default') | cclegacy.rendering.getPhaseID(passId, 'planarShadow')
|
||||
const phase = isEnableEffect() ? this._currentQueue.phaseID // | cclegacy.rendering.getPhaseID(passId, 'planarShadow')
|
||||
: getPhaseID('default') | getPhaseID('planarShadow');
|
||||
if (currTransparent !== isTransparent || !(pass.phaseID & (isTransparent ? phase : this._currentQueue.phaseID))) {
|
||||
return;
|
||||
@@ -1294,7 +1317,9 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
public start () {}
|
||||
protected _recordRenderList (isTransparent: boolean) {
|
||||
const submitMap = context.submitMap;
|
||||
const renderList = isTransparent ? submitMap.get(this.camera!)!.transparentList : submitMap.get(this.camera!)!.opaqueList;
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
const renderList = isTransparent ? currSubmitInfo.transparentList
|
||||
: currSubmitInfo.opaqueList;
|
||||
for (let i = 0; i < renderList.length; ++i) {
|
||||
const { subModel, passIdx } = renderList[i];
|
||||
const { inputAssembler } = subModel;
|
||||
@@ -1314,9 +1339,10 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
}
|
||||
protected _recordInstences () {
|
||||
const submitMap = context.submitMap;
|
||||
const it = submitMap.get(this.camera!)!.renderInstanceQueue.length === 0
|
||||
? submitMap.get(this.camera!)!.instances.values()
|
||||
: submitMap.get(this.camera!)!.renderInstanceQueue.values();
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
const it = currSubmitInfo.renderInstanceQueue.length === 0
|
||||
? currSubmitInfo.instances.values()
|
||||
: currSubmitInfo.renderInstanceQueue.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
const { instances, pass, hasPendingModels } = res.value;
|
||||
@@ -1344,7 +1370,8 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
}
|
||||
protected _recordBatches () {
|
||||
const submitMap = context.submitMap;
|
||||
const it = submitMap.get(this.camera!)!.batches.values(); let res = it.next();
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
const it = currSubmitInfo.batches.values(); let res = it.next();
|
||||
while (!res.done) {
|
||||
let boundPSO = false;
|
||||
for (let b = 0; b < res.value.batches.length; ++b) {
|
||||
@@ -1398,12 +1425,14 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
}
|
||||
protected _recordShadowMap () {
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.shadowMap?.recordCommandBuffer(context.device,
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
currSubmitInfo.shadowMap?.recordCommandBuffer(context.device,
|
||||
this._renderPass, context.commandBuffer);
|
||||
}
|
||||
protected _recordReflectionProbe () {
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.reflectionProbe?.recordCommandBuffer(context.device,
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
currSubmitInfo.reflectionProbe?.recordCommandBuffer(context.device,
|
||||
this._renderPass, context.commandBuffer);
|
||||
}
|
||||
private _isShadowMap () {
|
||||
@@ -1462,7 +1491,8 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
private _recordAdditiveLights () {
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.additiveLight?.recordCommandBuffer(context.device,
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
currSubmitInfo.additiveLight?.recordCommandBuffer(context.device,
|
||||
this._renderPass,
|
||||
context.commandBuffer);
|
||||
}
|
||||
@@ -1470,7 +1500,8 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
private _recordPlanarShadows () {
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.planarQueue?.recordCommandBuffer(context.device,
|
||||
const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!;
|
||||
currSubmitInfo.planarQueue?.recordCommandBuffer(context.device,
|
||||
this._renderPass,
|
||||
context.commandBuffer);
|
||||
}
|
||||
@@ -1572,6 +1603,7 @@ class ExecutorPools {
|
||||
this.deviceQueuePool.reset();
|
||||
this.graphScenePool.reset();
|
||||
this.reflectionProbe.reset();
|
||||
this.resetPassInfo();
|
||||
}
|
||||
readonly deviceQueuePool: RecyclePool<DeviceRenderQueue>;
|
||||
readonly graphScenePool: RecyclePool<GraphScene>;
|
||||
@@ -1784,8 +1816,9 @@ class ExecutorContext {
|
||||
}
|
||||
reset () {
|
||||
this.pools.reset();
|
||||
for (const info of this.submitMap) {
|
||||
info[1].reset();
|
||||
this.cullCamera = null;
|
||||
for (const infoMap of this.submitMap) {
|
||||
for (const info of infoMap[1]) info[1].reset();
|
||||
}
|
||||
}
|
||||
resize (width: number, height: number) {
|
||||
@@ -1806,12 +1839,13 @@ class ExecutorContext {
|
||||
readonly additiveLight: RenderAdditiveLightQueue;
|
||||
readonly shadowMapBatched: RenderShadowMapBatchedQueue;
|
||||
readonly planarShadow: PlanarShadowQueue;
|
||||
readonly submitMap: Map<Camera, SubmitInfo> = new Map<Camera, SubmitInfo>();
|
||||
readonly submitMap: Map<Camera, Map<number, SubmitInfo>> = new Map<Camera, Map<number, SubmitInfo>>();
|
||||
readonly pools: ExecutorPools;
|
||||
readonly blit: BlitInfo;
|
||||
renderGraph: RenderGraph;
|
||||
width: number;
|
||||
height: number;
|
||||
cullCamera;
|
||||
}
|
||||
class ResourceVisitor implements ResourceGraphVisitor {
|
||||
name: string;
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
import { Material } from '../../asset/assets';
|
||||
import { Camera } from '../../render-scene/scene/camera';
|
||||
import { GeometryRenderer } from '../geometry-renderer';
|
||||
import { Buffer, Color, CommandBuffer, DescriptorSet, DescriptorSetLayout, Device, DrawInfo, Format, InputAssembler, PipelineState, Rect, Sampler, Swapchain, Texture, Viewport } from '../../gfx';
|
||||
import { Buffer, ClearFlagBit, Color, CommandBuffer, DescriptorSet, DescriptorSetLayout, Device, DrawInfo, Format, InputAssembler, LoadOp, PipelineState, Rect, Sampler, StoreOp, Swapchain, Texture, Viewport } from '../../gfx';
|
||||
import { GlobalDSManager } from '../global-descriptor-set-manager';
|
||||
import { Mat4, Quat, Vec2, Vec4 } from '../../core/math';
|
||||
import { MacroRecord } from '../../render-scene/core/pass-utils';
|
||||
import { PipelineSceneData } from '../pipeline-scene-data';
|
||||
import { ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResourceResidency, SceneFlags, TaskType, UpdateFrequency } from './types';
|
||||
import { AccessType, ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResourceResidency, SceneFlags, TaskType, UpdateFrequency } from './types';
|
||||
import { RenderScene } from '../../render-scene/core/render-scene';
|
||||
import { RenderWindow } from '../../render-scene/core/render-window';
|
||||
import { Model } from '../../render-scene/scene';
|
||||
@@ -67,6 +67,10 @@ export interface PipelineRuntime {
|
||||
|
||||
export interface RenderNode {
|
||||
name: string;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
setCustomBehavior (name: string): void;
|
||||
}
|
||||
|
||||
export interface Setter extends RenderNode {
|
||||
@@ -76,6 +80,7 @@ export interface Setter extends RenderNode {
|
||||
setVec4 (name: string, vec: Vec4): void;
|
||||
setVec2 (name: string, vec: Vec2): void;
|
||||
setFloat (name: string, v: number): void;
|
||||
setArrayBuffer (name: string, arrayBuffer: ArrayBuffer): void;
|
||||
setBuffer (name: string, buffer: Buffer): void;
|
||||
setTexture (name: string, texture: Texture): void;
|
||||
setReadWriteBuffer (name: string, buffer: Buffer): void;
|
||||
@@ -95,10 +100,68 @@ export interface RasterQueueBuilder extends Setter {
|
||||
clearRenderTarget (name: string, color: Color): void;
|
||||
clearRenderTarget (name: string/*, new Color()*/): void;
|
||||
setViewport (viewport: Viewport): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addCustomCommand (customBehavior: string): void;
|
||||
}
|
||||
|
||||
export interface RasterSubpassBuilder extends Setter {
|
||||
addRasterView (name: string, view: RasterView): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp, color: Color): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp/*, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp/*, StoreOp.STORE, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, accessType: AccessType, slotName: string/*, LoadOp.CLEAR, StoreOp.STORE, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number, stencil: number, clearFlags: ClearFlagBit): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number, stencil: number/*, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number/*, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp, storeOp: StoreOp/*, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string, loadOp: LoadOp/*, StoreOp.STORE, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, accessType: AccessType, slotName: string/*, LoadOp.CLEAR, StoreOp.STORE, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addTexture (name: string, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageBuffer (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageImage (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addComputeView (name: string, view: ComputeView): void;
|
||||
setViewport (viewport: Viewport): void;
|
||||
addQueue (hint: QueueHint, layoutName: string): RasterQueueBuilder;
|
||||
@@ -114,14 +177,90 @@ export interface ComputeQueueBuilder extends Setter {
|
||||
}
|
||||
|
||||
export interface ComputeSubpassBuilder extends Setter {
|
||||
addRasterView (name: string, view: RasterView): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addTexture (name: string, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageBuffer (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageImage (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addComputeView (name: string, view: ComputeView): void;
|
||||
addQueue (layoutName: string): ComputeQueueBuilder;
|
||||
addQueue (/*''*/): ComputeQueueBuilder;
|
||||
}
|
||||
|
||||
export interface RasterPassBuilder extends Setter {
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp, color: Color): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp/*, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, slotName: string, loadOp: LoadOp/*, StoreOp.STORE, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addRenderTarget (name: string, slotName: string/*, LoadOp.CLEAR, StoreOp.STORE, new Color()*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number, stencil: number, clearFlags: ClearFlagBit): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number, stencil: number/*, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp, depth: number/*, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string, loadOp: LoadOp, storeOp: StoreOp/*, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string, loadOp: LoadOp/*, StoreOp.STORE, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addDepthStencil (name: string, slotName: string/*, LoadOp.CLEAR, StoreOp.STORE, 1, 0, ClearFlagBit.DEPTH_STENCIL*/): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addTexture (name: string, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageBuffer (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageImage (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addRasterView (name: string, view: RasterView): void;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addComputeView (name: string, view: ComputeView): void;
|
||||
addQueue (hint: QueueHint, layoutName: string): RasterQueueBuilder;
|
||||
addQueue (hint: QueueHint/*, ''*/): RasterQueueBuilder;
|
||||
@@ -136,6 +275,21 @@ export interface RasterPassBuilder extends Setter {
|
||||
}
|
||||
|
||||
export interface ComputePassBuilder extends Setter {
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addTexture (name: string, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageBuffer (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @beta method's name might change
|
||||
*/
|
||||
addStorageImage (name: string, accessType: AccessType, slotName: string): void;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addComputeView (name: string, view: ComputeView): void;
|
||||
addQueue (layoutName: string): ComputeQueueBuilder;
|
||||
addQueue (/*''*/): ComputeQueueBuilder;
|
||||
@@ -176,7 +330,11 @@ export interface Pipeline extends PipelineRuntime {
|
||||
beginSetup (): void;
|
||||
endSetup (): void;
|
||||
containsResource (name: string): boolean;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
addRenderTexture (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number;
|
||||
addRenderWindow (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number;
|
||||
updateRenderWindow (name: string, renderWindow: RenderWindow): void;
|
||||
addStorageBuffer (name: string, format: Format, size: number, residency: ResourceResidency): number;
|
||||
addStorageBuffer (name: string, format: Format, size: number/*, ResourceResidency.MANAGED*/): number;
|
||||
@@ -189,13 +347,13 @@ export interface Pipeline extends PipelineRuntime {
|
||||
addShadingRateTexture (name: string, width: number, height: number, residency: ResourceResidency): number;
|
||||
addShadingRateTexture (name: string, width: number, height: number/*, ResourceResidency.MANAGED*/): number;
|
||||
updateStorageBuffer (name: string, size: number, format: Format): void;
|
||||
updateStorageBuffer (name: string, size: number/*, gfx.Format.UNKNOWN*/): void;
|
||||
updateStorageBuffer (name: string, size: number/*, Format.UNKNOWN*/): void;
|
||||
updateRenderTarget (name: string, width: number, height: number, format: Format): void;
|
||||
updateRenderTarget (name: string, width: number, height: number/*, gfx.Format.UNKNOWN*/): void;
|
||||
updateRenderTarget (name: string, width: number, height: number/*, Format.UNKNOWN*/): void;
|
||||
updateDepthStencil (name: string, width: number, height: number, format: Format): void;
|
||||
updateDepthStencil (name: string, width: number, height: number/*, gfx.Format.UNKNOWN*/): void;
|
||||
updateDepthStencil (name: string, width: number, height: number/*, Format.UNKNOWN*/): void;
|
||||
updateStorageTexture (name: string, width: number, height: number, format: Format): void;
|
||||
updateStorageTexture (name: string, width: number, height: number/*, gfx.Format.UNKNOWN*/): void;
|
||||
updateStorageTexture (name: string, width: number, height: number/*, Format.UNKNOWN*/): void;
|
||||
updateShadingRateTexture (name: string, width: number, height: number): void;
|
||||
beginFrame (): void;
|
||||
endFrame (): void;
|
||||
@@ -204,6 +362,9 @@ export interface Pipeline extends PipelineRuntime {
|
||||
addComputePass (layoutName: string): ComputePassBuilder;
|
||||
addMovePass (): MovePassBuilder;
|
||||
addCopyPass (): CopyPassBuilder;
|
||||
/**
|
||||
* @deprecated method will be removed in 3.8.0
|
||||
*/
|
||||
createSceneTransversal (camera: Camera, scene: RenderScene): SceneTransversal;
|
||||
getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | null;
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ export class RaytracePass {
|
||||
}
|
||||
|
||||
export class ClearView {
|
||||
constructor (slotName = '', clearFlags: ClearFlagBit = gfx.ClearFlagBit.ALL, clearColor: Color = new Color()) {
|
||||
constructor (slotName = '', clearFlags: ClearFlagBit = ClearFlagBit.ALL, clearColor: Color = new Color()) {
|
||||
this.slotName = slotName;
|
||||
this.clearFlags = clearFlags;
|
||||
this.clearColor = clearColor;
|
||||
@@ -1152,6 +1152,7 @@ export class RenderData {
|
||||
readonly buffers: Map<number, Buffer> = new Map<number, Buffer>();
|
||||
readonly textures: Map<number, Texture> = new Map<number, Texture>();
|
||||
readonly samplers: Map<number, Sampler> = new Map<number, Sampler>();
|
||||
custom = '';
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,10 +86,10 @@ function cullRangedDirLight (light: RangedDirectionalLight, model: Model) {
|
||||
const phaseName = 'forward-add';
|
||||
let _phaseID = getPhaseID(phaseName);
|
||||
const _lightPassIndices: number[] = [];
|
||||
function getLightPassIndices (subModels: SubModel[], lightPassIndices: number[]) {
|
||||
function getLightPassIndices (subModels: SubModel[], lightPassIndices: number[], passLayout = 'default') {
|
||||
const r = cclegacy.rendering;
|
||||
if (isEnableEffect()) {
|
||||
_phaseID = r.getPhaseID(r.getPassID('default'), phaseName);
|
||||
_phaseID = r.getPhaseID(r.getPassID(passLayout), phaseName);
|
||||
}
|
||||
lightPassIndices.length = 0;
|
||||
let hasValidLightPass = false;
|
||||
@@ -191,26 +191,19 @@ export class RenderAdditiveLightQueue {
|
||||
}
|
||||
}
|
||||
|
||||
public gatherLightPasses (camera: Camera, cmdBuff: CommandBuffer) {
|
||||
this.clear();
|
||||
|
||||
const validPunctualLights = this._pipeline.pipelineSceneData.validPunctualLights;
|
||||
if (!validPunctualLights.length) { return; }
|
||||
|
||||
this._updateUBOs(camera, cmdBuff);
|
||||
this._updateLightDescriptorSet(camera, cmdBuff);
|
||||
private _bindForwardAddLight (validPunctualLights, passLayout = 'default') {
|
||||
const renderObjects = this._pipeline.pipelineSceneData.renderObjects;
|
||||
for (let i = 0; i < renderObjects.length; i++) {
|
||||
const ro = renderObjects[i];
|
||||
const { model } = ro;
|
||||
const { subModels } = model;
|
||||
if (!getLightPassIndices(subModels, _lightPassIndices)) { continue; }
|
||||
if (!getLightPassIndices(subModels, _lightPassIndices, passLayout)) { continue; }
|
||||
|
||||
_lightIndices.length = 0;
|
||||
|
||||
this._lightCulling(model, validPunctualLights);
|
||||
|
||||
if (!_lightIndices.length) { continue; }
|
||||
if (!_lightIndices.length && validPunctualLights.length > 0) { continue; }
|
||||
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const lightPassIdx = _lightPassIndices[j];
|
||||
@@ -229,7 +222,20 @@ export class RenderAdditiveLightQueue {
|
||||
this._addRenderQueue(pass, subModel, model, lightPassIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public gatherLightPasses (camera: Camera, cmdBuff: CommandBuffer, passLayout = 'default') {
|
||||
this.clear();
|
||||
|
||||
const validPunctualLights = this._pipeline.pipelineSceneData.validPunctualLights;
|
||||
if (!validPunctualLights.length) {
|
||||
this._bindForwardAddLight(validPunctualLights, passLayout);
|
||||
return;
|
||||
}
|
||||
|
||||
this._updateUBOs(camera, cmdBuff);
|
||||
this._updateLightDescriptorSet(camera, cmdBuff);
|
||||
this._bindForwardAddLight(validPunctualLights, passLayout);
|
||||
// only for instanced and batched, no light culling applied
|
||||
for (let l = 0; l < validPunctualLights.length; l++) {
|
||||
const light = validPunctualLights[l];
|
||||
|
||||
+124
-41
@@ -25,7 +25,7 @@
|
||||
import { Pool, cclegacy, warnID, settings, Settings, macro } from './core';
|
||||
import { RenderPipeline, createDefaultPipeline, DeferredPipeline } from './rendering';
|
||||
import { DebugView } from './rendering/debug-view';
|
||||
import { Camera, Light, Model } from './render-scene/scene';
|
||||
import { Camera, CameraType, Light, Model, TrackingType } from './render-scene/scene';
|
||||
import type { DataPoolManager } from './3d/skeletal-animation/data-pool-manager';
|
||||
import { LightType } from './render-scene/scene/light';
|
||||
import { IRenderSceneInfo, RenderScene } from './render-scene/core/render-scene';
|
||||
@@ -40,6 +40,7 @@ import { Pipeline, PipelineRuntime } from './rendering/custom/pipeline';
|
||||
import { Batcher2D } from './2d/renderer/batcher-2d';
|
||||
import { IPipelineEvent } from './rendering/pipeline-event';
|
||||
import { localDescriptorSetLayout_ResizeMaxJoints, UBOCamera, UBOGlobal, UBOLocal, UBOShadow, UBOWorldBound } from './rendering/define';
|
||||
import { XREye, XRPoseType } from './xr/xr-enums';
|
||||
|
||||
/**
|
||||
* @en Initialization information for the Root
|
||||
@@ -469,7 +470,6 @@ export class Root {
|
||||
* @param deltaTime @en The delta time since last update. @zh 距离上一帧间隔时间
|
||||
*/
|
||||
public frameMove (deltaTime: number) {
|
||||
const { director, Director } = cclegacy;
|
||||
this._frameTime = deltaTime;
|
||||
|
||||
/*
|
||||
@@ -491,46 +491,14 @@ export class Root {
|
||||
this._frameCount = 0;
|
||||
this._fpsTime = 0.0;
|
||||
}
|
||||
for (let i = 0; i < this._scenes.length; ++i) {
|
||||
this._scenes[i].removeBatches();
|
||||
|
||||
if (globalThis.__globalXR?.isWebXR) {
|
||||
this._doWebXRFrameMove();
|
||||
} else {
|
||||
this._frameMoveBegin();
|
||||
this._frameMoveProcess();
|
||||
this._frameMoveEnd();
|
||||
}
|
||||
|
||||
const windows = this._windows;
|
||||
const cameraList = this._cameraList;
|
||||
cameraList.length = 0;
|
||||
|
||||
for (let i = 0; i < windows.length; i++) {
|
||||
const window = windows[i];
|
||||
window.extractRenderCameras(cameraList);
|
||||
}
|
||||
|
||||
if (this._pipeline && cameraList.length > 0) {
|
||||
this._device.acquire([deviceManager.swapchain]);
|
||||
const scenes = this._scenes;
|
||||
const stamp = director.getTotalFrames();
|
||||
|
||||
if (this._batcher) {
|
||||
this._batcher.update();
|
||||
this._batcher.uploadBuffers();
|
||||
}
|
||||
|
||||
for (let i = 0; i < scenes.length; i++) {
|
||||
scenes[i].update(stamp);
|
||||
}
|
||||
|
||||
director.emit(Director.EVENT_BEFORE_COMMIT);
|
||||
cameraList.sort((a: Camera, b: Camera) => a.priority - b.priority);
|
||||
|
||||
for (let i = 0; i < cameraList.length; ++i) {
|
||||
cameraList[i].geometryRenderer?.update();
|
||||
}
|
||||
director.emit(Director.EVENT_BEFORE_RENDER);
|
||||
this._pipeline.render(cameraList);
|
||||
director.emit(Director.EVENT_AFTER_RENDER);
|
||||
this._device.present();
|
||||
}
|
||||
|
||||
if (this._batcher) this._batcher.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -733,6 +701,121 @@ export class Root {
|
||||
}
|
||||
}
|
||||
|
||||
private _doWebXRFrameMove () {
|
||||
const xr = globalThis.__globalXR;
|
||||
if (!xr || !xr.webXRMatProjs) {
|
||||
return;
|
||||
}
|
||||
|
||||
const windows = this._windows;
|
||||
const cameraList = this._cameraList;
|
||||
const viewCount = xr.webXRMatProjs.length;
|
||||
if (!xr.webXRWindowMap) {
|
||||
xr.webXRWindowMap = new Map<RenderWindow, number>();
|
||||
}
|
||||
|
||||
let allcameras: Camera[] = [];
|
||||
const webxrHmdPoseInfos = xr.webxrHmdPoseInfos;
|
||||
for (let xrEye = 0; xrEye < viewCount; xrEye++) {
|
||||
for (const window of windows) {
|
||||
allcameras = allcameras.concat(window.cameras);
|
||||
if (window.swapchain) {
|
||||
xr.webXRWindowMap.set(window, xrEye);
|
||||
}
|
||||
}
|
||||
|
||||
if (webxrHmdPoseInfos) {
|
||||
const cameraPosition: number[] = [];
|
||||
for (let i = 0; i < webxrHmdPoseInfos.length; i++) {
|
||||
const info = webxrHmdPoseInfos[i];
|
||||
if ((info.code === XRPoseType.VIEW_LEFT && xrEye === XREye.LEFT)
|
||||
|| (info.code === XRPoseType.VIEW_RIGHT && xrEye === XREye.RIGHT)) {
|
||||
cameraPosition[0] = info.position.x;
|
||||
cameraPosition[1] = info.position.y;
|
||||
cameraPosition[2] = info.position.z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const cam of allcameras) {
|
||||
if (cam.trackingType !== TrackingType.NO_TRACKING && cam.node) {
|
||||
cam.node.setPosition(cameraPosition[0], cameraPosition[1], cameraPosition[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
allcameras.length = 0;
|
||||
|
||||
this._frameMoveBegin();
|
||||
|
||||
this._frameMoveProcess();
|
||||
|
||||
for (let i = cameraList.length - 1; i >= 0; i--) {
|
||||
const camera = cameraList[i];
|
||||
const isMismatchedCam = (xrEye === XREye.LEFT && camera.cameraType === CameraType.RIGHT_EYE)
|
||||
|| (xrEye === XREye.RIGHT && camera.cameraType === CameraType.LEFT_EYE);
|
||||
if (isMismatchedCam) {
|
||||
// currently is left eye loop, so right camera do not need active
|
||||
cameraList.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
this._frameMoveEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private _frameMoveBegin () {
|
||||
for (let i = 0; i < this._scenes.length; ++i) {
|
||||
this._scenes[i].removeBatches();
|
||||
}
|
||||
|
||||
this._cameraList.length = 0;
|
||||
}
|
||||
|
||||
private _frameMoveProcess () {
|
||||
const { director } = cclegacy;
|
||||
const windows = this._windows;
|
||||
const cameraList = this._cameraList;
|
||||
|
||||
for (let i = 0; i < windows.length; i++) {
|
||||
const window = windows[i];
|
||||
window.extractRenderCameras(cameraList);
|
||||
}
|
||||
|
||||
if (this._pipeline && cameraList.length > 0) {
|
||||
this._device.acquire([deviceManager.swapchain]);
|
||||
const scenes = this._scenes;
|
||||
const stamp = director.getTotalFrames();
|
||||
|
||||
if (this._batcher) {
|
||||
this._batcher.update();
|
||||
this._batcher.uploadBuffers();
|
||||
}
|
||||
|
||||
for (let i = 0; i < scenes.length; i++) {
|
||||
scenes[i].update(stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _frameMoveEnd () {
|
||||
const { director, Director } = cclegacy;
|
||||
const cameraList = this._cameraList;
|
||||
if (this._pipeline && cameraList.length > 0) {
|
||||
director.emit(Director.EVENT_BEFORE_COMMIT);
|
||||
cameraList.sort((a: Camera, b: Camera) => a.priority - b.priority);
|
||||
|
||||
for (let i = 0; i < cameraList.length; ++i) {
|
||||
cameraList[i].geometryRenderer?.update();
|
||||
}
|
||||
director.emit(Director.EVENT_BEFORE_RENDER);
|
||||
this._pipeline.render(cameraList);
|
||||
director.emit(Director.EVENT_AFTER_RENDER);
|
||||
this._device.present();
|
||||
}
|
||||
|
||||
if (this._batcher) this._batcher.reset();
|
||||
}
|
||||
|
||||
private _resizeMaxJointForDS () {
|
||||
const usedUBOVectorCount = (UBOGlobal.COUNT + UBOCamera.COUNT + UBOShadow.COUNT + UBOLocal.COUNT + UBOWorldBound.COUNT) / 4;
|
||||
let maxJoints = Math.floor((deviceManager.gfxDevice.capabilities.maxVertexUniformVectors - usedUBOVectorCount) / 3);
|
||||
|
||||
@@ -131,6 +131,9 @@ export class Layers {
|
||||
js.value(Layers.Enum, String(val), name);
|
||||
Layers.BitMask[name] = val;
|
||||
js.value(Layers.BitMask, String(val), name);
|
||||
|
||||
BitMask.update(Layers.BitMask);
|
||||
Enum.update(Layers.Enum);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +151,9 @@ export class Layers {
|
||||
delete Layers.Enum[val];
|
||||
delete Layers.BitMask[Layers.BitMask[val]];
|
||||
delete Layers.BitMask[val];
|
||||
|
||||
BitMask.update(Layers.BitMask);
|
||||
Enum.update(Layers.Enum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -190,9 +190,16 @@ nodeProto.addComponent = function (typeOrClassName) {
|
||||
// check requirement
|
||||
|
||||
// TODO: `_requireComponent` is injected properties
|
||||
const ReqComp = (constructor as any)._requireComponent;
|
||||
if (ReqComp && !this.getComponent(ReqComp)) {
|
||||
this.addComponent(ReqComp);
|
||||
const reqComps = (constructor as any)._requireComponent;
|
||||
if (reqComps) {
|
||||
const tryAdd = (c: Component) => {
|
||||
if (!this.getComponent(c)) { this.addComponent(c); }
|
||||
};
|
||||
if (Array.isArray(reqComps)) {
|
||||
reqComps.forEach((c) => tryAdd(c));
|
||||
} else {
|
||||
tryAdd(reqComps);
|
||||
}
|
||||
}
|
||||
|
||||
/// / check conflict
|
||||
@@ -802,7 +809,7 @@ nodeProto.getWorldRS = function getWorldRS(out?: Mat4): Mat4 {
|
||||
return out;
|
||||
};
|
||||
|
||||
nodeProto.isTransformDirty = function(): Boolean {
|
||||
nodeProto.isTransformDirty = function (): Boolean {
|
||||
return this._transformFlags !== TransformBit.NONE;
|
||||
};
|
||||
|
||||
|
||||
@@ -565,6 +565,27 @@ export class SkyboxInfo {
|
||||
this._resource.setRotationAngle(this._rotationAngle);
|
||||
this._resource.activate(); // update global DS first
|
||||
}
|
||||
|
||||
/**
|
||||
* @en When the environment map changed will call this function to update scene.
|
||||
* @zh 环境贴图发生变化时,会调用此函数更新场景。
|
||||
* @param val environment map
|
||||
*/
|
||||
public updateEnvMap (val: TextureCube) {
|
||||
if (!val) {
|
||||
this.applyDiffuseMap = false;
|
||||
this.useIBL = false;
|
||||
this.envLightingType = EnvironmentLightingType.HEMISPHERE_DIFFUSE;
|
||||
warnID(15001);
|
||||
}
|
||||
if (this._resource) {
|
||||
this._resource.setEnvMaps(this._envmapHDR, this._envmapLDR);
|
||||
this._resource.setDiffuseMaps(this._diffuseMapHDR, this._diffuseMapLDR);
|
||||
this._resource.setReflectionMaps(this._reflectionHDR, this._reflectionLDR);
|
||||
this._resource.useDiffuseMap = this.applyDiffuseMap;
|
||||
this._resource.envmap = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
legacyCC.SkyboxInfo = SkyboxInfo;
|
||||
|
||||
|
||||
+16
-5
@@ -280,9 +280,8 @@ export class Skeleton extends UIRenderer {
|
||||
if (value) {
|
||||
this.setAnimation(0, value, this.loop);
|
||||
this.markForUpdateRenderData();
|
||||
} else if (!this.isAnimationCached()) {
|
||||
this.clearTrack(0);
|
||||
this.setToSetupPose();
|
||||
} else {
|
||||
this.clearAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +736,7 @@ export class Skeleton extends UIRenderer {
|
||||
*/
|
||||
public setSkeletonData (skeletonData: spine.SkeletonData) {
|
||||
const uiTrans = this.node._uiProps.uiTransformComp!;
|
||||
uiTrans.setContentSize(skeletonData.width, skeletonData.height);
|
||||
if (skeletonData.width && skeletonData.height) uiTrans.setContentSize(skeletonData.width, skeletonData.height);
|
||||
if (skeletonData.width !== 0) uiTrans.anchorX = Math.abs(skeletonData.x) / skeletonData.width;
|
||||
if (skeletonData.height !== 0) uiTrans.anchorY = Math.abs(skeletonData.y) / skeletonData.height;
|
||||
|
||||
@@ -1121,7 +1120,6 @@ export class Skeleton extends UIRenderer {
|
||||
*/
|
||||
public setAnimation (trackIndex: number, name: string, loop: boolean) {
|
||||
this._playTimes = loop ? 0 : 1;
|
||||
this._animationName = name;
|
||||
|
||||
if (this.isAnimationCached()) {
|
||||
if (trackIndex !== 0) {
|
||||
@@ -1133,6 +1131,7 @@ export class Skeleton extends UIRenderer {
|
||||
cache = this._skeletonCache.initAnimationCache(this._skeletonData!._uuid, name);
|
||||
}
|
||||
if (cache) {
|
||||
this._animationName = name;
|
||||
this._isAniComplete = false;
|
||||
this._accTime = 0;
|
||||
this._playCount = 0;
|
||||
@@ -1149,6 +1148,7 @@ export class Skeleton extends UIRenderer {
|
||||
logID(7509, name);
|
||||
return null;
|
||||
}
|
||||
this._animationName = name;
|
||||
const res = this._state!.setAnimationWith(trackIndex, animation, loop);
|
||||
this._state!.apply(this._skeleton);
|
||||
return res;
|
||||
@@ -1200,6 +1200,17 @@ export class Skeleton extends UIRenderer {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Clear animation and set to setup pose.
|
||||
* @zh 清除动画并还原到初始姿势。
|
||||
*/
|
||||
public clearAnimation () {
|
||||
if (!this.isAnimationCached()) {
|
||||
this.clearTrack(0);
|
||||
this.setToSetupPose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Returns track entry by trackIndex.<br>
|
||||
* Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.TrackEntry object.
|
||||
|
||||
@@ -80,3 +80,45 @@ export enum XRConfigKey {
|
||||
*/
|
||||
SPLIT_AR_GLASSES = 42
|
||||
}
|
||||
|
||||
/**
|
||||
* @en XR Pose Type Enum.
|
||||
* @zh XR姿态类型枚举。
|
||||
*/
|
||||
export enum XRPoseType {
|
||||
/**
|
||||
* @en The pose for left eye.
|
||||
* @zh 左眼姿态。
|
||||
*/
|
||||
VIEW_LEFT = 0,
|
||||
/**
|
||||
* @en The pose for left controller.
|
||||
* @zh 左手柄姿态。
|
||||
*/
|
||||
HAND_LEFT = 1,
|
||||
/**
|
||||
* @en The pose for left controller's aim.
|
||||
* @zh 左手柄瞄准方向姿态。
|
||||
*/
|
||||
AIM_LEFT = 2,
|
||||
/**
|
||||
* @en The pose for right eye.
|
||||
* @zh 右眼姿态。
|
||||
*/
|
||||
VIEW_RIGHT = 3,
|
||||
/**
|
||||
* @en The pose for right controller.
|
||||
* @zh 右手柄姿态。
|
||||
*/
|
||||
HAND_RIGHT = 4,
|
||||
/**
|
||||
* @en The pose for right controller's aim.
|
||||
* @zh 右手柄瞄准方向姿态。
|
||||
*/
|
||||
AIM_RIGHT = 5,
|
||||
/**
|
||||
* @en The pose for head.
|
||||
* @zh 头部姿态。
|
||||
*/
|
||||
HEAD_MIDDLE = 6,
|
||||
}
|
||||
|
||||
@@ -380,7 +380,8 @@ vec4 gpvs_main () {
|
||||
frameInfo = mix(frameInfo0, frameInfo1, factor_t);
|
||||
}
|
||||
startFrame = frameInfo.x / u_anim_info.y;
|
||||
frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);
|
||||
float EPSILON = 1e-6;
|
||||
frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1. + EPSILON);
|
||||
#endif
|
||||
uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// #pragma define SRGBToLinear(gamma) pow(gamma, vec3(2.2))
|
||||
vec3 SRGBToLinear (vec3 gamma) {
|
||||
#ifdef CC_USE_SURFACE_SHADER
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {
|
||||
return gamma;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ vec3 SRGBToLinear (vec3 gamma) {
|
||||
// #pragma define LinearToSRGB(linear) pow(linear, vec3(0.454545))
|
||||
vec3 LinearToSRGB(vec3 linear) {
|
||||
#ifdef CC_USE_SURFACE_SHADER
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {
|
||||
return linear;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
#include <common/color/aces>
|
||||
|
||||
vec3 HDRToLDR(vec3 color)
|
||||
{
|
||||
#if CC_USE_HDR
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
|
||||
#endif
|
||||
// linear exposure has already applied to light intensity
|
||||
#if CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "077c9168-e907-405b-b7f6-b4d5f68ced4a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#pragma define equalf_lowp(data1, data2) (abs(float(data1) - float(data2)) < EPSILON_LOWP)
|
||||
#pragma define equalf_epsilon(data1, data2, epsilonValue) (abs(float(data1) - float(data2)) < epsilonValue)
|
||||
#pragma define clip(value) if(value < 0.0) discard;
|
||||
#pragma define lerp(value1, value2, value2Multiplier) mix(value1, value2, value2Multiplier)
|
||||
|
||||
// runtime constants
|
||||
#pragma define-meta CC_DEVICE_SUPPORT_FLOAT_TEXTURE default(1)
|
||||
@@ -72,5 +73,9 @@
|
||||
#define IS_POINT_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_POINT)
|
||||
#define IS_RANGED_DIRECTIONAL_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_RANGED_DIRECTIONAL)
|
||||
|
||||
// CC_TONE_MAPPING_TYPE Values
|
||||
#define TONE_MAPPING_ACES 0
|
||||
#define TONE_MAPPING_LINEAR 1
|
||||
|
||||
// Material
|
||||
#define SURFACES_MAX_TRANSMIT_DEPTH_VALUE 999999.0
|
||||
|
||||
@@ -43,12 +43,12 @@
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_SPECULAR + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_DIFFUSE + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ALL CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_SPECULAR + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRT_DIRECT CC_SURFACES_DEBUG_VIEW_TRANSMIT_ALL + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRT_ENVIRONMENT CC_SURFACES_DEBUG_VIEW_TRT_DIRECT + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_TRT_ALL CC_SURFACES_DEBUG_VIEW_TRT_ENVIRONMENT + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR CC_SURFACES_DEBUG_VIEW_TRANSMIT_ALL + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_ENVIRONMENT_2ND_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_2ND_SPECULAR_ALL CC_SURFACES_DEBUG_VIEW_ENVIRONMENT_2ND_SPECULAR + 1
|
||||
|
||||
// misc data
|
||||
#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_TRT_ALL + 1
|
||||
#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_2ND_SPECULAR_ALL + 1
|
||||
|
||||
// Debug view UI and macros
|
||||
// #pragma define-meta CC_USE_DEBUG_VIEW range([0, 2])
|
||||
@@ -76,5 +76,5 @@
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FRESNEL (UnpackBitFromFloat(cc_debug_view_mode.z, 4) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRANSMIT_DIFFUSE (UnpackBitFromFloat(cc_debug_view_mode.z, 5) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRANSMIT_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.z, 6) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRT (UnpackBitFromFloat(cc_debug_view_mode.z, 7) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_2ND_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.z, 7) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TT (UnpackBitFromFloat(cc_debug_view_mode.w, 0) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
|
||||
|
||||
@@ -10,3 +10,32 @@ void DitheredAlphaClip(vec4 clipPos, vec2 screen_resolution, float transparency)
|
||||
float dither = ( dither5 * 5.0 + noiseValue ) * (1.0 / 6.0);
|
||||
if( transparency + dither < 0.833333333 ) discard;
|
||||
}
|
||||
|
||||
// NormalFromMap is: texture(normalmap) - 0.5
|
||||
vec3 BlendDetailedNormalMap(vec3 baseNormalFromMap, vec3 detailedNormalFromMap, float detailedIntensity)
|
||||
{
|
||||
return normalize(vec3(baseNormalFromMap.xy + detailedNormalFromMap.xy * detailedIntensity, baseNormalFromMap.z));
|
||||
}
|
||||
|
||||
|
||||
float BlendDetailedColorMap(float baseColor, float detailedColor)
|
||||
{
|
||||
float s = baseColor, d = detailedColor;
|
||||
if (s < 0.5)
|
||||
{
|
||||
return 2.0 * s * d;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d >= 0.5)
|
||||
return 1.0 - 2.0 * (1.0 - s) * (1.0 - d);
|
||||
else
|
||||
return mix(2.0 * s * d, s, (2.0 * s - 1.0) * (2.0 * s - 1.0));
|
||||
}
|
||||
}
|
||||
vec3 BlendDetailedColorMap(vec3 baseColor, vec3 detailedColor)
|
||||
{
|
||||
return vec3(BlendDetailedColorMap(baseColor.r, detailedColor.r),
|
||||
BlendDetailedColorMap(baseColor.g, detailedColor.g),
|
||||
BlendDetailedColorMap(baseColor.b, detailedColor.b));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "8cab82a8-3634-48c2-8853-021f200cf799",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// base coordinates & color expressions for shader-graph
|
||||
|
||||
|
||||
// fraction is saturation percentage, 0 means gray
|
||||
vec3 Desaturation(vec3 color, float fraction)
|
||||
{
|
||||
vec3 gray = vec3(dot(color, GRAY_VECTOR));
|
||||
return mix(color, gray, fraction);
|
||||
}
|
||||
|
||||
vec2 Rotator(vec2 uv, vec2 centerUV, float time, float speed)
|
||||
{
|
||||
uv -= centerUV;
|
||||
vec3 dir = vec3(uv.x, 0.0, uv.y);
|
||||
float dirLength = length(dir);
|
||||
dir /= dirLength + EPSILON;
|
||||
dir = RotationVecFromAxisY(dir, time * speed) * dirLength;
|
||||
return vec2(dir.x, dir.z) + centerUV;
|
||||
}
|
||||
|
||||
// tangent space -> world space
|
||||
// same as TransformVector
|
||||
vec3 TransformNormalMap(vec3 vectorFromNormalMap)
|
||||
{
|
||||
vec3 vectorTS = normalize(vectorFromNormalMap - vec3(0.5));
|
||||
vec3 normal = normalize(FSInput_worldNormal);
|
||||
vec3 tangent = normalize(FSInput_worldTangent);
|
||||
vec3 binormal = CalculateBinormal(normal, tangent, FSInput_mirrorNormal);
|
||||
vec3 vecWS = vectorTS.x * tangent + vectorTS.y * binormal + vectorTS.z * normal;
|
||||
return vecWS * vec3(1.0, 1.0, -1.0); // inverse Z for RH
|
||||
}
|
||||
|
||||
|
||||
// return 0.0 when out of range
|
||||
// hardness: 0 - 1
|
||||
float SphereMask(vec2 center, vec2 point, float radius, float hardness)
|
||||
{
|
||||
float length = length(center - point);
|
||||
float coef = pow(saturate(length / radius), 1.0 / (1.0 - saturate(sqrt(hardness)) + EPSILON));
|
||||
return length > radius ? 0.0 : 1.0 - coef;
|
||||
}
|
||||
float SphereMask(vec3 center, vec3 point, float radius, float hardness)
|
||||
{
|
||||
float length = length(center - point);
|
||||
float coef = pow(saturate(length / radius), 1.0 / (1.0 - saturate(sqrt(hardness)) + EPSILON));
|
||||
return length > radius ? 0.0 : 1.0 - coef;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "4b4d0c0f-1d50-4d50-84e7-226c8d0dbd6f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -4,17 +4,34 @@
|
||||
// V from pixel to camera
|
||||
vec3 CalculateRefractDirection(vec3 N, vec3 V, float NoV, float ior)
|
||||
{
|
||||
float NoVAbs = abs(NoV);
|
||||
// two sided
|
||||
float sideSign = NoV < 0.0 ? -1.0 : 1.0;
|
||||
N *= sideSign;
|
||||
NoV *= sideSign;
|
||||
float sinB = sqrt(1.0 - NoVAbs*NoVAbs) / ior;
|
||||
vec3 X = normalize(-V + N * NoVAbs);
|
||||
vec3 R = -N + X * sinB;
|
||||
|
||||
// A: NV B:NR
|
||||
float cosA = abs(NoV);
|
||||
float sinA = sqrt(1.0 - cosA * cosA);
|
||||
float sinB = saturate(sinA / ior);
|
||||
float cosB = sqrt(1.0 - sinB * sinB);
|
||||
|
||||
vec3 edgeA = -V + N * cosA;
|
||||
vec3 edgeB = normalize(edgeA) * sinB;
|
||||
vec3 R = edgeB - N * cosB;
|
||||
return R;
|
||||
}
|
||||
|
||||
vec3 CalculateRefractDirectionFast(vec3 N, vec3 V, float NoV, float ior)
|
||||
{
|
||||
// two sided
|
||||
float sideSign = NoV < 0.0 ? -1.0 : 1.0;
|
||||
N *= sideSign;
|
||||
|
||||
float w = ior * NoV;
|
||||
float k = sqrt(1.0 + (w - ior) * (w + ior)); // 1 + ior2 * (NoV2 - 1)
|
||||
vec3 R = (w - k) * N - ior * V;
|
||||
return -R;
|
||||
}
|
||||
|
||||
vec3 CalculateReflectDirection(vec3 N, vec3 V, float NoV)
|
||||
{
|
||||
// two sided
|
||||
|
||||
@@ -27,7 +27,8 @@ vec2 GetPlanarReflectScreenUV(vec3 worldPos, mat4 matVirtualCameraViewProj, floa
|
||||
return screenUV;
|
||||
}
|
||||
|
||||
// depthHS = ndc depth(-1 ~ +1)
|
||||
// depthHS (Z) = ndc depth(-1 ~ +1)
|
||||
// return camera depth (W), negative in RH
|
||||
float GetCameraDepthRH(float depthHS, mat4 matProj)
|
||||
{
|
||||
return -matProj[3][2] / (depthHS + matProj[2][2]);
|
||||
@@ -55,10 +56,18 @@ float GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {
|
||||
return (dist - near) / (far - near);
|
||||
}
|
||||
|
||||
// params must be normalized
|
||||
// for right-hand coordinates, params must be normalized
|
||||
vec3 CalculateBinormal(vec3 normal, vec3 tangent, float mirrorNormal)
|
||||
{
|
||||
return cross(normal.xyz, tangent) * mirrorNormal;
|
||||
return cross(normal, tangent) * mirrorNormal;
|
||||
}
|
||||
vec3 CalculateTangent(vec3 normal, vec3 binormal)
|
||||
{
|
||||
return cross(binormal, normal);
|
||||
}
|
||||
vec3 CalculateNormal(vec3 tangent, vec3 binormal)
|
||||
{
|
||||
return cross(tangent, binormal);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +90,11 @@ vec3 RotationVecFromAxisY(vec3 v, float cosTheta, float sinTheta)
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 RotationVecFromAxisY(vec3 v, float rotateAngleArc)
|
||||
{
|
||||
return RotationVecFromAxisY(v, cos(rotateAngleArc), sin(rotateAngleArc));
|
||||
}
|
||||
|
||||
// rotationAngle: radians, 0-2Pi
|
||||
void RotateTangentAndBinormal(inout vec3 tangent, inout vec3 binormal, vec3 normal, float rotationAngle)
|
||||
{
|
||||
@@ -94,14 +108,22 @@ void RotateTangentAndBinormal(inout vec3 tangent, inout vec3 binormal, vec3 norm
|
||||
|
||||
tangentNew = T.x * binormal + T.y * normal + T.z * tangent;
|
||||
tangent = normalize(tangentNew);
|
||||
// tangent = cross(binormal, normal);
|
||||
}
|
||||
|
||||
// fast rotation for anisotropic offset
|
||||
// rotationAngle: -1 - +1
|
||||
void RotateNormalAndBinormal(inout vec3 binormal, inout vec3 normal, in vec3 tangent, float rotationAngle)
|
||||
void RotateNormalAndBinormal(inout vec3 binormal, inout vec3 normal, in vec3 tangent, float rotationAngle, float mirrorNormal)
|
||||
{
|
||||
normal += (binormal - normal) * rotationAngle;
|
||||
normal = normalize(normal);
|
||||
binormal = normalize(cross(tangent, normal));
|
||||
if(rotationAngle > 0.0)
|
||||
{
|
||||
normal += (binormal - normal) * rotationAngle;
|
||||
normal = normalize(normal);
|
||||
binormal = CalculateBinormal(normal, tangent, mirrorNormal);
|
||||
}
|
||||
else if(rotationAngle < 0.0)
|
||||
{
|
||||
binormal += (binormal - normal) * rotationAngle;
|
||||
binormal = normalize(binormal);
|
||||
normal = CalculateNormal(tangent, binormal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
#include <common/color/aces>
|
||||
#include <common/color/gamma>
|
||||
#include <common/data/unpack>
|
||||
|
||||
vec4 CCFragOutput (vec4 color) {
|
||||
#if !CC_USE_RGBE_OUTPUT
|
||||
#if CC_USE_HDR
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#elif !CC_USE_FLOAT_OUTPUT
|
||||
#if CC_USE_HDR && CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {
|
||||
#endif
|
||||
#if CC_USE_LIGHTMAP == LIGHT_MAP_TYPE_INDIRECT_OCCLUSION
|
||||
shadow *= s.lightmap.a; // apply baked shadows for real-time lighting
|
||||
s.occlusion *= s.lightmap_test;
|
||||
finalColor += diffuse * lightmap.rgb;
|
||||
#else
|
||||
finalColor += diffuse * lightmap.rgb * shadow; // apply real-time shadows for baked color
|
||||
#endif
|
||||
s.occlusion *= s.lightmap_test;
|
||||
#endif
|
||||
|
||||
#if !CC_DISABLE_DIRECTIONAL_LIGHT
|
||||
|
||||
@@ -31,14 +31,11 @@
|
||||
\
|
||||
void main () { \
|
||||
StandardSurface s; surf(s); \
|
||||
vec4 color = CCFragOutput(CCStandardShadingBase(s, CC_SHADOW_POSITION)); \
|
||||
vec4 color = CCStandardShadingBase(s, CC_SHADOW_POSITION); \
|
||||
#if CC_USE_FOG != CC_FOG_NONE \
|
||||
CC_APPLY_FOG(color, s.position.xyz); \
|
||||
#endif \
|
||||
#if CC_USE_RGBE_OUTPUT \
|
||||
color = packRGBE(color.rgb); \
|
||||
#endif \
|
||||
fragColorX = color; \
|
||||
fragColorX = CCFragOutput(color); \
|
||||
} \
|
||||
\
|
||||
#elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED \
|
||||
|
||||
@@ -34,9 +34,6 @@ struct LightingIntermediateData
|
||||
vec3 baseColorTT;
|
||||
float ttIntensity, ttScatterCoef;
|
||||
#endif
|
||||
// #if CC_SURFACES_LIGHTING_CLEAR_COAT
|
||||
// float roughnessClearCoat; // for clear coat or multi-layer pbr
|
||||
// #endif
|
||||
};
|
||||
|
||||
// add overrided functions for difference shading-models in <surfaces/module-functions/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
struct LightingResult
|
||||
{
|
||||
// material-dependent lighting data
|
||||
vec3 diffuseColorWithLighting, specularColorWithLighting;
|
||||
vec3 diffuseColorWithLighting, specularColorWithLighting, specularColorWithEnvLighting;
|
||||
|
||||
// pure lighting
|
||||
vec3 directDiffuse, directSpecular;
|
||||
@@ -21,9 +21,9 @@ struct LightingResult
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE
|
||||
vec3 directTransmitDiffuse, environmentTransmitDiffuse;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
vec3 directTRT, environmentTRT;
|
||||
vec3 specularColorWithLightingTRT;
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
vec3 direct2ndSpecular, environment2ndSpecular;
|
||||
vec3 specularColorWithLighting2ndSpecular, specularColorWithEnvLighting2ndSpecular;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
vec3 directTT;
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
{
|
||||
#if CC_SURFACES_LIGHTING_SSS
|
||||
float sssIntensity = surfaceData.sssParams.x;
|
||||
// curvature needs pre-generating in vertex or texture data, otherwise disable pre-integrated skin
|
||||
float sssCurvature = surfaceData.sssParams.y;
|
||||
float sssColoration = surfaceData.sssParams.z;
|
||||
float cavity = surfaceData.sssParams.w;
|
||||
|
||||
// update lighting data for diffuse calculations
|
||||
LightingIntermediateData lightingData3S = lightingData;
|
||||
lightingData3S.N = FSInput_worldNormal;
|
||||
lightingData3S.N = normalize(FSInput_worldNormal);
|
||||
lightingData3S.NoL = dot(lightingData3S.N, -miscData.lightDir);
|
||||
lightingData3S.NoL = mix(lightingData.NoL, lightingData3S.NoL, sssIntensity);
|
||||
lightingData3S.NoLSat = saturate(lightingData3S.NoL);
|
||||
@@ -31,11 +31,8 @@
|
||||
result.directDiffuse = CalculateDirectDiffuse(lightingData3S, miscData.lightColorAndIntensity) * multiplier;
|
||||
#endif
|
||||
|
||||
result.directSpecular *= cavity;
|
||||
|
||||
#if !CC_FORWARD_ADD
|
||||
result.environmentDiffuse = CalculateEnvironmentDiffuse(lightingData3S, cc_ambientSky.w);
|
||||
result.environmentSpecular *= cavity;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11,24 +11,24 @@
|
||||
CCSurfacesInitializeLightingIntermediateData(lightingData, surfaceData);
|
||||
|
||||
LightingResult lightingResult;
|
||||
CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData);
|
||||
lightingResultAccumulated.diffuseColorWithLighting = lightingResult.diffuseColorWithLighting;
|
||||
lightingResultAccumulated.specularColorWithLighting = lightingResult.specularColorWithLighting;
|
||||
lightingResultAccumulated.specularColorWithEnvLighting = lightingResult.specularColorWithEnvLighting;
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
vec3 diff;
|
||||
SurfacesMaterialData surfaceDataTRT;
|
||||
CCSurfacesGetSurfacesMaterialDataTRT(surfaceDataTRT, surfaceData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(diff, lightingResultAccumulated.specularColorWithLightingTRT, surfaceDataTRT, lightingData);
|
||||
SurfacesMaterialData surfaceData2ndSpecular;
|
||||
CCSurfacesGetSurfacesMaterialData2ndSpecular(surfaceData2ndSpecular, surfaceData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(diff, lightingResultAccumulated.specularColorWithLighting2ndSpecular, lightingResultAccumulated.specularColorWithEnvLighting2ndSpecular, surfaceData2ndSpecular, lightingData);
|
||||
#endif
|
||||
|
||||
int numLights = CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);
|
||||
for (int i = 0; i < LIGHTS_PER_PASS; i++) {
|
||||
if (i >= numLights) break;
|
||||
|
||||
vec3 lightDirWithLength = IS_RANGED_DIRECTIONAL_LIGHT(cc_lightPos[i].w) ? -normalize(cc_lightDir[i].xyz) : cc_lightPos[i].xyz - worldPos;
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, lightDirWithLength);
|
||||
CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, cc_lightPos[i].xyz - worldPos);
|
||||
CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData);
|
||||
|
||||
vec3 diffuseLighting, specularLighting;
|
||||
CCSurfacesLightingCalculateDirect(diffuseLighting, specularLighting, lightingData, cc_lightColor[i]);
|
||||
@@ -38,10 +38,9 @@
|
||||
fresnel = lightingResult.fresnel = CCSurfaceLightingCalculateFresnel(lightingData);
|
||||
#endif
|
||||
|
||||
// shadows
|
||||
float shadow = 1.0;
|
||||
#if CC_RECEIVE_SHADOW && CC_SHADOW_TYPE == CC_SHADOW_MAP
|
||||
if (IS_SPOT_LIGHT(cc_lightPos[i].w) && cc_lightSizeRangeAngle[i].w > 0.0) {
|
||||
if (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {
|
||||
vec4 shadowPos = vec4(0.0), shadowPosWithDepthBias = vec4(0.0);
|
||||
if (CCSurfacesLightingEnableShadow(lightingData.NoL)) {
|
||||
shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);
|
||||
@@ -65,23 +64,16 @@
|
||||
#endif
|
||||
|
||||
lightingResult.shadow = shadow;
|
||||
|
||||
// attenuations
|
||||
float distAtt = 1.0;
|
||||
if(IS_RANGED_DIRECTIONAL_LIGHT(cc_lightPos[i].w)) {
|
||||
distAtt = GetOutOfRange(worldPos, cc_lightPos[i].xyz, cc_lightDir[i].xyz, cc_lightSizeRangeAngle[i].xyz, cc_lightBoundingSizeVS[i].xyz);
|
||||
} else {
|
||||
distAtt = CCSurfacesLightingCalculateDistanceAttenuation(lightingData, cc_lightSizeRangeAngle[i], cc_lightPos[i].w);
|
||||
}
|
||||
|
||||
float distAtt = CCSurfacesLightingCalculateDistanceAttenuation(lightingData, cc_lightSizeRangeAngle[i]);
|
||||
|
||||
float angleAtt = 1.0;
|
||||
if (IS_SPOT_LIGHT(cc_lightPos[i].w)) {
|
||||
if (cc_lightPos[i].w > 0.0) {
|
||||
angleAtt = CCSurfacesLightingCalculateAngleAttenuation(lightingData, cc_lightSizeRangeAngle[i], -cc_lightDir[i].xyz);
|
||||
}
|
||||
|
||||
float multiplier = distAtt * angleAtt;
|
||||
|
||||
// output
|
||||
lightingData.angleAttenuation = angleAtt;
|
||||
lightingData.distAttenuation = distAtt;
|
||||
lightingResult.directDiffuse = diffuseLighting * multiplier;
|
||||
@@ -98,16 +90,16 @@
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE
|
||||
LightingIntermediateData lightingDataTD;
|
||||
CCSurfacesGetLightingIntermediateDataTransmitDiffuse(lightingDataTD, lightingData, surfaceData);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingDataTD, surfaceData, lightDirWithLength);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingDataTD, surfaceData, cc_lightPos[i].xyz - worldPos);
|
||||
CCSurfacesLightingCalculateDirectTransmitDiffuse(lightingResult.directTransmitDiffuse, lightingDataTD, attenuatedLightColorAndIntensity, lightingResult.shadow);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
LightingIntermediateData lightingDataTRT;
|
||||
CCSurfacesGetLightingIntermediateDataTRT(lightingDataTRT, lightingData, surfaceData);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingDataTRT, surfaceData, lightDirWithLength);
|
||||
CCSurfacesLightingCalculateDirectTRT(lightingResult.directTRT, lightingDataTRT, attenuatedLightColorAndIntensity, lightingResult.directSpecular);
|
||||
lightingResult.directTRT *= multiplier * fresnel;
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
LightingIntermediateData lightingData2ndSpecular;
|
||||
CCSurfacesInitializeLightingIntermediateData(lightingData2ndSpecular, surfaceData2ndSpecular);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData2ndSpecular, surfaceData, cc_lightPos[i].xyz - worldPos);
|
||||
CCSurfacesLightingCalculateDirect2ndSpecular(lightingResult.direct2ndSpecular, lightingData2ndSpecular, attenuatedLightColorAndIntensity, surfaceData2ndSpecular.intensity2ndSpecular, lightingResult.directSpecular);
|
||||
lightingResult.direct2ndSpecular *= multiplier * fresnel;
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
@@ -124,7 +116,7 @@
|
||||
miscData.lightColorAndIntensity = cc_lightColor[i];
|
||||
miscData.lightSizeRangeAngle = cc_lightSizeRangeAngle[i];
|
||||
SurfacesLightingModifyFinalResult(lightingResult, lightingData, surfaceData, miscData);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// accumulate per-light results
|
||||
CCSurfacesAccumulateLightingResult(lightingResultAccumulated, lightingResult);
|
||||
@@ -140,7 +132,7 @@
|
||||
CCSurfacesInitializeLightingIntermediateData(lightingData, surfaceData);
|
||||
CCSurfacesInitializeLightingResult(lightingResult, surfaceData);
|
||||
|
||||
CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData);
|
||||
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, -cc_mainLitDir.xyz);
|
||||
|
||||
@@ -186,14 +178,15 @@
|
||||
|
||||
#if CC_SURFACES_USE_LIGHT_MAP == LIGHT_MAP_TYPE_INDIRECT_OCCLUSION
|
||||
lightingResult.shadow *= lightmapShadow;
|
||||
lightingResult.ao *= lightmapAO;
|
||||
#endif
|
||||
// env lighting hasn't baked with static / stationary type, so ao need to be output all the time
|
||||
lightingResult.ao *= lightmapAO;
|
||||
#endif
|
||||
|
||||
// dynamic & stationary dir light
|
||||
lightingResult.directDiffuse = lightingResult.directSpecular = vec3(0.0);
|
||||
#if !CC_DISABLE_DIRECTIONAL_LIGHT && !CC_FORWARD_ADD
|
||||
CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData);
|
||||
CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, lightingResult.specularColorWithEnvLighting, surfaceData, lightingData);
|
||||
|
||||
CCSurfacesLightingCalculateDirect(lightingResult.directDiffuse, lightingResult.directSpecular, lightingData, cc_mainLitColor);
|
||||
#endif
|
||||
@@ -221,17 +214,18 @@
|
||||
CCSurfacesLightingCalculateEnvironmentTransmitDiffuse(lightingResult.environmentTransmitDiffuse, lightingDataTD, cc_ambientSky.w, lightingResult.ao, -cc_mainLitDir.xyz);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
LightingIntermediateData lightingDataTRT;
|
||||
CCSurfacesGetLightingIntermediateDataTRT(lightingDataTRT, lightingData, surfaceData);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingDataTRT, surfaceData, -cc_mainLitDir.xyz);
|
||||
CCSurfacesLightingCalculateDirectTRT(lightingResult.directTRT, lightingDataTRT, cc_mainLitColor, lightingResult.directSpecular);
|
||||
CCSurfacesLightingCalculateEnvironmentTRT(lightingResult.environmentTRT, lightingDataTRT, cc_ambientSky.w, lightingResult.environmentSpecular);
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
SurfacesMaterialData surfaceData2ndSpecular;
|
||||
CCSurfacesGetSurfacesMaterialData2ndSpecular(surfaceData2ndSpecular, surfaceData);
|
||||
|
||||
LightingIntermediateData lightingData2ndSpecular;
|
||||
CCSurfacesInitializeLightingIntermediateData(lightingData2ndSpecular, surfaceData2ndSpecular);
|
||||
CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData2ndSpecular, surfaceData2ndSpecular, -cc_mainLitDir.xyz);
|
||||
CCSurfacesLightingCalculateDirect2ndSpecular(lightingResult.direct2ndSpecular, lightingData2ndSpecular, cc_mainLitColor, surfaceData2ndSpecular.intensity2ndSpecular, lightingResult.directSpecular);
|
||||
CCSurfacesLightingCalculateEnvironment2ndSpecular(lightingResult.environment2ndSpecular, lightingData2ndSpecular, cc_ambientSky.w, surfaceData2ndSpecular.intensity2ndSpecular, lightingResult.environmentSpecular);
|
||||
|
||||
vec3 diff;
|
||||
SurfacesMaterialData surfaceDataTRT;
|
||||
CCSurfacesGetSurfacesMaterialDataTRT(surfaceDataTRT, surfaceData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(diff, lightingResult.specularColorWithLightingTRT, surfaceDataTRT, lightingDataTRT);
|
||||
CCSurfacesLightingInitializeColorWithLighting(diff, lightingResult.specularColorWithLighting2ndSpecular, lightingResult.specularColorWithEnvLighting2ndSpecular, surfaceData2ndSpecular, lightingData2ndSpecular);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
@@ -247,7 +241,7 @@
|
||||
miscData.lightColorAndIntensity = cc_mainLitColor;
|
||||
miscData.lightSizeRangeAngle = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
SurfacesLightingModifyFinalResult(lightingResult, lightingData, surfaceData, miscData);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#if CC_ENABLE_CLUSTERED_LIGHT_CULLING
|
||||
// #todo: cluster related lighting flow, invoke after CCSurfacesLighting
|
||||
|
||||
@@ -113,6 +113,7 @@ void CCSurfacesLightingCalculateEnvironment(out vec3 lightingDiffuse, out vec3 l
|
||||
|
||||
void CCSurfacesLightingCalculateDirectTransmitDiffuse(out vec3 transmitDiffuse, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity, float shadow)
|
||||
{
|
||||
#if !CC_SURFACES_LIGHTING_DISABLE_DIFFUSE
|
||||
float distance = lightingData.transmitScatteringParams.w;
|
||||
if (!DONOT_USE_SHADOWMAP_DISTANCE)
|
||||
{
|
||||
@@ -123,10 +124,14 @@ void CCSurfacesLightingCalculateEnvironment(out vec3 lightingDiffuse, out vec3 l
|
||||
vec3 backIrradiance = CalculateDirectDiffuse(lightingData, lightSourceColorAndIntensity);
|
||||
backIrradiance *= shadow * transmitMask;
|
||||
transmitDiffuse = CalculateScattering(backIrradiance, distance, lightingData.transmitScatteringParams.x, lightingData.transmitScatteringParams.x, lightingData.transmitScatteringParams.y, lightingData.inScatteringColor.rgb, lightingData.outScatteringColor.rgb);
|
||||
#else
|
||||
transmitDiffuse = vec3(0.0);
|
||||
#endif
|
||||
}
|
||||
// depend on dir-light shadow direction, if there are some occluders in front of the light source, env transmit will dark
|
||||
void CCSurfacesLightingCalculateEnvironmentTransmitDiffuse(out vec3 transmitDiffuse, in LightingIntermediateData lightingData, float lightIntensity, float ao, vec3 shadowLightDirection)
|
||||
{
|
||||
#if !CC_SURFACES_LIGHTING_DISABLE_DIFFUSE
|
||||
float distance = lightingData.transmitScatteringParams.w;
|
||||
if (!DONOT_USE_SHADOWMAP_DISTANCE)
|
||||
{
|
||||
@@ -141,6 +146,9 @@ void CCSurfacesLightingCalculateEnvironment(out vec3 lightingDiffuse, out vec3 l
|
||||
backIrradiance *= ao * transmitMask;
|
||||
transmitDiffuse = CalculateScattering(backIrradiance, distance, lightingData.transmitScatteringParams.x, lightingData.transmitScatteringParams.x, lightingData.transmitScatteringParams.y, lightingData.inScatteringColor.rgb, lightingData.outScatteringColor.rgb);
|
||||
transmitDiffuse *= envTransmitScale;
|
||||
#else
|
||||
transmitDiffuse = vec3(0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef objectThickness
|
||||
@@ -151,38 +159,48 @@ void CCSurfacesLightingCalculateEnvironment(out vec3 lightingDiffuse, out vec3 l
|
||||
#undef SHADOWMAP_DISTANCE
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
// this surface function used for adjust TRT color with brdf lighting, input are lighting result and surface data
|
||||
// the default function can only be defined here
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRT_SPECULAR_COLOR
|
||||
vec3 SurfacesLightingGetTRTSpecularColor(float specBRDF, bool isSaturated)
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_2ND_SPECULAR_COLOR
|
||||
vec3 SurfacesLightingGet2ndSpecularColor(float specBRDF, bool isSaturated)
|
||||
{
|
||||
return vec3(specBRDF);
|
||||
return vec3(saturate(specBRDF));
|
||||
}
|
||||
#endif
|
||||
|
||||
void CCSurfacesLightingCalculateDirectTRT(out vec3 TRTLighting, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity, in vec3 originalSpecular)
|
||||
void CCSurfacesLightingCalculateDirect2ndSpecular(out vec3 specularLighting, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity, float intensitySpecular, in vec3 originalSpecular)
|
||||
{
|
||||
#if !CC_SURFACES_LIGHTING_DISABLE_SPECULAR
|
||||
vec3 unused;
|
||||
// light color has less influence
|
||||
CCSurfacesLightingCalculateDirect(unused, TRTLighting, lightingData, vec4(1.0));
|
||||
float brdf = TRTLighting.x;
|
||||
vec3 Color = SurfacesLightingGetTRTSpecularColor(brdf, true);
|
||||
CCSurfacesLightingCalculateDirect(unused, specularLighting, lightingData, lightSourceColorAndIntensity);
|
||||
// float brdf = specularLighting.x;
|
||||
// vec3 Color = SurfacesLightingGet2ndSpecularColor(brdf, true);
|
||||
// todo: modify Color to add some light color influence
|
||||
TRTLighting *= Color * lightSourceColorAndIntensity.w;
|
||||
// TRTLighting -= originalSpecular;
|
||||
// specularLighting *= Color * lightSourceColorAndIntensity.w;
|
||||
specularLighting *= intensitySpecular;
|
||||
// specularLighting -= originalSpecular;
|
||||
#else
|
||||
specularLighting = vec3(0.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCSurfacesLightingCalculateEnvironmentTRT(out vec3 TRTLighting, in LightingIntermediateData lightingData, float lightIntensity, in vec3 originalSpecular)
|
||||
void CCSurfacesLightingCalculateEnvironment2ndSpecular(out vec3 specularLighting, in LightingIntermediateData lightingData, float lightIntensity, float intensitySpecular, in vec3 originalSpecular)
|
||||
{
|
||||
#if !CC_SURFACES_LIGHTING_DISABLE_SPECULAR
|
||||
vec3 unused;
|
||||
// light color has less influence
|
||||
TRTLighting = CalculateEnvironmentSpecular(lightingData, 1.0);
|
||||
float brdf = length(TRTLighting);
|
||||
vec3 Color = SurfacesLightingGetTRTSpecularColor(brdf, false);
|
||||
specularLighting = CalculateEnvironmentSpecular(lightingData, lightIntensity);
|
||||
// float brdf = length(specularLighting);
|
||||
// vec3 Color = SurfacesLightingGet2ndSpecularColor(brdf, false);
|
||||
// todo: modify Color to add some light color influence
|
||||
TRTLighting *= Color * lightIntensity;
|
||||
// TRTLighting -= originalSpecular;
|
||||
// specularLighting *= Color * lightIntensity;
|
||||
specularLighting *= intensitySpecular;
|
||||
// specularLighting -= originalSpecular;
|
||||
#else
|
||||
specularLighting = vec3(0.0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void CCSurfacesGetFragmentInput(out SurfacesStandardFragmentInput fsInput)
|
||||
|
||||
// Use macros instead of structure to avoid structure precision issues
|
||||
#define FSInput_worldPos v_worldPos
|
||||
#define FSInput_worldNormal v_normal.xyz
|
||||
#define FSInput_worldNormal v_normal.xyz // unnormalized
|
||||
#define FSInput_faceSideSign v_normal.w // physical face side, has no relation to USE_TWO_SIDED
|
||||
#define FSInput_texcoord v_uv
|
||||
|
||||
@@ -28,7 +28,7 @@ void CCSurfacesGetFragmentInput(out SurfacesStandardFragmentInput fsInput)
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_USE_TANGENT_SPACE
|
||||
#define FSInput_worldTangent v_tangent.xyz
|
||||
#define FSInput_worldTangent v_tangent.xyz // unnormalized
|
||||
#define FSInput_mirrorNormal v_tangent.w
|
||||
#else
|
||||
#define FSInput_worldTangent vec3(0.0, 0.0, 0.0)
|
||||
|
||||
@@ -7,16 +7,11 @@ void main () {
|
||||
//#uniformStyle need sync here
|
||||
|
||||
// Color output
|
||||
#if CC_USE_HDR
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#elif !CC_USE_FLOAT_OUTPUT
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
#endif
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION)
|
||||
#endif
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
|
||||
fragColorX = color;
|
||||
}
|
||||
|
||||
@@ -15,20 +15,12 @@ void main() {
|
||||
vec4 color = SurfacesFragmentModifyBaseColorAndTransparency();
|
||||
color.a = 1.0;
|
||||
|
||||
#if CC_USE_HDR
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
|
||||
#endif
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION)
|
||||
#endif
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#elif !CC_USE_FLOAT_OUTPUT
|
||||
color.rgb = HDRToLDR(color.rgb);
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
fragColorX = color;
|
||||
}
|
||||
|
||||
+34
-27
@@ -41,8 +41,8 @@ void main() {
|
||||
|
||||
|
||||
// Fog factor
|
||||
float fogFactor = 1.0;
|
||||
#if !CC_FORWARD_ADD
|
||||
float fogFactor = 1.0;
|
||||
#if CC_USE_FOG != CC_FOG_NONE
|
||||
#if !CC_USE_ACCURATE_FOG
|
||||
fogFactor = FSInput_fogFactor;
|
||||
@@ -71,7 +71,10 @@ void main() {
|
||||
|
||||
#if !CC_FORWARD_ADD
|
||||
CCSurfacesDebugViewMeshData(debugColor);
|
||||
CCSurfacesDebugViewSurfaceData(debugColor, surfaceData);
|
||||
if (CCSurfacesDebugViewSurfaceData(debugColor, surfaceData))
|
||||
{
|
||||
debugColor.a = materialTransparency;
|
||||
}
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FOG))
|
||||
{
|
||||
debugColor.rgb = vec3(1.0 - fogFactor);
|
||||
@@ -81,7 +84,7 @@ void main() {
|
||||
// only base pass or direct lighting is enabled in add pass
|
||||
#if CC_FORWARD_ADD
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_ALL) ||
|
||||
IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_DIFFUSE) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_SPECULAR) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRT_DIRECT))
|
||||
IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_DIFFUSE) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_SPECULAR) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR))
|
||||
#endif
|
||||
{
|
||||
if (CCSurfacesDebugViewLightingResult(debugColor, lightingResult))
|
||||
@@ -90,12 +93,10 @@ void main() {
|
||||
debugColor.a = materialTransparency;
|
||||
|
||||
// lighting needs color space conversion
|
||||
#if CC_USE_HDR
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
|
||||
debugColor.rgb = ACESToneMap(debugColor.rgb);
|
||||
#if !CC_USE_FLOAT_OUTPUT
|
||||
debugColor.rgb = HDRToLDR(debugColor.rgb);
|
||||
debugColor.rgb = LinearToSRGB(debugColor.rgb);
|
||||
#endif
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION)
|
||||
debugColor.rgb = LinearToSRGB(debugColor.rgb);
|
||||
}
|
||||
}
|
||||
if (IS_DEBUG_VIEW_ENABLE_WITH_CAMERA) {
|
||||
@@ -123,26 +124,32 @@ void main() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Color output
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
fragColorX = packRGBE(color.rgb); // for reflection-map
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if CC_USE_HDR
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
|
||||
// Fog, linear output
|
||||
#if CC_USE_FOG != CC_FOG_NONE
|
||||
#if CC_USE_RGBE_OUTPUT || CC_USE_FLOAT_OUTPUT
|
||||
CC_APPLY_FOG_BASE(color, fogFactor);
|
||||
#endif
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION)
|
||||
#endif
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
|
||||
#if !CC_FORWARD_ADD && CC_USE_FOG != CC_FOG_NONE
|
||||
CC_APPLY_FOG_BASE(color, fogFactor);
|
||||
#endif
|
||||
|
||||
fragColorX = CCSurfacesDebugDisplayInvalidNumber(color);
|
||||
// Color output
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb); // for reflection-map
|
||||
#else
|
||||
color = CCSurfacesDebugDisplayInvalidNumber(color);
|
||||
#if !CC_USE_FLOAT_OUTPUT
|
||||
color.rgb = HDRToLDR(color.rgb);
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// todo:
|
||||
// can not perform forward-add with fog with 8888 output, and should blend with LDR gamma color, need move before color output
|
||||
#if !CC_USE_RGBE_OUTPUT && !CC_USE_FLOAT_OUTPUT && !CC_FORWARD_ADD
|
||||
#if CC_USE_FOG != CC_FOG_NONE
|
||||
CC_APPLY_FOG_BASE(color, fogFactor);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
fragColorX = color;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,12 @@ void main()
|
||||
// Other Data
|
||||
CCSurfacesVertexTransformUV(In);
|
||||
CCSurfacesVertexTransferFog(In);
|
||||
CCSurfacesVertexTransferShadow(In);
|
||||
CCSurfacesVertexTransferLightMapUV(In);
|
||||
|
||||
CCSurfacesVertexTransferShadow(In);
|
||||
#if CC_RECEIVE_SHADOW || CC_USE_REFLECTION_PROBE
|
||||
In.shadowBiasAndProbeId.xy = SurfacesVertexModifyShadowBias(In, In.shadowBiasAndProbeId.xy);
|
||||
#endif
|
||||
|
||||
CCSurfacesVertexOutput(In);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ layout(location = 0) out vec4 fragColorX;
|
||||
|
||||
void main () {
|
||||
// better performance than SurfacesFragmentModifyBaseColorAndTransparency
|
||||
#ifdef CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
SurfacesFragmentAlphaClipOnly();
|
||||
|
||||
#endif
|
||||
|
||||
highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;
|
||||
// spot use linear
|
||||
|
||||
@@ -26,10 +26,10 @@ struct SurfacesMaterialData
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE
|
||||
vec4 transmitDiffuseParams;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
vec3 baseColorTRT;
|
||||
float trtIntensity, roughnessTRT;
|
||||
vec3 worldNormalTRT, worldTangentTRT, worldBinormalTRT;
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
vec3 baseColor2ndSpecular, color2ndSpecular;
|
||||
float intensity2ndSpecular, roughness2ndSpecular;
|
||||
vec3 worldNormal2ndSpecular, worldTangent2ndSpecular, worldBinormal2ndSpecular;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
vec3 baseColorTT;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_POS
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_LOCAL_POS
|
||||
vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
return In.position.xyz;
|
||||
@@ -6,6 +7,7 @@ vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In)
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_NORMAL
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_LOCAL_NORMAL
|
||||
vec3 SurfacesVertexModifyLocalNormal(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
return In.normal.xyz;
|
||||
@@ -14,6 +16,7 @@ vec3 SurfacesVertexModifyLocalNormal(in SurfacesStandardVertexIntermediate In)
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_TANGENT
|
||||
#if CC_SURFACES_USE_TANGENT_SPACE
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_LOCAL_TANGENT
|
||||
vec4 SurfacesVertexModifyLocalTangent(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
return In.tangent;
|
||||
@@ -21,9 +24,10 @@ vec3 SurfacesVertexModifyLocalNormal(in SurfacesStandardVertexIntermediate In)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
|
||||
// some vertex datas use shared raw data, avoid sample / calculate same raw data multiply times, use this function for better performance
|
||||
// this function invokes before world transform
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
|
||||
void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
}
|
||||
@@ -31,6 +35,7 @@ void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediat
|
||||
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_WORLD_POS
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_WORLD_POS
|
||||
vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
return In.worldPos;
|
||||
@@ -38,6 +43,7 @@ vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_CLIP_POS
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_CLIP_POS
|
||||
vec4 SurfacesVertexModifyClipPos(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
return In.clipPos;
|
||||
@@ -45,6 +51,7 @@ vec4 SurfacesVertexModifyClipPos(in SurfacesStandardVertexIntermediate In)
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_UV
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_UV
|
||||
void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
// In.texCoord = In.texCoord;
|
||||
@@ -55,6 +62,7 @@ void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In)
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
vec3 worldNormal = In.worldNormal.xyz;
|
||||
@@ -65,9 +73,19 @@ vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_SHADOW_BIAS
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_SHADOW_BIAS
|
||||
// shadow bias for submesh-level
|
||||
vec2 SurfacesVertexModifyShadowBias(in SurfacesStandardVertexIntermediate In, vec2 originShadowBias)
|
||||
{
|
||||
return originShadowBias;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_SHARED_DATA
|
||||
// depends on CC_SURFACES_VERTEX_MODIFY_SHARED_DATA
|
||||
// some vertex datas use shared raw data, avoid sample / calculate same raw data multiply times, use this function for better performance
|
||||
// this function invokes at last
|
||||
#ifndef CC_SURFACES_VERTEX_MODIFY_SHARED_DATA
|
||||
void SurfacesVertexModifySharedData(inout SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
|
||||
vec4 SurfacesFragmentModifyBaseColorAndTransparency()
|
||||
{
|
||||
return FSInput_vertexColor;
|
||||
@@ -6,6 +7,7 @@ vec4 SurfacesFragmentModifyBaseColorAndTransparency()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
// depends on CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
// for base shape without color usage, such as render-to-shadow
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
@@ -14,6 +16,7 @@ void SurfacesFragmentAlphaClipOnly()
|
||||
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
return normalize(FSInput_worldNormal);
|
||||
@@ -21,9 +24,10 @@ vec3 SurfacesFragmentModifyWorldNormal()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_WORLD_TANGENT_AND_BINORMAL
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_WORLD_TANGENT_AND_BINORMAL
|
||||
void SurfacesFragmentModifyWorldTangentAndBinormal(inout vec3 worldTangent, inout vec3 worldBinormal, vec3 worldNormal)
|
||||
{
|
||||
vec3 tangent = FSInput_worldTangent;
|
||||
vec3 tangent = normalize(FSInput_worldTangent);
|
||||
|
||||
#if CC_SURFACES_USE_TANGENT_SPACE
|
||||
vec3 binormal = normalize(CalculateBinormal(worldNormal.xyz, tangent, FSInput_mirrorNormal));
|
||||
@@ -38,6 +42,7 @@ void SurfacesFragmentModifyWorldTangentAndBinormal(inout vec3 worldTangent, inou
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_IOR
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_IOR
|
||||
float SurfacesFragmentModifyIOR()
|
||||
{
|
||||
return 1.0;
|
||||
@@ -45,6 +50,7 @@ float SurfacesFragmentModifyIOR()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
|
||||
// isRotation=1.0: shape(0~1), rotation(0~2PI), 0.0, 0.0
|
||||
// or
|
||||
// isRotation=0.0: shape(0~1), anisoDir.xyz(-1~1)
|
||||
@@ -56,6 +62,7 @@ vec4 SurfacesFragmentModifyAnisotropyParams(out float isRotation)
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE
|
||||
vec3 SurfacesFragmentModifyEmissive()
|
||||
{
|
||||
return vec3(0.0, 0.0, 0.0);
|
||||
@@ -63,6 +70,7 @@ vec3 SurfacesFragmentModifyEmissive()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
|
||||
vec4 SurfacesFragmentModifyPBRParams()
|
||||
{
|
||||
// ao, roughness, metallic, specularIntensity
|
||||
@@ -71,6 +79,7 @@ vec4 SurfacesFragmentModifyPBRParams()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS
|
||||
// scattering related parameters and colors
|
||||
vec4 SurfacesFragmentModifyTransmitScatteringParams()
|
||||
{
|
||||
@@ -85,6 +94,7 @@ vec4 SurfacesFragmentModifyTransmitScatteringParams()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR
|
||||
vec3 SurfacesFragmentModifyTransmitInScatteringColor()
|
||||
{
|
||||
// added light multiplier
|
||||
@@ -92,6 +102,7 @@ vec3 SurfacesFragmentModifyTransmitInScatteringColor()
|
||||
}
|
||||
#endif
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
|
||||
vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
|
||||
{
|
||||
// transmit background multiplier
|
||||
@@ -100,6 +111,7 @@ vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_DIFFUSE_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_DIFFUSE_PARAMS
|
||||
vec4 SurfacesFragmentModifyTransmitDiffuseParams()
|
||||
{
|
||||
// this param valid only when CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT is 1
|
||||
@@ -115,6 +127,7 @@ vec4 SurfacesFragmentModifyTransmitDiffuseParams()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRT_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRT_PARAMS
|
||||
vec4 SurfacesFragmentModifyTRTParams()
|
||||
{
|
||||
//x: roughness offset
|
||||
@@ -123,7 +136,9 @@ vec4 SurfacesFragmentModifyTRTParams()
|
||||
return vec4(0.2, 0.0, 0.0, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TRT_COLOR
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TRT_COLOR
|
||||
vec3 SurfacesFragmentModifyTRTColor()
|
||||
{
|
||||
return vec3(1.0, 1.0, 1.0);
|
||||
@@ -131,6 +146,7 @@ vec3 SurfacesFragmentModifyTRTColor()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TT_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TT_PARAMS
|
||||
vec4 SurfacesFragmentModifyTTParams()
|
||||
{
|
||||
//x: scatter coef
|
||||
@@ -138,29 +154,43 @@ vec4 SurfacesFragmentModifyTTParams()
|
||||
return vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TT_COLOR
|
||||
vec3 SurfacesFragmentModifyTTColor(in vec3 baseColor, in vec3 trtColor)
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TT_COLOR
|
||||
vec3 SurfacesFragmentModifyTTColor(in vec3 baseColor)
|
||||
{
|
||||
// baseColor and trtColor for reference
|
||||
// baseColor for reference
|
||||
return vec3(1.0, 1.0, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_DUAL_LOBE_SPECULAR_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_DUAL_LOBE_SPECULAR_PARAMS
|
||||
vec4 SurfacesFragmentModifyDualLobeSpecularParams(float roughness)
|
||||
{
|
||||
//x: secondary lobe roughness, according to argument (first lobe roughness)
|
||||
//w: intensity
|
||||
return vec4(0.2, 0.0, 0.0, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_SSS_PARAMS
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_SSS_PARAMS
|
||||
vec4 SurfacesFragmentModifySSSParams()
|
||||
{
|
||||
// x: sssIntensity, moisture
|
||||
// y: sssCurvature, for preintegrated sss
|
||||
// z: sssColoration, for sss transmitted light color with dark area
|
||||
// w: cavity for specular
|
||||
return vec4(1.0, 0.1, 1.0, 1.0);
|
||||
// w: unused
|
||||
return vec4(1.0, 0.1, 1.0, 0.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
|
||||
// some material datas use shared raw data, avoid sample / calculate same raw data multiply times, use this function for better performance
|
||||
// this function invokes at last
|
||||
// should use corresponding shading-model header: #include <surfaces/data-structures/XXX> before function define
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
|
||||
void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <surfaces/default-functions/standard-fs>
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TOONSHADE
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TOONSHADE
|
||||
void SurfacesFragmentModifyBaseColorAndToonShade(out vec4 baseColorAndTransparency, out vec3 shade1, out vec3 shade2, in vec3 baseColor)
|
||||
{
|
||||
baseColorAndTransparency = FSInput_vertexColor;
|
||||
@@ -9,6 +10,7 @@ void SurfacesFragmentModifyBaseColorAndToonShade(out vec4 baseColorAndTransparen
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_STEP_AND_FEATHER
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TOON_STEP_AND_FEATHER
|
||||
vec4 SurfacesFragmentModifyToonStepAndFeather()
|
||||
{
|
||||
return vec3(0.8, 0.001, 0.5, 0.001);
|
||||
@@ -16,6 +18,7 @@ vec4 SurfacesFragmentModifyToonStepAndFeather()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_SHADOW_COVER
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TOON_SHADOW_COVER
|
||||
float SurfacesFragmentModifyToonShadowCover()
|
||||
{
|
||||
return 0.5;
|
||||
@@ -23,6 +26,7 @@ float SurfacesFragmentModifyToonShadowCover()
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_SPECULAR
|
||||
// depends on CC_SURFACES_FRAGMENT_MODIFY_TOON_SPECULAR
|
||||
vec4 SurfacesFragmentModifyToonSpecular()
|
||||
{
|
||||
return vec4(1.0, 1.0, 1.0, 0.3);
|
||||
|
||||
@@ -68,6 +68,12 @@
|
||||
#ifndef CC_SURFACES_LIGHTING_TRT
|
||||
#define CC_SURFACES_LIGHTING_TRT 0
|
||||
#endif
|
||||
#ifndef CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR
|
||||
#define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR 0
|
||||
#endif
|
||||
#ifndef CC_SURFACES_LIGHTING_CLEAR_COAT
|
||||
#define CC_SURFACES_LIGHTING_CLEAR_COAT 0
|
||||
#endif
|
||||
#ifndef CC_SURFACES_LIGHTING_TT
|
||||
#define CC_SURFACES_LIGHTING_TT 0
|
||||
#endif
|
||||
@@ -75,17 +81,22 @@
|
||||
#define CC_SURFACES_LIGHTING_SSS 0
|
||||
#endif
|
||||
|
||||
// common 2nd-specular for TRT / Dual-Lobe / Wet / ClearCoat...
|
||||
#ifndef CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
#if CC_SURFACES_LIGHTING_TRT || CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR || CC_SURFACES_LIGHTING_CLEAR_COAT
|
||||
#define CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
#define CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR 0
|
||||
#endif
|
||||
|
||||
|
||||
// render-to-color-map can disable functionality to avoid error data map
|
||||
#ifndef CC_SURFACES_ENABLE_DEBUG_VIEW
|
||||
#define CC_SURFACES_ENABLE_DEBUG_VIEW 1
|
||||
#endif
|
||||
|
||||
// for skin
|
||||
/*
|
||||
#ifndef CC_SURFACES_LIGHTING_DISABLE_DIFFUSE
|
||||
#define CC_SURFACES_LIGHTING_DISABLE_DIFFUSE 0
|
||||
#endif
|
||||
#ifndef CC_SURFACES_LIGHTING_DISABLE_SPECULAR
|
||||
#define CC_SURFACES_LIGHTING_DISABLE_SPECULAR 0
|
||||
#endif
|
||||
*/
|
||||
// for ssss skin, only can be defined in pass embedded macros
|
||||
// CC_SURFACES_LIGHTING_DISABLE_DIFFUSE / CC_SURFACES_LIGHTING_DISABLE_SPECULAR
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <common/texture/texture-lod>
|
||||
#include <common/data/packing>
|
||||
#include <common/data/unpack>
|
||||
#include <common/color/aces>
|
||||
#include <common/color/tone-mapping>
|
||||
#include <common/color/gamma>
|
||||
#include <common/math/number>
|
||||
#include <common/math/coordinates>
|
||||
|
||||
@@ -110,7 +110,7 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR))
|
||||
{
|
||||
color.rgb = lightingResult.directSpecular * lightingResult.specularColorWithLighting;
|
||||
color.rgb = lightingResult.directSpecular * lightingResult.specularColorWithEnvLighting;
|
||||
isSRGBColor = true;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR))
|
||||
{
|
||||
color.rgb = lightingResult.environmentSpecular * lightingResult.specularColorWithLighting;
|
||||
color.rgb = lightingResult.environmentSpecular * lightingResult.specularColorWithEnvLighting;
|
||||
isSRGBColor = true;
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
float fresnel = 0.0;
|
||||
vec3 directTransmitSpecular = vec3(0.0), environmentTransmitSpecular = vec3(0.0);
|
||||
vec3 directTransmitDiffuse = vec3(0.0), environmentTransmitDiffuse = vec3(0.0);
|
||||
vec3 diffuseColorWithLightingTT = vec3(0.0), specularColorWithLightingTRT = vec3(0.0);
|
||||
vec3 directTRT = vec3(0.0), environmentTRT = vec3(0.0);
|
||||
vec3 diffuseColorWithLightingTT = vec3(0.0), specularColorWithLighting2ndSpecular = vec3(0.0);
|
||||
vec3 direct2ndSpecular = vec3(0.0), environment2ndSpecular = vec3(0.0);
|
||||
#if CC_SURFACES_LIGHTING_USE_FRESNEL
|
||||
fresnel = lightingResult.fresnel;
|
||||
#endif
|
||||
@@ -178,10 +178,10 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
directTransmitDiffuse = lightingResult.directTransmitDiffuse;
|
||||
environmentTransmitDiffuse = lightingResult.environmentTransmitDiffuse;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
directTRT = lightingResult.directTRT;
|
||||
environmentTRT = lightingResult.environmentTRT;
|
||||
specularColorWithLightingTRT = lightingResult.specularColorWithLightingTRT;
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
direct2ndSpecular = lightingResult.direct2ndSpecular;
|
||||
environment2ndSpecular = lightingResult.environment2ndSpecular;
|
||||
specularColorWithLighting2ndSpecular = lightingResult.specularColorWithEnvLighting2ndSpecular;
|
||||
#endif
|
||||
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRESNEL))
|
||||
@@ -218,19 +218,19 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
isSRGBColor = true;
|
||||
}
|
||||
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRT_DIRECT))
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR))
|
||||
{
|
||||
color.rgb = directTRT * specularColorWithLightingTRT;
|
||||
color.rgb = direct2ndSpecular * specularColorWithLighting2ndSpecular;
|
||||
isSRGBColor = true;
|
||||
}
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRT_ENVIRONMENT))
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_ENVIRONMENT_2ND_SPECULAR))
|
||||
{
|
||||
color.rgb = environmentTRT * specularColorWithLightingTRT;
|
||||
color.rgb = environment2ndSpecular * specularColorWithLighting2ndSpecular;
|
||||
isSRGBColor = true;
|
||||
}
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRT_ALL))
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_2ND_SPECULAR_ALL))
|
||||
{
|
||||
color.rgb = (directTRT + environmentTRT) * specularColorWithLightingTRT;
|
||||
color.rgb = (direct2ndSpecular + environment2ndSpecular) * specularColorWithLighting2ndSpecular;
|
||||
isSRGBColor = true;
|
||||
}
|
||||
|
||||
@@ -265,9 +265,9 @@ vec4 CCSurfacesDebugDisplayInvalidInputData(vec4 color, vec3 data)
|
||||
lightingResult.directTransmitSpecular = lightingResult.environmentTransmitSpecular = vec3(0.0);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRT)
|
||||
lightingResult.directTRT = lightingResult.environmentTRT = vec3(0.0);
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_2ND_SPECULAR)
|
||||
lightingResult.direct2ndSpecular = lightingResult.environment2ndSpecular = vec3(0.0);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
|
||||
@@ -43,23 +43,36 @@ void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData)
|
||||
surfaceData.transmitDiffuseParams = SurfacesFragmentModifyTransmitDiffuseParams();
|
||||
#endif
|
||||
|
||||
vec3 baseColorTRT = vec3(0.0);
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
// skip in shader graph, need extra code
|
||||
vec4 trtParams = SurfacesFragmentModifyTRTParams();
|
||||
surfaceData.roughnessTRT = saturate(surfaceData.roughness + trtParams.x);
|
||||
surfaceData.trtIntensity = trtParams.w;
|
||||
surfaceData.baseColorTRT = baseColorTRT = SurfacesFragmentModifyTRTColor();
|
||||
surfaceData.worldNormalTRT = surfaceData.worldNormal;
|
||||
surfaceData.worldTangentTRT = surfaceData.worldTangent;
|
||||
surfaceData.worldBinormalTRT = surfaceData.worldBinormal;
|
||||
RotateNormalAndBinormal(surfaceData.worldBinormalTRT, surfaceData.worldNormalTRT, surfaceData.worldTangentTRT, trtParams.y);
|
||||
surfaceData.roughness2ndSpecular = saturate(surfaceData.roughness + trtParams.x);
|
||||
surfaceData.intensity2ndSpecular = trtParams.w;
|
||||
surfaceData.baseColor2ndSpecular = vec3(1.0); // specular color use specified trt color only
|
||||
surfaceData.color2ndSpecular = SurfacesFragmentModifyTRTColor();
|
||||
surfaceData.worldNormal2ndSpecular = surfaceData.worldNormal;
|
||||
surfaceData.worldTangent2ndSpecular = surfaceData.worldTangent;
|
||||
surfaceData.worldBinormal2ndSpecular = surfaceData.worldBinormal;
|
||||
RotateNormalAndBinormal(surfaceData.worldBinormal2ndSpecular, surfaceData.worldNormal2ndSpecular, surfaceData.worldTangent2ndSpecular, trtParams.y, FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
vec4 ttParams = SurfacesFragmentModifyTTParams();
|
||||
surfaceData.ttScatterCoef = ttParams.x;
|
||||
surfaceData.ttIntensity = ttParams.w;
|
||||
surfaceData.baseColorTT = SurfacesFragmentModifyTTColor(surfaceData.baseColor.rgb, baseColorTRT);
|
||||
surfaceData.baseColorTT = SurfacesFragmentModifyTTColor(surfaceData.baseColor.rgb);
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR
|
||||
// skip in shader graph, need extra code
|
||||
vec4 dualLobeParams = SurfacesFragmentModifyDualLobeSpecularParams(surfaceData.roughness);
|
||||
surfaceData.roughness2ndSpecular = saturate(dualLobeParams.x);
|
||||
surfaceData.intensity2ndSpecular = dualLobeParams.w;
|
||||
surfaceData.baseColor2ndSpecular = surfaceData.baseColor.rgb;
|
||||
surfaceData.color2ndSpecular = vec3(1.0); // no extra coloration
|
||||
surfaceData.worldNormal2ndSpecular = surfaceData.worldNormal;
|
||||
surfaceData.worldTangent2ndSpecular = surfaceData.worldTangent;
|
||||
surfaceData.worldBinormal2ndSpecular = surfaceData.worldBinormal;
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_SSS
|
||||
@@ -70,8 +83,8 @@ void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData)
|
||||
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP) {
|
||||
surfaceData.worldNormal = FSInput_worldNormal;
|
||||
surfaceData.worldTangent = FSInput_worldTangent;
|
||||
surfaceData.worldNormal = normalize(FSInput_worldNormal);
|
||||
surfaceData.worldTangent = normalize(FSInput_worldTangent);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -79,8 +92,8 @@ void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData)
|
||||
if (!IS_DEBUG_VIEW_LIGHTING_ENABLE_WITH_ALBEDO)
|
||||
{
|
||||
surfaceData.baseColor.rgb = vec3(1.0);
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
surfaceData.baseColorTRT.rgb = vec3(1.0);
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
surfaceData.baseColor2ndSpecular.rgb = vec3(1.0);
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
surfaceData.baseColorTT.rgb = vec3(1.0);
|
||||
@@ -101,15 +114,16 @@ vec3 CCSurfacesGetSpecularColor(in SurfacesMaterialData surfaceData)
|
||||
}
|
||||
|
||||
// Diffuse/Specular Color with BRDF lighting preparation
|
||||
void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, inout vec3 specularColorWithEnvLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
{
|
||||
diffuseColorWithLighting = CCSurfacesGetDiffuseColor(surfaceData);
|
||||
specularColorWithLighting = CCSurfacesGetSpecularColor(surfaceData).xyz;
|
||||
// (Intergrated) GF/4Pi use approximate value for both direct lighting and environment lighting
|
||||
// accuracy value can be calculated in LightingCalculateDirect/Environment instead of IntegratedGFApprox
|
||||
specularColorWithLighting = IntegratedGFApprox(CCSurfacesGetSpecularColor(surfaceData).xyz, surfaceData.roughness, lightingData.NoVAbsSat);
|
||||
specularColorWithEnvLighting = IntegratedGFApprox(specularColorWithLighting, surfaceData.roughness, lightingData.NoVAbsSat);
|
||||
}
|
||||
// Update two colors with BRDF which depend on lights (optional)
|
||||
void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, inout vec3 specularColorWithEnvLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -153,26 +167,22 @@ void CCSurfacesGetLightingIntermediateDataTransmitDiffuse(inout LightingIntermed
|
||||
lightingDataTD = lightingData;
|
||||
// view-depenedent mode make sure normal always back from view direction
|
||||
// (-N) + (-V) for smoother result
|
||||
lightingDataTD.N = lightingData.transmitScatteringParams.z > 0.0 ? -lightingData.N : -normalize(lightingData.N+lightingData.V);
|
||||
// ignore normalMap for 3S simulation
|
||||
lightingDataTD.N = lightingData.transmitScatteringParams.z > 0.0 ? -FSInput_worldNormal : -(normalize(FSInput_worldNormal)+lightingData.V);
|
||||
lightingDataTD.N = normalize(lightingDataTD.N);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
// pass original lightingData, get TRT lightingData
|
||||
void CCSurfacesGetLightingIntermediateDataTRT(inout LightingIntermediateData lightingDataTRT, in LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData)
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
// pass original surfaceData, get surfaceData for 2nd specular
|
||||
void CCSurfacesGetSurfacesMaterialData2ndSpecular(inout SurfacesMaterialData surfaceData2ndSpecular, in SurfacesMaterialData surfaceData)
|
||||
{
|
||||
lightingDataTRT = lightingData;
|
||||
lightingDataTRT.specularParam = surfaceData.roughnessTRT;
|
||||
// new TBN with anisotropic offset
|
||||
lightingDataTRT.N = surfaceData.worldNormalTRT;
|
||||
lightingDataTRT.T = surfaceData.worldTangentTRT;
|
||||
lightingDataTRT.B = surfaceData.worldBinormalTRT;
|
||||
}
|
||||
// pass original surfaceData, get TRT surfaceData
|
||||
void CCSurfacesGetSurfacesMaterialDataTRT(inout SurfacesMaterialData surfaceDataTRT, in SurfacesMaterialData surfaceData)
|
||||
{
|
||||
surfaceDataTRT = surfaceData;
|
||||
surfaceDataTRT.baseColor = vec4(surfaceData.baseColorTRT, 1.0);
|
||||
surfaceData2ndSpecular = surfaceData;
|
||||
surfaceData2ndSpecular.baseColor = vec4(surfaceData.baseColor2ndSpecular, 1.0);
|
||||
surfaceData2ndSpecular.roughness = surfaceData.roughness2ndSpecular;
|
||||
surfaceData2ndSpecular.worldNormal = surfaceData.worldNormal2ndSpecular;
|
||||
surfaceData2ndSpecular.worldTangent = surfaceData.worldTangent2ndSpecular;
|
||||
surfaceData2ndSpecular.worldBinormal = surfaceData.worldBinormal2ndSpecular;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -194,8 +204,8 @@ void CCSurfacesInitializeLightingResult(inout LightingResult lightingResult)
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE
|
||||
lightingResult.directTransmitDiffuse = vec3(0.0);
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
lightingResult.directTRT = vec3(0.0);
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
lightingResult.direct2ndSpecular = vec3(0.0);
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
lightingResult.directTT = vec3(0.0);
|
||||
@@ -214,8 +224,8 @@ void CCSurfacesAccumulateLightingResult(inout LightingResult lightingResultAccum
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE
|
||||
lightingResultAccumulated.directTransmitDiffuse += lightingResult.directTransmitDiffuse;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
lightingResultAccumulated.directTRT += lightingResult.directTRT * lightingResult.shadow;
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
lightingResultAccumulated.direct2ndSpecular += lightingResult.direct2ndSpecular * lightingResult.shadow;
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
lightingResultAccumulated.directTT += lightingResult.directTT * lightingResult.shadow;
|
||||
@@ -246,15 +256,16 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
{
|
||||
vec4 color = vec4(0.0, 0.0, 0.0, surfaceData.baseColor.a);
|
||||
|
||||
// todo: local lighting also use EnvLightingSpecularColor for estimated GF terms, calculate accurate GF instead in the future, CCSurfacesDebugViewLightingResult also needs modified
|
||||
#if CC_FORWARD_ADD
|
||||
// shadow and fresnel has already been applied with common flow
|
||||
color.xyz += lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting
|
||||
+ lightingResult.directSpecular * lightingResult.specularColorWithLighting
|
||||
+ lightingResult.directSpecular * lightingResult.specularColorWithEnvLighting
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_SPECULAR
|
||||
+ lightingResult.directTransmitSpecular * lightingResult.specularColorWithLighting
|
||||
+ lightingResult.directTransmitSpecular * lightingResult.specularColorWithEnvLighting
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
+ lightingResult.directTRT * lightingResult.specularColorWithLightingTRT * surfaceData.trtIntensity * surfaceData.baseColorTRT
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
+ lightingResult.direct2ndSpecular * lightingResult.specularColorWithEnvLighting2ndSpecular * surfaceData.color2ndSpecular
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
+ lightingResult.directTT * lightingResult.diffuseColorWithLightingTT
|
||||
@@ -273,12 +284,12 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
|
||||
color.xyz +=
|
||||
( lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting
|
||||
+ lightingResult.directSpecular * lightingResult.specularColorWithLighting * fresnel
|
||||
+ lightingResult.directSpecular * lightingResult.specularColorWithEnvLighting * fresnel
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_SPECULAR
|
||||
+ lightingResult.directTransmitSpecular * lightingResult.specularColorWithLighting * invFresnel
|
||||
+ lightingResult.directTransmitSpecular * lightingResult.specularColorWithEnvLighting * invFresnel
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
+ lightingResult.directTRT * lightingResult.specularColorWithLightingTRT * surfaceData.trtIntensity * surfaceData.baseColorTRT
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
+ lightingResult.direct2ndSpecular * lightingResult.specularColorWithEnvLighting2ndSpecular * surfaceData.color2ndSpecular
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TT
|
||||
+ lightingResult.directTT * lightingResult.diffuseColorWithLightingTT
|
||||
@@ -298,12 +309,12 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
|
||||
color.xyz +=
|
||||
( lightingResult.environmentDiffuse * lightingResult.diffuseColorWithLighting
|
||||
+ lightingResult.environmentSpecular * lightingResult.specularColorWithLighting * fresnel
|
||||
+ lightingResult.environmentSpecular * lightingResult.specularColorWithEnvLighting * fresnel
|
||||
#if CC_SURFACES_LIGHTING_TRANSMIT_SPECULAR
|
||||
+ lightingResult.environmentTransmitSpecular * lightingResult.specularColorWithLighting * invFresnel
|
||||
+ lightingResult.environmentTransmitSpecular * lightingResult.specularColorWithEnvLighting * invFresnel
|
||||
#endif
|
||||
#if CC_SURFACES_LIGHTING_TRT
|
||||
+ lightingResult.environmentTRT * lightingResult.specularColorWithLightingTRT * surfaceData.trtIntensity * surfaceData.baseColorTRT
|
||||
#if CC_SURFACES_LIGHTING_2ND_LAYER_SPECULAR
|
||||
+ lightingResult.environment2ndSpecular * lightingResult.specularColorWithEnvLighting2ndSpecular * surfaceData.color2ndSpecular
|
||||
#endif
|
||||
)
|
||||
* lightingResult.ao
|
||||
@@ -314,15 +325,16 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
|
||||
color.xyz += lightingResult.emissive;
|
||||
#endif
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
// Debug view
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE
|
||||
void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData surfaceData)
|
||||
bool CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData surfaceData)
|
||||
{
|
||||
bool enableMaterialAlpha = true;
|
||||
vec4 black = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
float scalar;
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL))
|
||||
@@ -349,6 +361,7 @@ void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData su
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSPARENCY)) {
|
||||
scalar = surfaceData.baseColor.a;
|
||||
color = vec4(scalar, scalar, scalar, 1.0);
|
||||
enableMaterialAlpha = false;
|
||||
}
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_BASE_COLOR))
|
||||
color = vec4(LinearToSRGB(surfaceData.baseColor.rgb), 1.0);
|
||||
@@ -375,6 +388,8 @@ void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData su
|
||||
scalar = surfaceData.ior - 1.0;
|
||||
color = vec4(scalar, scalar, scalar, 1.0);
|
||||
}
|
||||
|
||||
return enableMaterialAlpha;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData)
|
||||
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
|
||||
if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP)
|
||||
surfaceData.worldNormal = FSInput_worldNormal;
|
||||
surfaceData.worldNormal = normalize(FSInput_worldNormal);
|
||||
#endif
|
||||
|
||||
#if CC_USE_DEBUG_VIEW
|
||||
@@ -50,11 +50,12 @@ vec3 CCSurfacesGetSpecularColor(in SurfacesMaterialData surfaceData)
|
||||
{
|
||||
return surfaceData.specular.xyz;
|
||||
}
|
||||
void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, inout vec3 specularColorWithEnvLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
{
|
||||
specularColorWithLighting = surfaceData.specular.xyz * surfaceData.baseStep;
|
||||
diffuseColorWithLighting = vec3(0.0);
|
||||
specularColorWithEnvLighting = specularColorWithLighting = surfaceData.specular.xyz * surfaceData.baseStep;
|
||||
}
|
||||
void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, inout vec3 specularColorWithEnvLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData)
|
||||
{
|
||||
float NL = 0.5 * lightingData.NoL + 0.5;
|
||||
|
||||
@@ -139,7 +140,8 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
LightingIntermediateData lightingData;
|
||||
lightingData.NoL = -1.0;
|
||||
vec3 backLightingDiffuse, backLightingSpecular;
|
||||
CCSurfacesLightingCalculateColorWithLighting(backLightingDiffuse, backLightingSpecular, surfaceData, lightingData);
|
||||
CCSurfacesLightingInitializeColorWithLighting(backLightingDiffuse, backLightingSpecular, backLightingSpecular, surfaceData, lightingData);
|
||||
CCSurfacesLightingCalculateColorWithLighting(backLightingDiffuse, backLightingSpecular, backLightingSpecular, surfaceData, lightingData);
|
||||
|
||||
color.xyz +=
|
||||
mix(lightingResult.directDiffuse, lightingResult.lightmapColor, lightmapCoef) * mix(backLightingDiffuse, lightingResult.diffuseColorWithLighting, lightingResult.shadow)
|
||||
@@ -156,8 +158,9 @@ vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult li
|
||||
|
||||
// Debug view
|
||||
#if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE
|
||||
void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData surfaceData)
|
||||
bool CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData surfaceData)
|
||||
{
|
||||
bool enableMaterialAlpha = true;
|
||||
float scalar;
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL))
|
||||
color = vec4(surfaceData.worldNormal * 0.5 + vec3(0.5), 1.0);
|
||||
@@ -172,6 +175,7 @@ void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData su
|
||||
{
|
||||
scalar = surfaceData.baseColor.a;
|
||||
color = vec4(scalar, scalar, scalar, 1.0);
|
||||
enableMaterialAlpha = false;
|
||||
}
|
||||
|
||||
if (IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_BASE_COLOR))
|
||||
@@ -188,6 +192,8 @@ void CCSurfacesDebugViewSurfaceData(inout vec4 color, in SurfacesMaterialData su
|
||||
scalar = surfaceData.specular.a;
|
||||
color = vec4(scalar, scalar, scalar, 1.0);
|
||||
}
|
||||
|
||||
return enableMaterialAlpha;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
#include <common/graph-expression/base>
|
||||
|
||||
vec3 lerp_3Color(vec3 A, vec3 B, vec3 C, float alpha)
|
||||
{
|
||||
float alpha1 = saturate(alpha * 2.0);
|
||||
float alpha2 = saturate(alpha * 2.0 - 1.0);
|
||||
vec3 AB = lerp(A, B, alpha1);
|
||||
return lerp(AB, C, alpha2);
|
||||
}
|
||||
|
||||
vec3 GetIrisUVMask(float IrisUVRadius)
|
||||
{
|
||||
const float IrisBorderWidth = 0.04, IrisBleedWidth = 0.035, IrisMaskWidth = 0.045;
|
||||
|
||||
vec3 arg3_LimbusUVWidth = vec3(IrisBorderWidth, IrisBleedWidth, IrisMaskWidth);
|
||||
float arg8_IrisUVRadius = IrisUVRadius * 0.03 + 0.15;
|
||||
// vec3 out_IrisUVMask = Custom1(IrisUVRadius,UV,LimbusUVWidth)
|
||||
{
|
||||
float IrisUVRadiusTemp = arg8_IrisUVRadius;
|
||||
vec2 UV = FSInput_texcoord;
|
||||
vec3 LimbusUVWidth = arg3_LimbusUVWidth;
|
||||
UV = UV - vec2(0.5, 0.5);
|
||||
|
||||
vec3 r = (vec3(length(UV)) - (vec3(IrisUVRadiusTemp) - LimbusUVWidth)) / LimbusUVWidth;
|
||||
return smoothstep(0.0, 1.0, saturate(vec3(1.0) - r));
|
||||
}
|
||||
}
|
||||
|
||||
vec2 GetIrisUV(vec2 refractedUV, float IrisUVRadius, float PupilScale)
|
||||
{
|
||||
// code between Refract->Parallax, for control pupil size
|
||||
const float PupilShiftX = 0.0, PupilShiftY = 0.0, ScaleIrisWithinMask = 1.0;
|
||||
|
||||
float uvRadius = (IrisUVRadius*0.03+0.15) * 2.0;
|
||||
vec2 UV1 = refractedUV - vec2(0.5);
|
||||
vec2 UV =(UV1 / uvRadius) + vec2(0.5);
|
||||
|
||||
vec2 UVscaled;// = ScalePupils(UV,PupilScale1,PupilShiftX1,PupilShiftY1)
|
||||
{
|
||||
float ShiftMask = pow(saturate(-4.0 * (distance(vec2(0.5), UV) - 0.45)),0.7);
|
||||
vec2 UVshifted = UV + vec2(PupilShiftX * (ShiftMask * -0.1), PupilShiftY * (ShiftMask * 0.1));
|
||||
vec2 UVcentered = UVshifted - vec2(0.5, 0.5);
|
||||
float UVlength = length(UVcentered);
|
||||
// UV on circle at distance 0.5 from the center, in direction of original UV
|
||||
vec2 UVmax = normalize(UVcentered) * 0.5;
|
||||
UVscaled = lerp(UVmax, vec2(0.0, 0.0), saturate((1.0 - UVlength * 2.0) * PupilScale)) + vec2(0.5, 0.5);
|
||||
}
|
||||
float TextureScale = ScaleIrisWithinMask;
|
||||
vec2 UVs_out;// = ScaleUVsByCenter(UVscaled,TextureScale)
|
||||
{
|
||||
UVs_out = (UVscaled - vec2(0.5)) * TextureScale + vec2(0.5);
|
||||
}
|
||||
|
||||
return UVs_out;
|
||||
}
|
||||
|
||||
vec3 GetGeneratedColorForIris(vec2 irisUV, sampler2D irisColorMap, float IrisColor1U, float IrisColor2U, float IrisColor1Bright, float IrisColor2Bright)
|
||||
{
|
||||
//MF_irisGenerator
|
||||
// custom pupil spherical scaling, should after refraction
|
||||
/* vec2 centeredUV = (irisUV - vec2(0.5)) * 2.0;
|
||||
float lengthUV = length(centeredUV);
|
||||
vec2 dirUV = normalize(centeredUV);
|
||||
irisUV = pow(lengthUV, pupilScale) * dirUV * 0.5 + vec2(0.5);
|
||||
*/
|
||||
const float IrisColor1V = 0.3, IrisColor2V = 0.3, IrisColorValueVariation = 0.25, IrisColorHueVariation = 0.1;
|
||||
const float IrisColorBalance = 0.5, IrisColorBalanceSmoothness = 0.5, IrisSaturationVariation = 0.25;
|
||||
const float RadialStructuralBlendSwitch = 0.0, LimbusDarkAmount = 0.5, AOinIris = 0.7;
|
||||
|
||||
vec4 M_Tex = texture(irisColorMap/*T_Iris_A_M*/, irisUV);
|
||||
|
||||
vec2 uv1 = vec2(IrisColor2U - IrisColorHueVariation, IrisColor2V + IrisColorValueVariation);
|
||||
vec2 uv2 = vec2(IrisColor2U + IrisColorHueVariation, IrisColor2V - IrisColorHueVariation);
|
||||
vec2 uv3 = vec2(IrisColor1U - IrisColorHueVariation, IrisColor1V + IrisColorValueVariation);
|
||||
vec2 uv4 = vec2(IrisColor1U + IrisColorHueVariation, IrisColor1V - IrisColorValueVariation);
|
||||
vec3 col2 = SRGBToLinear(texture(irisGradientMap, vec2(IrisColor2U, IrisColor2V)).rgb) * IrisColor2Bright;
|
||||
vec3 col2_hue1 = SRGBToLinear(texture(irisGradientMap, uv1).rgb) * IrisColor2Bright;
|
||||
vec3 col2_hue2 = SRGBToLinear(texture(irisGradientMap, uv2).rgb) * IrisColor2Bright;
|
||||
vec3 col1 = SRGBToLinear(texture(irisGradientMap, vec2(IrisColor1U, IrisColor1V)).rgb) * IrisColor1Bright;
|
||||
vec3 col1_hue1 = SRGBToLinear(texture(irisGradientMap, uv3).rgb) * IrisColor1Bright;
|
||||
vec3 col1_hue2 = SRGBToLinear(texture(irisGradientMap, uv4).rgb) * IrisColor1Bright;
|
||||
|
||||
float minValue = IrisColorBalance - IrisColorBalanceSmoothness;
|
||||
float maxValue = IrisColorBalance + IrisColorBalanceSmoothness;
|
||||
vec2 invMaskRB = vec2(1.0) - M_Tex.rb;
|
||||
vec2 alphaRB = smoothstep(minValue, maxValue, invMaskRB);
|
||||
float Fraction = lerp(-1.0, 1.0, M_Tex.r) * IrisSaturationVariation;
|
||||
vec3 desat_col1 = Desaturation(lerp_3Color(col1_hue2, col1, col1_hue1, M_Tex.r), Fraction);
|
||||
vec3 desat_col2 = Desaturation(lerp_3Color(col2_hue2, col2, col2_hue1, M_Tex.r), Fraction);
|
||||
vec3 b = lerp(desat_col2, desat_col1, alphaRB.x);
|
||||
vec3 a = lerp(desat_col2, desat_col1, alphaRB.y);
|
||||
vec3 lerpedColor = lerp(a, b, RadialStructuralBlendSwitch) * M_Tex.a;
|
||||
vec3 base = lerpedColor * lerp(1.0, M_Tex.g, AOinIris);
|
||||
|
||||
float radius = distance(irisUV - vec2(0.5), vec2(0.0));
|
||||
float alpha = smoothstep(0.275, 0.5, radius);
|
||||
return lerp(base, pow(base, vec3(LimbusDarkAmount + 1.0)), alpha);
|
||||
}
|
||||
|
||||
vec3 GetBlendColorForIrisAndSclera(vec3 irisUVMask, vec3 irisGeneratedColor, sampler2D irisHeightMapAlpha, sampler2D scleraDiffuse, sampler2D T_Veins_D, vec3 scleraTintColor, float VeinsPower, float scleraBright)
|
||||
{
|
||||
const float ScleraCornerDarkRadius = 0.6, ScleraCornerDarkHardness = 0.4, ScleraBrightness = 0.5, ScleraPower = 1.0, ScleraTintU = 0.2, ScleraTintV = 0.2, ScleraRotate = 0.0;
|
||||
const float VeinsRotate = 0.0, IrisBrightness = 1.0, IrisSaturation = 0.5, CloudyIrisRadius = 0.13, CloudyIrisHardness = 0.0;
|
||||
const vec4 ScleraCornerDarkColor = vec4(0.745,0.213,0.237,1), IrisBleedTint = vec4(1.0,1.0,1.0,1.0), CloudyIrisColor = vec4(0.009684,0.011247,0.015625,1.0);
|
||||
|
||||
float heightAlpha = texture(irisHeightMapAlpha, FSInput_texcoord).r;
|
||||
vec2 scleraUV = Rotator(FSInput_texcoord, vec2(0.5,0.5), heightAlpha * ScleraRotate, 6.283);
|
||||
vec2 veinsUV = Rotator(FSInput_texcoord, vec2(0.5,0.5), heightAlpha * VeinsRotate, 6.283);
|
||||
vec3 scleraTexColor = SRGBToLinear(texture(/*T_Sclera_D*/scleraDiffuse, scleraUV).rgb) * scleraBright;
|
||||
vec3 veinsTexColor = SRGBToLinear(texture(T_Veins_D, veinsUV).rgb) * scleraBright;
|
||||
// use fixed color for optimizing, scleraTintColor = texture(T_sclera_tint_picker, vec2(ScleraTintU,ScleraTintV)).rgb;
|
||||
vec3 scleraColor = pow(scleraTexColor, vec3(ScleraPower))*ScleraBrightness*1.1 + vec3(0.8);
|
||||
scleraColor *= scleraTintColor;
|
||||
vec3 bleededScleraColor = lerp(scleraColor, IrisBleedTint.rgb * scleraColor, irisUVMask.g);
|
||||
vec3 veinsColor = pow(veinsTexColor, vec3(VeinsPower));
|
||||
vec3 ScleraColor = bleededScleraColor * veinsColor;
|
||||
|
||||
vec3 irisColor = Desaturation(irisGeneratedColor * IrisBrightness, (IrisSaturation - 0.5) * -2.0);
|
||||
vec3 lerpedScleraAndIris = lerp(ScleraColor, irisColor, irisUVMask.r);
|
||||
vec3 cloudyPupilAddColor = SphereMask(FSInput_texcoord, vec2(0.5), CloudyIrisRadius, CloudyIrisHardness) * CloudyIrisColor.rgb;
|
||||
|
||||
float scleraCornerDarkMask = SphereMask(FSInput_texcoord, vec2(0.5), ScleraCornerDarkRadius, ScleraCornerDarkHardness);
|
||||
vec3 ScleraCorner = lerp(ScleraCornerDarkColor.rgb, vec3(1.0), scleraCornerDarkMask);
|
||||
vec3 BaseColor = ScleraCorner * (cloudyPupilAddColor + lerpedScleraAndIris);
|
||||
return BaseColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// unused
|
||||
// out_RefractedUV = GetRefractedUV(out_IrisUVMask, irisHeightMap, irisNormalMap, viewDir, IrisUVRadius, CONREAL_IOR);
|
||||
vec2 GetRefractedUV(vec3 irisUVMask, sampler2D irisHeightMap, sampler2D T_Eye_N, vec3 viewDir, float IrisUVRadius, float internalIoR)
|
||||
{
|
||||
const float RefractionDepthScale = 1.2;
|
||||
vec3 normalW = normalize(FSInput_worldNormal), cameraW = viewDir;
|
||||
vec3 RefractionDirection;
|
||||
// RefractionDirection = custom2(internalloR,normalW,cameraW)
|
||||
{
|
||||
float n = internalIoR;
|
||||
float facing = dot(normalW, cameraW);
|
||||
float w = n * facing;
|
||||
float k = sqrt(1.0+(w-n)*(w+n));
|
||||
vec3 t;
|
||||
t = (w - k)*normalW - n*cameraW;
|
||||
t = normalize(t);
|
||||
RefractionDirection = -t;
|
||||
}
|
||||
float arg8_IrisUVRadius = IrisUVRadius * 0.03 + 0.15;
|
||||
vec2 arg2_UV = FSInput_texcoord;
|
||||
float arg4_DepthScale = RefractionDepthScale;
|
||||
float arg5_DepthPlaneOffset = SampleTextureExr(irisHeightMap, vec2(arg8_IrisUVRadius + 0.5, 0.5)).r;
|
||||
vec3 arg6_MidPlaneDisplacement = SampleTextureExr(irisHeightMap, FSInput_texcoord).rgb;
|
||||
vec3 arg7_EyeDirectionWorld = TransformNormalMap(texture(T_Eye_N, FSInput_texcoord).rgb);
|
||||
vec3 a5 = max(arg6_MidPlaneDisplacement - arg5_DepthPlaneOffset, vec3(0.0)) * arg4_DepthScale;
|
||||
float b5 = lerp(0.325, 1.0, dot(cameraW,arg7_EyeDirectionWorld) * dot(cameraW,arg7_EyeDirectionWorld));
|
||||
vec3 heightW = a5 / b5;
|
||||
vec3 b3 = RefractionDirection*heightW;
|
||||
vec3 tangent = normalize(FSInput_worldTangent);
|
||||
vec3 a3 = normalize(tangent - dot(tangent, arg7_EyeDirectionWorld) * arg7_EyeDirectionWorld);
|
||||
vec3 a4 = cross(a3,arg7_EyeDirectionWorld);
|
||||
vec3 b4 = b3;
|
||||
vec2 b2 = vec2(dot(a3,b3),dot(a4,b4));
|
||||
// float VectorLength = distance(vec2(0.0), vec2(arg8_IrisUVRadius*vec2(-1.0,1.0)*b2));
|
||||
// float out_Transparency = VectorLength - arg8_IrisUVRadius;
|
||||
vec2 a1 = arg2_UV;
|
||||
vec2 b1 = vec2(arg8_IrisUVRadius) * vec2(-1.0,1.0)*b2 + arg2_UV;
|
||||
float alpha1 = irisUVMask.r;
|
||||
return lerp(a1,b1,alpha1);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "bce797be-05d4-400e-8eb8-f2816147b869",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
CCEffect %{
|
||||
techniques:
|
||||
- name: opaque
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
frag: standard-fs
|
||||
properties: &props
|
||||
occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
roughness: { value: 0.07, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
metallic: { value: 0.0, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
specularIntensity: { value: 1.0, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: ScleraColorMap, tooltip: 'T_Sclera_D' } }
|
||||
normalMap: { value: normal, editor: { displayName: ScleraNormalMap, tooltip: 'T_Sclera_N' } }
|
||||
occlusionMap: { value: white }
|
||||
irisGradientMap: { value: white, editor: { tooltip: 'T_Eye_Gradient' } }
|
||||
irisColorMaskMap: { value: black, editor: { tooltip: 'T_Iris_A_M' } }
|
||||
veinsColorMap: { value: black, editor: { tooltip: 'T_Veins_D' } }
|
||||
irisNormalMap: { value: normal, editor: { parent: USE_IRIS_REFRACTION, tooltip: 'normalMap with conreal shape like T_Eye_N' } }
|
||||
irisHeightMap: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement' } }
|
||||
irisHeightMapAlpha: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement Alpha Channel' } }
|
||||
irisHeightScale: { value: 1.0, target: irisParams.x, editor: { parent: USE_IRIS_REFRACTION, slide: true, range: [0, 5.0], step: 0.001 } }
|
||||
irisScale: { value: 0.5, target: irisParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
pupilScale: { value: 1.0, target: irisParams.w, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
|
||||
veinsBleeding: { value: 1.5, target: irisParams.y, editor: { slide: true, range: [0.0, 3.0], step: 0.001 } }
|
||||
irisMainColor: { value: 0.8, target: irisColorParams.x, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
irisMainBright: { value: 1.0, target: irisColorParams.y, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
|
||||
irisEdgeColor: { value: 0.5, target: irisColorParams.z, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
irisEdgeBright: { value: 1.0, target: irisColorParams.w, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
|
||||
reflectionEnhancement: { value: 1.5, target: emissiveScaleParam.x, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
|
||||
scleraBright: { value: 1.0, target: emissiveScaleParam.y, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
causticsPosition: { value: 0.3, target: causticsParams.x, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
causticsWidth: { value: 0.3, target: causticsParams.y, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
causticsIntensity: { value: 1.0, target: causticsParams.w, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 3.0], step: 0.001 } }
|
||||
- &forward-add
|
||||
vert: standard-vs
|
||||
frag: standard-fs
|
||||
phase: forward-add
|
||||
propertyIndex: 0
|
||||
embeddedMacros: { CC_FORWARD_ADD: true }
|
||||
depthStencilState:
|
||||
depthFunc: equal
|
||||
depthTest: true
|
||||
depthWrite: false
|
||||
blendState:
|
||||
targets:
|
||||
- blend: true
|
||||
blendSrc: one
|
||||
blendDst: one
|
||||
blendSrcAlpha: zero
|
||||
blendDstAlpha: one
|
||||
- &shadow-caster
|
||||
vert: shadow-caster-vs
|
||||
frag: shadow-caster-fs
|
||||
phase: shadow-caster
|
||||
propertyIndex: 0
|
||||
rasterizerState:
|
||||
cullMode: front
|
||||
properties:
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
- &reflect-map
|
||||
vert: standard-vs
|
||||
frag: reflect-map-fs
|
||||
phase: reflect-map
|
||||
propertyIndex: 0
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
frag: standard-fs
|
||||
embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
|
||||
depthStencilState:
|
||||
depthTest: true
|
||||
depthWrite: false
|
||||
blendState:
|
||||
targets:
|
||||
- blend: true
|
||||
blendSrc: src_alpha
|
||||
blendDst: one_minus_src_alpha
|
||||
blendDstAlpha: one_minus_src_alpha
|
||||
properties: *props
|
||||
- *forward-add
|
||||
- *shadow-caster
|
||||
}%
|
||||
|
||||
CCProgram shared-ubos %{
|
||||
uniform Constants {
|
||||
vec4 pbrParams;
|
||||
vec4 emissiveScaleParam;
|
||||
vec4 irisParams;
|
||||
vec4 irisColorParams;
|
||||
vec4 causticsParams;
|
||||
};
|
||||
}%
|
||||
|
||||
CCProgram macro-remapping %{
|
||||
// depend on UI macros
|
||||
#if USE_NORMAL_MAP
|
||||
#define CC_SURFACES_USE_TANGENT_SPACE 1
|
||||
#endif
|
||||
}%
|
||||
|
||||
CCProgram surface-vertex %{
|
||||
out vec4 v_planeN;
|
||||
out vec4 v_planeT;
|
||||
|
||||
#define CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
|
||||
void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
mat4 matWorld, matWorldIT;
|
||||
CCGetWorldMatrixFull(matWorld, matWorldIT);
|
||||
|
||||
v_planeN.xyz = normalize((matWorldIT * vec4(0.0, 0.0, 1.0, 0.0)).xyz); // meta human exported mesh is facing to Z-Axis
|
||||
v_planeT.xyz = normalize((matWorldIT * vec4(1.0, 0.0, 0.0, 0.0)).xyz);
|
||||
v_planeN.w = v_planeT.w = 1.0;
|
||||
}
|
||||
}%
|
||||
|
||||
CCProgram surface-fragment %{
|
||||
uniform sampler2D albedoMap;
|
||||
#if USE_NORMAL_MAP
|
||||
uniform sampler2D normalMap;
|
||||
#endif
|
||||
#if USE_OCCLUSION_MAP
|
||||
uniform sampler2D occlusionMap;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////User Define
|
||||
in vec4 v_planeN;
|
||||
in vec4 v_planeT;
|
||||
#if USE_IRIS_REFRACTION
|
||||
uniform sampler2D irisNormalMap;
|
||||
#endif
|
||||
uniform sampler2D irisHeightMap;
|
||||
uniform sampler2D irisHeightMapAlpha;
|
||||
uniform sampler2D irisColorMaskMap;
|
||||
uniform sampler2D irisGradientMap;
|
||||
uniform sampler2D veinsColorMap;
|
||||
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
|
||||
vec4 SurfacesFragmentModifyPBRParams()
|
||||
{
|
||||
vec4 pbr = pbrParams;
|
||||
pbr.x = 1.0;
|
||||
#if USE_OCCLUSION_MAP
|
||||
pbr.x = mix(1.0, texture(occlusionMap, FSInput_texcoord).r, pbrParams.x);
|
||||
#endif
|
||||
|
||||
return pbr;
|
||||
}
|
||||
|
||||
|
||||
#include <common/texture/texture-misc>
|
||||
#include <common/lighting/functions>
|
||||
#include <eye>
|
||||
|
||||
#define CONREAL_IOR 1.336
|
||||
vec2 GetEllipseRefractionOffset(vec3 planeN, vec3 planeT, vec3 planeB, vec3 conrealNormal, vec3 refractDir, float height)
|
||||
{
|
||||
float NoR = dot(conrealNormal, -refractDir);
|
||||
float lenR = height / max(NoR, EPSILON_LOWP);
|
||||
vec3 refract = refractDir * lenR;
|
||||
// project R onto plane UV space, -B for Y -> V dir correction
|
||||
return vec2(dot(refract, planeT), dot(refract, -planeB));
|
||||
}
|
||||
|
||||
|
||||
// definition of SurfacesMaterialData structure with corresponding shading-model
|
||||
#include <surfaces/data-structures/standard>
|
||||
|
||||
//see <surfaces/default-functions/XXXX> for more overrided functions, XXXX is shading-model name
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
|
||||
void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData)
|
||||
{
|
||||
vec3 worldPos;
|
||||
HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
|
||||
|
||||
float irisHeightScale = irisParams.x;
|
||||
float IrisUVRadius = irisParams.z * 2.0; // default is 0.5
|
||||
float PupilScale = irisParams.w;
|
||||
float VeinsPower = irisParams.y;
|
||||
float IrisColor1U = irisColorParams.x; // default is 0.8 for asian
|
||||
float IrisColor2U = irisColorParams.z; // default is 0.5 for asian
|
||||
float IrisColor1Bright = irisColorParams.y;
|
||||
float IrisColor2Bright = irisColorParams.w;
|
||||
float scleraBright = emissiveScaleParam.y;
|
||||
vec3 scleraTintColor = vec3(1.0);
|
||||
|
||||
vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
|
||||
|
||||
// vec2 irisUV = (FSInput_texcoord - vec2(0.5)) / IrisScale + vec2(0.5);
|
||||
// if (irisUV.x > 0.0 && irisUV.y > 0.0 && irisUV.x < 1.0 && irisUV.y < 1.0)
|
||||
|
||||
// Iris Mask with Limbus Ring falloff
|
||||
vec3 out_IrisUVMask = GetIrisUVMask(IrisUVRadius);
|
||||
|
||||
// Refraction
|
||||
vec2 out_RefractedUV = FSInput_texcoord;
|
||||
#if USE_IRIS_REFRACTION
|
||||
float texHeight = SampleTextureExr(irisHeightMap, FSInput_texcoord).x;
|
||||
float height = texHeight * irisHeightScale;
|
||||
|
||||
vec3 irisN = normalize(FSInput_worldNormal);
|
||||
vec3 R = CalculateRefractDirection(irisN, viewDir, dot(irisN, viewDir), CONREAL_IOR);
|
||||
|
||||
vec3 receivePlaneN = v_planeN.xyz;
|
||||
vec3 receivePlaneT = v_planeT.xyz;
|
||||
vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
|
||||
|
||||
vec2 uv_offset = GetEllipseRefractionOffset(receivePlaneN, receivePlaneT, receivePlaneB, irisN, normalize(R), height);
|
||||
out_RefractedUV = saturate(FSInput_texcoord + uv_offset /** texHeight*/ * 0.1); //需要边缘位移稍微小一点的话就加texHeight
|
||||
#endif
|
||||
|
||||
// scaling pupil
|
||||
vec2 out_IrisUV = GetIrisUV(out_RefractedUV, IrisUVRadius, PupilScale);
|
||||
|
||||
// generating iris color
|
||||
vec3 out_IrisGeneratedColor = GetGeneratedColorForIris(out_IrisUV, irisColorMaskMap, IrisColor1U, IrisColor2U, IrisColor1Bright, IrisColor2Bright);
|
||||
|
||||
// blend iris and sclera use IrisMask
|
||||
surfaceData.baseColor.rgb = GetBlendColorForIrisAndSclera(out_IrisUVMask, out_IrisGeneratedColor, irisHeightMapAlpha, albedoMap, veinsColorMap, scleraTintColor, VeinsPower, scleraBright);
|
||||
|
||||
// flatterned normal for iris area
|
||||
surfaceData.worldNormal = normalize(lerp(surfaceData.worldNormal, FSInput_worldNormal, out_IrisUVMask.r));
|
||||
|
||||
// iris area flag (UVMask) and attenuation for caustics
|
||||
// irisUVMask area is a little bit larger than irisGeneratedColor
|
||||
float irisAttenuation = saturate(out_IrisUVMask.r * length(out_IrisGeneratedColor) * 10.0);
|
||||
surfaceData.ior = irisAttenuation;
|
||||
surfaceData.emissive = out_IrisUVMask;
|
||||
}
|
||||
|
||||
// see <lighting-models/default-functions/XXXX> for more overrided functions, XXXX is lighting-model name
|
||||
#include <lighting-models/includes/standard>
|
||||
#define CC_SURFACES_LIGHTING_MODIFY_FINAL_RESULT
|
||||
void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, in LightingMiscData miscData)
|
||||
{
|
||||
#if USE_IRIS_REFRACTION
|
||||
vec3 worldPos;
|
||||
HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
|
||||
|
||||
vec3 L = lightingData.L;
|
||||
vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
|
||||
|
||||
LightingIntermediateData lightingDataRefract = lightingData;
|
||||
vec3 newL = -CalculateRefractDirection(surfaceData.worldNormal, L, dot(surfaceData.worldNormal, L), CONREAL_IOR);
|
||||
CCSurfacesLightingGetIntermediateData_PerLight(lightingDataRefract, newL);
|
||||
if (surfaceData.emissive.x > 0.0) {
|
||||
result.directSpecular = CalculateDirectSpecular(lightingDataRefract, miscData.lightColorAndIntensity);
|
||||
|
||||
#if !CC_FORWARD_ADD
|
||||
lightingDataRefract.V = -CalculateRefractDirection(surfaceData.worldNormal, viewDir, dot(surfaceData.worldNormal, viewDir), CONREAL_IOR);
|
||||
result.environmentSpecular = CalculateEnvironmentSpecular(lightingDataRefract, cc_ambientSky.w);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// enhanced more contrast for brighter part
|
||||
result.environmentSpecular = pow(result.environmentSpecular, vec3(emissiveScaleParam.x));
|
||||
|
||||
|
||||
#if USE_SCLERA_SSS
|
||||
LightingIntermediateData lightingData3S = lightingData;
|
||||
lightingData3S.N = normalize(FSInput_worldNormal);
|
||||
CCSurfacesLightingGetIntermediateData_PerLight(lightingData3S, lightingData.L);
|
||||
result.directDiffuse = CalculateDirectDiffuse(lightingData3S, miscData.lightColorAndIntensity);
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_IRIS_CAUSTICS
|
||||
vec3 receivePlaneN = v_planeN.xyz;
|
||||
vec3 receivePlaneT = v_planeT.xyz;
|
||||
vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
|
||||
|
||||
// conreal back face normal has inverse projector dir with plane T B
|
||||
float projectorN = dot(surfaceData.worldNormal, receivePlaneN);
|
||||
float projectorT = dot(surfaceData.worldNormal, receivePlaneT);
|
||||
float projectorB = dot(surfaceData.worldNormal, receivePlaneB);
|
||||
vec3 backN = normalize(projectorN * receivePlaneN - projectorT * receivePlaneT - projectorB * receivePlaneB);
|
||||
|
||||
LightingIntermediateData lightingDataCaustics = lightingData;
|
||||
lightingDataCaustics.N = backN;
|
||||
CCSurfacesLightingGetIntermediateData_PerLight(lightingDataCaustics, lightingData.L);
|
||||
|
||||
float causticsIntensity = causticsParams.w;
|
||||
|
||||
float irisMaskAttenuation = surfaceData.ior;
|
||||
#if USE_IRIS_CAUSTICS_RANGE
|
||||
// rangeFilter results according to UV distribution, 5.0 can be modified to match different UVs
|
||||
float uvLength = saturate(length(FSInput_texcoord - vec2(0.5)) * 5.0);
|
||||
float start = causticsParams.x, end = saturate(start + causticsParams.y), widthAtten = 0.2;
|
||||
float rangeFilter = saturate(smoothstep(start, end, uvLength)) * (1.0 - saturate(smoothstep(end, saturate(end + widthAtten), uvLength)));
|
||||
// rangeFilter can be ignored
|
||||
irisMaskAttenuation *= rangeFilter;
|
||||
#endif
|
||||
|
||||
vec3 directCaustics = vec3(pow(lightingDataCaustics.NoLSat, 10.0)) * 2.0;
|
||||
result.directDiffuse += directCaustics * causticsIntensity * irisMaskAttenuation * miscData.lightColorAndIntensity.rgb * miscData.lightColorAndIntensity.w;
|
||||
#if !CC_FORWARD_ADD
|
||||
vec3 envCaustics = CalculateEnvironmentDiffuse(lightingDataCaustics, 1.0);
|
||||
envCaustics = pow(envCaustics, vec3(4.0)) * 0.5;
|
||||
result.environmentDiffuse += envCaustics * causticsIntensity * irisMaskAttenuation * cc_ambientSky.w;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// restore emissive
|
||||
result.emissive = vec3(0.0);
|
||||
}
|
||||
}%
|
||||
|
||||
CCProgram standard-vs %{
|
||||
precision highp float;
|
||||
|
||||
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
|
||||
#include <macro-remapping>
|
||||
#include <surfaces/effect-macros/common-macros>
|
||||
|
||||
// 2. common include with corresponding shader stage, include before surface functions
|
||||
#include <surfaces/includes/common-vs>
|
||||
|
||||
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
|
||||
// see surfaces/default-functions/xxx.chunk
|
||||
#include <shared-ubos>
|
||||
#include <surface-vertex>
|
||||
|
||||
// 4. surface include with corresponding shader stage and shading-model (optional)
|
||||
#include <surfaces/includes/standard-vs>
|
||||
|
||||
// 5. shader entry with corresponding shader stage and technique usage/type
|
||||
#include <shading-entries/main-functions/render-to-scene/vs>
|
||||
}%
|
||||
|
||||
|
||||
CCProgram shadow-caster-vs %{
|
||||
precision highp float;
|
||||
#include <surfaces/effect-macros/render-to-shadowmap>
|
||||
#include <surfaces/includes/common-vs>
|
||||
#include <shared-ubos>
|
||||
#include <surface-vertex>
|
||||
#include <shading-entries/main-functions/render-to-shadowmap/vs>
|
||||
}%
|
||||
|
||||
|
||||
|
||||
CCProgram standard-fs %{
|
||||
// shading-model : standard
|
||||
// lighting-model : standard (isotropy / anisotropy pbr)
|
||||
// shader stage : fs
|
||||
// technique usage/type : render-to-scene
|
||||
|
||||
precision highp float;
|
||||
// 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
|
||||
#include <macro-remapping>
|
||||
#include <surfaces/effect-macros/common-macros>
|
||||
|
||||
// 2. common include with corresponding shader stage, include before surface functions
|
||||
#include <surfaces/includes/common-fs>
|
||||
|
||||
// 3. user surface functions that can use user (effect) parameters (ubo Constants)
|
||||
// see surfaces/default-functions/xxx.chunk
|
||||
#include <shared-ubos>
|
||||
#include <surface-fragment>
|
||||
|
||||
// 4. lighting-model (optional)
|
||||
#include <lighting-models/includes/standard>
|
||||
|
||||
// 5. surface include with corresponding shader stage and shading-model (optional)
|
||||
#include <surfaces/includes/standard-fs>
|
||||
|
||||
// 6. shader entry with corresponding shader stage and technique usage/type
|
||||
#include <shading-entries/main-functions/render-to-scene/fs>
|
||||
}%
|
||||
|
||||
CCProgram shadow-caster-fs %{
|
||||
precision highp float;
|
||||
#include <surfaces/effect-macros/render-to-shadowmap>
|
||||
#include <surfaces/includes/common-fs>
|
||||
#include <shared-ubos>
|
||||
#include <surface-fragment>
|
||||
#include <shading-entries/main-functions/render-to-shadowmap/fs>
|
||||
}%
|
||||
|
||||
|
||||
CCProgram reflect-map-fs %{
|
||||
precision highp float;
|
||||
#include <macro-remapping>
|
||||
#include <surfaces/effect-macros/common-macros>
|
||||
#include <surfaces/includes/common-fs>
|
||||
#include <shared-ubos>
|
||||
#include <surface-fragment>
|
||||
#include <lighting-models/includes/standard>
|
||||
#include <surfaces/includes/standard-fs>
|
||||
#include <shading-entries/main-functions/render-to-reflectmap/fs>
|
||||
}%
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.7.0",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "f0475923-826e-45dc-85cc-b5d9c2b220e9",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ CCEffect %{
|
||||
anisotropyIntensity: { value: 1.0, target: anisotropyParam.x, editor: { slide : true, range : [0.0, 1.0] , step : 0.0001 } }
|
||||
anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { slide : true, range : [0, 1.0] , step : 0.0001 } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: AlbedoMap } }
|
||||
transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: TransparencyMap } }
|
||||
normalMap: { value: normal }
|
||||
pbrMap: { value: grey }
|
||||
occlusionMap: { value: white }
|
||||
@@ -34,9 +34,10 @@ CCEffect %{
|
||||
ScatterCoefTT: { value: 0.0, target: ttParams.x, editor: { displayName: TT Scatter Coef, slide: true, range: [0, 1.0], step: 0.01, tooltip: 'The saturation of internal transmit lighting color' } }
|
||||
IntensityTT: { value: 1.0, target: ttParams.w, editor: { displayName: TT Intensity, slide: true, range: [0, 1.0], step: 0.01 } }
|
||||
baseColorTT: { value: [0.5, 0.33, 0.18, 1.0], target: ttColor, linear: true, editor: { displayName: TT Albedo, type: color, tooltip: 'The color of internal transmit lighting, allow the light color to vary between backlit and light-facing areas' } }
|
||||
thickness: { value: 1.0, target: ttParams.y, editor: { displayName: Scatter Thickness, slide: true, range: [0, 1.0], step: 0.001, tooltip: 'The extend range of internal reflection lighting around the direct specular' } }
|
||||
extinction: { value: 0.0, target: ttParams.z, editor: { displayName: Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001, tooltip: 'The position offset of internal reflection lighting compared to direct specular' } }
|
||||
depthMap: { value: white }
|
||||
thickness: { value: 1.0, target: ttParams.y, editor: { parent: USE_BACK_LIT, displayName: Scatter Thickness, slide: true, range: [0, 1.0], step: 0.001, tooltip: 'The extend range of internal reflection lighting around the direct specular' } }
|
||||
extinction: { value: 0.0, target: ttParams.z, editor: { parent: USE_BACK_LIT, displayName: Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001, tooltip: 'The position offset of internal reflection lighting compared to direct specular' } }
|
||||
transmitColor: { value: [0.7, 0.5, 0.3, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting' } }
|
||||
thicknessMap: { value: white, editor: { parent: USE_BACK_LIT } }
|
||||
selfShadowMap: { value: white, editor: { parent: USE_SELF_SHADOW_MAP } }
|
||||
rasterizerState:
|
||||
cullMode: None
|
||||
@@ -149,7 +150,7 @@ CCEffect %{
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: AlbedoMap } }
|
||||
transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: TransparencyMap } }
|
||||
- &reflect-map
|
||||
vert: standard-vs
|
||||
frag: reflect-map-fs
|
||||
@@ -187,6 +188,7 @@ CCProgram shared-ubos %{
|
||||
vec4 trtParams;
|
||||
vec4 ttColor;
|
||||
vec4 ttParams;
|
||||
vec4 transmitColor;
|
||||
};
|
||||
}%
|
||||
|
||||
@@ -197,15 +199,17 @@ CCProgram macro-remapping %{
|
||||
#pragma define IS_ANISOTROPY 1
|
||||
#pragma define-meta USE_VERTEX_COLOR
|
||||
#pragma define-meta USE_DITHERED_ALPHA_TEST
|
||||
#pragma define-meta USE_BACK_LIT
|
||||
#pragma define-meta USE_HIGH_QUALITY_REFLECTION
|
||||
|
||||
#define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
|
||||
#define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
|
||||
#define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY
|
||||
#define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
|
||||
|
||||
#define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT
|
||||
#define CC_SURFACES_LIGHTING_TRT 1
|
||||
#define CC_SURFACES_LIGHTING_TT 1
|
||||
#define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE 1
|
||||
#define CC_SURFACES_TRANSFER_CLIP_POS 1
|
||||
|
||||
// depend on UI macros
|
||||
@@ -214,7 +218,9 @@ CCProgram macro-remapping %{
|
||||
#endif
|
||||
|
||||
// functionality for each effect
|
||||
#define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31
|
||||
#if USE_HIGH_QUALITY_REFLECTION
|
||||
#define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 9
|
||||
#endif
|
||||
}%
|
||||
|
||||
CCProgram surface-vertex %{
|
||||
@@ -259,8 +265,8 @@ CCProgram surface-fragment %{
|
||||
uniform sampler2D anisotropyMap;
|
||||
#endif
|
||||
|
||||
#if USE_DEPTH_MAP
|
||||
uniform sampler2D depthMap;
|
||||
#if USE_BACK_LIT && USE_THICKNESS_MAP
|
||||
uniform sampler2D thicknessMap;
|
||||
#endif
|
||||
#if USE_SELF_SHADOW_MAP
|
||||
uniform sampler2D selfShadowMap;
|
||||
@@ -284,7 +290,7 @@ CCProgram surface-fragment %{
|
||||
return ttParams;
|
||||
}
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_TT_COLOR
|
||||
vec3 SurfacesFragmentModifyTTColor(in vec3 baseColor, in vec3 trtColor)
|
||||
vec3 SurfacesFragmentModifyTTColor(in vec3 baseColor)
|
||||
{
|
||||
return mix(baseColor.rgb, ttColor.rgb, ttColor.a); //ttColor can be (0.992, 0.808, 0.516)
|
||||
}
|
||||
@@ -294,8 +300,8 @@ CCProgram surface-fragment %{
|
||||
{
|
||||
float depth = SURFACES_MAX_TRANSMIT_DEPTH_VALUE;
|
||||
depth = ttParams.y;
|
||||
#if USE_DEPTH_MAP
|
||||
// depth = texture(depthMap, FSInput_texcoord).x;
|
||||
#if USE_BACK_LIT && USE_THICKNESS_MAP
|
||||
// depth = texture(thicknessMap, FSInput_texcoord).x;
|
||||
// depth = pow(depth, 1.0);
|
||||
// depth = 1.0 - depth;
|
||||
// depth *= ttParams.y;
|
||||
@@ -307,8 +313,8 @@ CCProgram surface-fragment %{
|
||||
vec4 SurfacesFragmentModifyTransmitDiffuseParams()
|
||||
{
|
||||
float mask = 1.0;
|
||||
#if USE_DEPTH_MAP
|
||||
mask = texture(depthMap, FSInput_texcoord).x;
|
||||
#if USE_BACK_LIT && USE_THICKNESS_MAP
|
||||
mask = texture(thicknessMap, FSInput_texcoord).x;
|
||||
mask = pow(mask, 1.0);
|
||||
mask = 1.0 - mask;
|
||||
mask *= 10.0;
|
||||
@@ -326,7 +332,7 @@ CCProgram surface-fragment %{
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
|
||||
vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
|
||||
{
|
||||
return vec3(0.7, 0.5, 0.3);
|
||||
return transmitColor.rgb;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
|
||||
|
||||
@@ -20,19 +20,21 @@ CCEffect %{
|
||||
normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
normalMap: { value: normal }
|
||||
pbrMap: { value: grey }
|
||||
pbrMap: { value: grey, editor: { displayName: PbrOrRoughnessMap } }
|
||||
occlusionMap: { value: white }
|
||||
emissiveMap: { value: grey }
|
||||
sssIntensity: { value: 1.0, target: scatterParams.z, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
preIntegratedSkinMap: { value: grey, editor: { parent: USE_PREINTEGRATED_SKIN } }
|
||||
sssCurvatureMap: { value: white, editor: { parent: USE_PREINTEGRATED_SKIN } }
|
||||
sssCurvature: { value: 0.1, target: scatterParams.w, editor: { parent: USE_PREINTEGRATED_SKIN, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
sssColoration: { value: 1.0, target: scatterColor.w, editor: { parent: USE_PREINTEGRATED_SKIN, slide: true, range: [0, 10.0], step: 0.001 } }
|
||||
cavityMap: { value: white }
|
||||
maskMap: { value: white, editor: { parent: USE_BACK_LIT } }
|
||||
sssColoration: { value: 1.0, target: dualLobeParams.z, editor: { parent: USE_PREINTEGRATED_SKIN, slide: true, range: [0, 10.0], step: 0.001 } }
|
||||
cavityMap: { value: white, editor: { tooltip: 'cavity map or specular map' } }
|
||||
maskMap: { value: black, editor: { parent: USE_BACK_LIT } }
|
||||
thickness: { value: 0.0, target: scatterParams.x, editor: { parent: USE_BACK_LIT, displayName: Object Thickness, range: [0, 1000.0], tooltip: 'Object thickness (world space unit), setting a too small value will cause the scattered light to disappear' } }
|
||||
extinction: { value: 0.0, target: scatterParams.y, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001 } }
|
||||
scatterColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting' } }
|
||||
transmitColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting' } }
|
||||
dualLobeRoughness: { value: 0.5, target: dualLobeParams.x, editor: { parent: USE_DUAL_LOBE_SPECULAR, range: [0, 1.0] } }
|
||||
dualLobeIntensity: { value: 0.02, target: dualLobeParams.w, editor: { parent: USE_DUAL_LOBE_SPECULAR, slide: true, range: [0, 0.1], step: 0.001 } }
|
||||
rasterizerState:
|
||||
cullMode: None
|
||||
depthStencilState:
|
||||
@@ -98,8 +100,9 @@ CCProgram shared-ubos %{
|
||||
vec4 pbrParams;
|
||||
vec4 emissive;
|
||||
vec4 emissiveScaleParam;
|
||||
vec4 scatterColor;
|
||||
vec4 transmitColor;
|
||||
vec4 scatterParams;
|
||||
vec4 dualLobeParams;
|
||||
};
|
||||
}%
|
||||
|
||||
@@ -110,11 +113,13 @@ CCProgram macro-remapping %{
|
||||
#pragma define-meta USE_VERTEX_COLOR
|
||||
#pragma define-meta USE_BACK_LIT
|
||||
#pragma define-meta USE_PREINTEGRATED_SKIN
|
||||
#pragma define-meta USE_DUAL_LOBE_SPECULAR
|
||||
|
||||
#define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
|
||||
#define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
|
||||
#define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
|
||||
|
||||
#define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR USE_DUAL_LOBE_SPECULAR
|
||||
#define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT
|
||||
#define CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT USE_BACK_LIT
|
||||
#define CC_SURFACES_LIGHTING_SSS 1
|
||||
@@ -178,7 +183,7 @@ CCProgram surface-fragment %{
|
||||
{
|
||||
float mask = 1.0;
|
||||
#if USE_BACK_LIT
|
||||
mask = texture(maskMap, FSInput_texcoord).x > 0.0 ? 1.0 : 0.0;
|
||||
mask = texture(maskMap, FSInput_texcoord).x;
|
||||
#endif
|
||||
return vec4(scatterParams.x, mask, 1.0, 1.0);
|
||||
}
|
||||
@@ -192,21 +197,40 @@ CCProgram surface-fragment %{
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
|
||||
vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
|
||||
{
|
||||
return scatterColor.rgb;
|
||||
return transmitColor.rgb;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_DUAL_LOBE_SPECULAR_PARAMS
|
||||
vec4 SurfacesFragmentModifyDualLobeSpecularParams(float roughness)
|
||||
{
|
||||
return vec4(dualLobeParams.x * roughness, 0.0, 0.0, dualLobeParams.w);
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_SSS_PARAMS
|
||||
vec4 SurfacesFragmentModifySSSParams()
|
||||
{
|
||||
float sssCurvature = scatterParams.w;
|
||||
float cavity = texture(cavityMap, FSInput_texcoord).x;
|
||||
#if USE_PREINTEGRATED_SKIN
|
||||
sssCurvature *= texture(sssCurvatureMap, FSInput_texcoord).x;
|
||||
#endif
|
||||
return vec4(scatterParams.z, sssCurvature, scatterColor.w, cavity);
|
||||
return vec4(scatterParams.z, sssCurvature, dualLobeParams.z, 0.0);
|
||||
}
|
||||
|
||||
#include <common-functions>
|
||||
|
||||
#include <surfaces/data-structures/standard>
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
|
||||
void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData)
|
||||
{
|
||||
float cavity = texture(cavityMap, FSInput_texcoord).x;
|
||||
surfaceData.specularIntensity *= cavity;
|
||||
|
||||
// ao and metallic ignored from pbrMap
|
||||
#if !USE_OCCLUSION_MAP
|
||||
surfaceData.ao = 1.0;
|
||||
#endif
|
||||
surfaceData.metallic = 0.0;
|
||||
}
|
||||
|
||||
#include <lighting-models/default-functions/simple-skin>
|
||||
}%
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ CCProgram surface-fragment %{
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#include <common/effect/special-effects>
|
||||
vec3 GetDetailedNormal(vec2 texCoord, float tiling, sampler2D normalMap, sampler2D normalMapDetailed, vec3 N, vec3 T)
|
||||
{
|
||||
float waterSpeed = waterParam.x;
|
||||
@@ -155,7 +155,7 @@ CCProgram surface-fragment %{
|
||||
vec2 uvDetailed = texCoord * detailedTiling + vec2(0.0, cc_time.w) * detailedSpeed;
|
||||
vec3 nmmpDetailed = texture(normalMapDetailed, uvDetailed).xyz - vec3(0.5);
|
||||
// normal blending
|
||||
nmmp = normalize(vec3(nmmp.xy + nmmpDetailed.xy * detailedIntensity, nmmp.z));
|
||||
nmmp = BlendDetailedNormalMap(nmmp, nmmpDetailed, detailedIntensity);
|
||||
return normalize(CalculateNormalFromTangentSpace(nmmp, normalIntensity, N, T, FSInput_mirrorNormal));
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ CCProgram surface-fragment %{
|
||||
{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
normal = GetDetailedNormal(NORMAL_UV, pbrParams.x, normalMap, normalMapDetailed, normal, FSInput_worldTangent);
|
||||
normal = GetDetailedNormal(NORMAL_UV, pbrParams.x, normalMap, normalMapDetailed, normalize(normal), normalize(FSInput_worldTangent));
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -21,6 +21,7 @@ CCEffect %{
|
||||
anisotropyIntensity: { value: 1.0, target: anisotropyParam.x, editor: { parent: IS_ANISOTROPY, slide : true, range : [0.0, 1.0] , step : 0.0001 } }
|
||||
anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { parent: IS_ANISOTROPY, slide : true, range : [0, 1.0] , step : 0.0001 } }
|
||||
anisotropyMapResolutionHeight: { value: 0.0, target: anisotropyParam.w, editor: { parent: FIX_ANISOTROPIC_ROTATION_MAP } }
|
||||
addOnShadowBias: { value: 0.0, target: anisotropyParam.z }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
normalMap: { value: normal }
|
||||
pbrMap: { value: grey }
|
||||
@@ -117,6 +118,12 @@ CCProgram macro-remapping %{
|
||||
}%
|
||||
|
||||
CCProgram surface-vertex %{
|
||||
#define CC_SURFACES_VERTEX_MODIFY_SHADOW_BIAS
|
||||
vec2 SurfacesVertexModifyShadowBias(in SurfacesStandardVertexIntermediate In, vec2 originShadowBias)
|
||||
{
|
||||
return originShadowBias + vec2(anisotropyParam.z, 0.0);
|
||||
}
|
||||
|
||||
/*#define CC_SURFACES_VERTEX_MODIFY_WORLD_POS
|
||||
vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
|
||||
{
|
||||
@@ -236,7 +243,7 @@ CCProgram surface-fragment %{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -133,8 +133,14 @@ CCProgram surface-fragment %{
|
||||
#endif
|
||||
surfaceData.baseColor = vec4(SRGBToLinear(baseColor.rgb), 1.0);
|
||||
|
||||
vec4 baseNormal = vec4(0, 0, 0, 0);
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
||||
vec3 binormal = vec3(0.0, 0.0, 1.0);
|
||||
binormal = cross(tangent, normal);
|
||||
tangent = cross(normal, binormal);
|
||||
|
||||
#if USE_NORMALMAP
|
||||
vec4 baseNormal = vec4(0, 0, 0, 0);
|
||||
#if LAYERS == 1
|
||||
baseNormal = texture(normalMap0, uv0);
|
||||
#elif LAYERS == 2
|
||||
@@ -153,20 +159,12 @@ CCProgram surface-fragment %{
|
||||
baseNormal = texture(normalMap0, uv0);
|
||||
#endif
|
||||
|
||||
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
||||
vec3 binormal = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
binormal = cross(tangent, FSInput_worldNormal);
|
||||
tangent = cross(FSInput_worldNormal, binormal);
|
||||
|
||||
vec3 nmmp = baseNormal.xyz - vec3(0.5);
|
||||
surfaceData.worldNormal =
|
||||
nmmp.x * normalize(tangent) +
|
||||
nmmp.y * normalize(binormal) +
|
||||
nmmp.z * normalize(FSInput_worldNormal);
|
||||
#else
|
||||
surfaceData.worldNormal = FSInput_worldNormal;
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, 1.0, normalize(normal.xyz), normalize(tangent), 1.0);
|
||||
#endif
|
||||
surfaceData.worldNormal = normalize(normal);
|
||||
surfaceData.worldTangent = normalize(tangent);
|
||||
surfaceData.worldBinormal = normalize(binormal);
|
||||
|
||||
float roughnessValue = 1.0;
|
||||
float metallicValue = 0.0;
|
||||
|
||||
@@ -194,7 +194,7 @@ CCProgram surface-fragment %{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleAndStrenth.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleAndStrenth.w, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -109,7 +109,6 @@ CCProgram unlit-vs %{
|
||||
CCProgram unlit-fs %{
|
||||
precision highp float;
|
||||
#include <legacy/output-standard>
|
||||
#include <common/data/unpack>
|
||||
#include <legacy/fog-fs>
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
@@ -150,9 +149,6 @@ CCProgram unlit-fs %{
|
||||
#endif
|
||||
|
||||
CC_APPLY_FOG(o);
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
o = packRGBE(o.rgb);
|
||||
#endif
|
||||
return CCFragOutput(o);
|
||||
}
|
||||
}%
|
||||
|
||||
@@ -69,9 +69,6 @@ CCProgram sky-fs %{
|
||||
vec3 c = SRGBToLinear(fragTextureLod(environmentMap, rotationDir.xyz, 0.0).rgb);
|
||||
#endif
|
||||
vec4 color = CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
}%
|
||||
|
||||
@@ -260,7 +260,7 @@ CCProgram surface-fragment %{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, normalStrength, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, normalStrength, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -263,7 +263,7 @@ CCProgram surface-fragment %{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, normalScale, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, normalScale, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
|
||||
#endif
|
||||
|
||||
return normalize(normal);
|
||||
|
||||
@@ -54,9 +54,9 @@ export class DebugViewRuntimeControl extends Component {
|
||||
'Env Transmit Diffuse',
|
||||
'Env Transmit Specular',
|
||||
'Transmit All',
|
||||
'Direct TRT',
|
||||
'Env TRT',
|
||||
'TRT All',
|
||||
'Direct Internal Specular',
|
||||
'Env Internal Specular',
|
||||
'Internal All',
|
||||
|
||||
'Fog',
|
||||
];
|
||||
@@ -79,7 +79,7 @@ export class DebugViewRuntimeControl extends Component {
|
||||
'Fresnel',
|
||||
'Transmit Diffuse',
|
||||
'Transmit Specular',
|
||||
'TRT',
|
||||
'Internal Specular',
|
||||
'TT',
|
||||
];
|
||||
private strMisc: string[] = [
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user