mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge pull request #9569 from cocos-creator/v3.4.0
sync V3.4.0 to V3.5.0
This commit is contained in:
@@ -3023,6 +3023,10 @@ Should only one camera exists, please check your project.
|
||||
|
||||
Camera does not support Canvas Mode.
|
||||
|
||||
### 8302
|
||||
|
||||
Camera.viewport is deprecated, please use setViewportInOrientedSpace instead.
|
||||
|
||||
### 8400
|
||||
|
||||
Wrong type arguments, 'filePath' must be a String.
|
||||
|
||||
@@ -417,7 +417,9 @@ export class Sprite extends Renderable2D {
|
||||
&& this._renderData) {
|
||||
this.markForUpdateRenderData(true);
|
||||
}
|
||||
this._updateUVWithTrim();
|
||||
if (UI_GPU_DRIVEN && this._canDrawByFourVertex) {
|
||||
this._updateUVWithTrim();
|
||||
}
|
||||
}
|
||||
|
||||
@editable
|
||||
|
||||
@@ -221,12 +221,9 @@ export class Canvas extends RenderRoot2D {
|
||||
protected _onResizeCamera () {
|
||||
if (this._cameraComponent && this._alignCanvasWithScreen) {
|
||||
if (this._cameraComponent.targetTexture) {
|
||||
const win = this._cameraComponent.targetTexture.window;
|
||||
if (this._cameraComponent.camera) { this._cameraComponent.camera.setFixedSize(win!.width, win!.height); }
|
||||
this._cameraComponent.orthoHeight = visibleRect.height / 2;
|
||||
} else if (game.canvas) {
|
||||
} else {
|
||||
const size = screen.windowSize;
|
||||
if (this._cameraComponent.camera) { this._cameraComponent.camera.resize(size.width, size.height); }
|
||||
this._cameraComponent.orthoHeight = size.height / view.getScaleY() / 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
import { ccclass, serializable, editable, editorOnly } from 'cc.decorator';
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { Root } from '../root';
|
||||
import { BlendState, DepthStencilState, RasterizerState, DescriptorType,
|
||||
DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, SamplerInfo, Uniform, Attribute, MemoryAccess, Format } from '../gfx';
|
||||
import { BlendState, DepthStencilState, RasterizerState,
|
||||
DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, Uniform, MemoryAccess, Format } from '../gfx';
|
||||
import { RenderPassStage } from '../pipeline/define';
|
||||
import { MacroRecord } from '../renderer/core/pass-utils';
|
||||
import { programLib } from '../renderer/core/program-lib';
|
||||
@@ -44,7 +44,8 @@ export declare namespace EffectAsset {
|
||||
type: number; // auto-extracted from shader
|
||||
handleInfo?: [string, number, number]; // auto-generated from 'target'
|
||||
samplerHash?: number; // auto-generated from 'sampler'
|
||||
value?: number[] | string;
|
||||
value?: number[] | string; // default value
|
||||
linear?: boolean; // whether to convert the input to linear space first before applying
|
||||
}
|
||||
// Pass instance itself are compliant to IPassStates too
|
||||
export interface IPassStates {
|
||||
|
||||
@@ -39,6 +39,9 @@ import { IPassInfoFull, Pass, PassOverrides } from '../renderer/core/pass';
|
||||
import { MacroRecord, MaterialProperty } from '../renderer/core/pass-utils';
|
||||
import { Color } from '../math/color';
|
||||
import { warnID } from '../platform/debug';
|
||||
import { Vec4 } from '../math';
|
||||
|
||||
const v4_1 = new Vec4();
|
||||
|
||||
/**
|
||||
* @en The basic infos for material initialization.
|
||||
@@ -423,6 +426,7 @@ export class Material extends Asset {
|
||||
if (Array.isArray(val)) {
|
||||
pass.setUniformArray(handle, val as MaterialProperty[]);
|
||||
} else if (val !== null) {
|
||||
if (pass.properties[name]?.linear) val = Vec4.multiply(v4_1, val as Vec4, val as Vec4);
|
||||
pass.setUniform(handle, val as MaterialProperty);
|
||||
} else {
|
||||
pass.resetUniform(name);
|
||||
|
||||
@@ -170,15 +170,14 @@ export class TextureBase extends Asset {
|
||||
* @param wrapR R(W) coordinate wrap mode
|
||||
*/
|
||||
public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) {
|
||||
if (wrapR === undefined) wrapR = wrapS; // wrap modes should be as consistent as possible for performance
|
||||
|
||||
this._wrapS = wrapS;
|
||||
this._samplerInfo.addressU = wrapS as unknown as Address;
|
||||
this._wrapT = wrapT;
|
||||
this._samplerInfo.addressV = wrapT as unknown as Address;
|
||||
|
||||
if (wrapR !== undefined) {
|
||||
this._wrapR = wrapR;
|
||||
this._samplerInfo.addressW = wrapR as unknown as Address;
|
||||
}
|
||||
this._wrapR = wrapR;
|
||||
this._samplerInfo.addressW = wrapR as unknown as Address;
|
||||
|
||||
if (this._gfxDevice) {
|
||||
this._gfxSampler = this._gfxDevice.getSampler(this._samplerInfo);
|
||||
|
||||
@@ -447,7 +447,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "standard|standard-vs|standard-fs",
|
||||
"hash": 2247364393,
|
||||
"hash": 2992576417,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 222, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 65 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
|
||||
@@ -466,15 +466,17 @@ export const effects = [
|
||||
{ "name": "USE_BATCHING", "type": "boolean" },
|
||||
{ "name": "USE_LIGHTMAP", "type": "boolean" },
|
||||
{ "name": "CC_USE_FOG", "type": "number", "range": [0, 4] },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
{ "name": "CC_USE_ACCURATE_FOG", "type": "boolean" },
|
||||
{ "name": "CC_RECEIVE_SHADOW", "type": "boolean" },
|
||||
{ "name": "USE_VERTEX_COLOR", "type": "boolean" },
|
||||
{ "name": "USE_NORMAL_MAP", "type": "boolean" },
|
||||
{ "name": "HAS_SECOND_UV", "type": "boolean" },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
{ "name": "USE_TWOSIDE", "type": "boolean" },
|
||||
{ "name": "SAMPLE_FROM_RT", "type": "boolean" },
|
||||
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
|
||||
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
|
||||
{ "name": "USE_REFLECTION_DENOISE", "type": "boolean" },
|
||||
{ "name": "CC_ENABLE_DIR_SHADOW", "type": "boolean" },
|
||||
{ "name": "CC_USE_HDR", "type": "boolean" },
|
||||
{ "name": "USE_ALBEDO_MAP", "type": "boolean" },
|
||||
@@ -539,7 +541,7 @@ export const effects = [
|
||||
},
|
||||
{
|
||||
"name": "standard|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
||||
"hash": 2596134892,
|
||||
"hash": 3990388591,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 183, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 65 },
|
||||
"globals": { "blocks": [{ "name": "CCShadow", "defines": [] }, { "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }], "buffers": [], "images": [] },
|
||||
@@ -610,7 +612,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "terrain|terrain-vs|terrain-fs",
|
||||
"hash": 1796906081,
|
||||
"hash": 1551773371,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 69, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 60 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
|
||||
@@ -618,13 +620,15 @@ export const effects = [
|
||||
},
|
||||
"defines": [
|
||||
{ "name": "CC_USE_FOG", "type": "number", "range": [0, 4] },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
{ "name": "CC_USE_ACCURATE_FOG", "type": "boolean" },
|
||||
{ "name": "CC_RECEIVE_SHADOW", "type": "boolean" },
|
||||
{ "name": "USE_NORMALMAP", "type": "boolean" },
|
||||
{ "name": "USE_LIGHTMAP", "type": "boolean" },
|
||||
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
|
||||
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
|
||||
{ "name": "USE_REFLECTION_DENOISE", "type": "boolean" },
|
||||
{ "name": "USE_BATCHING", "type": "boolean" },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
{ "name": "CC_ENABLE_DIR_SHADOW", "type": "boolean" },
|
||||
{ "name": "CC_USE_HDR", "type": "boolean" },
|
||||
{ "name": "LAYERS", "type": "number", "range": [0, 4] },
|
||||
@@ -701,7 +705,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "unlit|unlit-vs:vert|unlit-fs:frag",
|
||||
"hash": 2218802024,
|
||||
"hash": 1088129332,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 197, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -720,7 +724,7 @@ export const effects = [
|
||||
{ "name": "USE_BATCHING", "type": "boolean" },
|
||||
{ "name": "USE_LIGHTMAP", "type": "boolean" },
|
||||
{ "name": "CC_USE_FOG", "type": "number", "range": [0, 4] },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
{ "name": "CC_USE_ACCURATE_FOG", "type": "boolean" },
|
||||
{ "name": "USE_VERTEX_COLOR", "type": "boolean" },
|
||||
{ "name": "USE_TEXTURE", "type": "boolean" },
|
||||
{ "name": "SAMPLE_FROM_RT", "type": "boolean" },
|
||||
@@ -772,7 +776,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "bloom|bloom-vs|prefilter-fs",
|
||||
"hash": 2185821616,
|
||||
"hash": 3568412722,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 147, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -815,7 +819,7 @@ export const effects = [
|
||||
},
|
||||
{
|
||||
"name": "bloom|bloom-vs|downsample-fs",
|
||||
"hash": 1780231359,
|
||||
"hash": 3451245756,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 147, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -858,7 +862,7 @@ export const effects = [
|
||||
},
|
||||
{
|
||||
"name": "bloom|bloom-vs|upsample-fs",
|
||||
"hash": 3580425335,
|
||||
"hash": 3904509271,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 147, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -901,7 +905,7 @@ export const effects = [
|
||||
},
|
||||
{
|
||||
"name": "bloom|bloom-vs|combine-fs",
|
||||
"hash": 3457196798,
|
||||
"hash": 1662800198,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 147, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -953,7 +957,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "deferred-lighting|lighting-vs|lighting-fs",
|
||||
"hash": 2618924412,
|
||||
"hash": 679237985,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 39, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 58 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_IBL", "CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] },
|
||||
@@ -963,6 +967,7 @@ export const effects = [
|
||||
{ "name": "CC_RECEIVE_SHADOW", "type": "boolean" },
|
||||
{ "name": "CC_USE_IBL", "type": "number", "range": [0, 2] },
|
||||
{ "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] },
|
||||
{ "name": "USE_REFLECTION_DENOISE", "type": "boolean" },
|
||||
{ "name": "USE_LIGHTMAP", "type": "boolean" },
|
||||
{ "name": "USE_BATCHING", "type": "boolean" },
|
||||
{ "name": "CC_FORWARD_ADD", "type": "boolean" },
|
||||
@@ -1005,7 +1010,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag",
|
||||
"hash": 2954155677,
|
||||
"hash": 1302078023,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 215, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 58 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
@@ -1057,7 +1062,7 @@ export const effects = [
|
||||
"shaders": [
|
||||
{
|
||||
"name": "post-process|post-process-vs|post-process-fs",
|
||||
"hash": 3237848814,
|
||||
"hash": 1625499010,
|
||||
"builtins": {
|
||||
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 147, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 39 },
|
||||
"globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] },
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -393,7 +393,7 @@ export class Camera extends Component {
|
||||
|
||||
set rect (val) {
|
||||
this._rect = val;
|
||||
if (this._camera) { this._camera.viewport = val; }
|
||||
if (this._camera) { this._camera.setViewportInOrientedSpace(val); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -543,7 +543,7 @@ export class Camera extends Component {
|
||||
priority: this._priority,
|
||||
});
|
||||
|
||||
this._camera.viewport = this._rect;
|
||||
this._camera.setViewportInOrientedSpace(this._rect);
|
||||
this._camera.fovAxis = this._fovAxis;
|
||||
this._camera.fov = toRadian(this._fov);
|
||||
this._camera.orthoHeight = this._orthoHeight;
|
||||
|
||||
@@ -1319,7 +1319,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
offset: 0,
|
||||
|
||||
glType,
|
||||
glLoc: -1,
|
||||
glLoc: null!,
|
||||
array: null!,
|
||||
};
|
||||
}
|
||||
@@ -1365,8 +1365,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
|
||||
if (!isSampler) {
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, uniformInfo.name);
|
||||
// Note: wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
if (device.extensions.isLocationActive(glLoc)) {
|
||||
let varName: string;
|
||||
const nameOffset = uniformInfo.name.indexOf('[');
|
||||
if (nameOffset !== -1) {
|
||||
@@ -1426,8 +1425,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// Note: wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
if (device.extensions.isLocationActive(glLoc)) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
@@ -1462,7 +1460,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
for (let i = 0; i < glActiveSamplers.length; ++i) {
|
||||
const glSampler = glActiveSamplers[i];
|
||||
|
||||
if (!glSampler.glLoc) {
|
||||
if (!device.extensions.isLocationActive(glSampler.glLoc)) {
|
||||
glSampler.glLoc = glActiveSamplerLocations[i];
|
||||
for (let t = 0; t < glSampler.count; ++t) {
|
||||
while (usedTexUnits[unitIdx]) {
|
||||
@@ -2201,8 +2199,7 @@ export function WebGLCmdFuncBindStates (
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gpuDescriptor.gpuTexture
|
||||
&& gpuDescriptor.gpuTexture.size > 0) {
|
||||
if (gpuDescriptor.gpuTexture && gpuDescriptor.gpuTexture.size > 0) {
|
||||
const { gpuTexture } = gpuDescriptor;
|
||||
const glTexUnit = cache.glTexUnits[texUnit];
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ export interface IWebGLExtensions {
|
||||
ANGLE_instanced_arrays: ANGLE_instanced_arrays | null;
|
||||
destroyShadersImmediately: boolean;
|
||||
noCompressedTexSubImage2D: boolean;
|
||||
isLocationActive: (glLoc: unknown) => glLoc is WebGLUniformLocation;
|
||||
useVAO: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ export function getExtensions (gl: WebGLRenderingContext) {
|
||||
WEBGL_compressed_texture_astc: null,
|
||||
destroyShadersImmediately: true,
|
||||
noCompressedTexSubImage2D: false,
|
||||
isLocationActive: (glLoc: unknown): glLoc is WebGLUniformLocation => !!glLoc,
|
||||
useVAO: false,
|
||||
};
|
||||
|
||||
@@ -154,14 +155,25 @@ export function getExtensions (gl: WebGLRenderingContext) {
|
||||
res.destroyShadersImmediately = false;
|
||||
}
|
||||
|
||||
// compressedTexSubImage2D has always been problematic because the parameters differs slightly from GLES
|
||||
if (WECHAT) { // and MANY platforms get it wrong
|
||||
// compressedTexSubImage2D has always been problematic because the
|
||||
// parameters differs slightly from GLES, and many platforms get it wrong
|
||||
if (WECHAT) {
|
||||
res.noCompressedTexSubImage2D = true;
|
||||
}
|
||||
|
||||
if (res.OES_vertex_array_object) {
|
||||
res.useVAO = true;
|
||||
// getUniformLocation too [eyerolling]
|
||||
if (WECHAT) {
|
||||
// wEcHaT just returns { id: -1 } for inactive names
|
||||
res.isLocationActive = (glLoc: unknown): glLoc is WebGLUniformLocation => !!glLoc && (glLoc as { id: number }).id !== -1;
|
||||
}
|
||||
if (ALIPAY) {
|
||||
// aLiPaY just returns the location number directly on actual devices, and WebGLUniformLocation objects in simulators
|
||||
res.isLocationActive = (glLoc: unknown): glLoc is WebGLUniformLocation => !!glLoc && glLoc !== -1 || glLoc === 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (res.OES_vertex_array_object) {
|
||||
res.useVAO = true;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -96,13 +96,13 @@ export class PostProcessStage extends RenderStage {
|
||||
pipeline.pipelineUBO.updateCameraUBO(camera);
|
||||
|
||||
const vp = camera.viewport;
|
||||
this._renderArea.x = vp.x * camera.width;
|
||||
this._renderArea.y = vp.y * camera.height;
|
||||
this._renderArea.width = vp.width * camera.width;
|
||||
this._renderArea.height = vp.height * camera.height;
|
||||
this._renderArea.x = vp.x * camera.window.width;
|
||||
this._renderArea.y = vp.y * camera.window.height;
|
||||
this._renderArea.width = vp.width * camera.window.width;
|
||||
this._renderArea.height = vp.height * camera.window.height;
|
||||
const renderData = pipeline.getPipelineRenderData();
|
||||
const framebuffer = camera.window!.framebuffer;
|
||||
const swapchain = camera.window!.swapchain;
|
||||
const framebuffer = camera.window.framebuffer;
|
||||
const swapchain = camera.window.swapchain;
|
||||
const renderPass = swapchain ? pipeline.getRenderPass(camera.clearFlag, swapchain) : framebuffer.renderPass;
|
||||
|
||||
if (camera.clearFlag & ClearFlagBit.COLOR) {
|
||||
@@ -131,7 +131,7 @@ export class PostProcessStage extends RenderStage {
|
||||
|
||||
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet);
|
||||
|
||||
const inputAssembler = camera.window!.swapchain ? pipeline.quadIAOnscreen : pipeline.quadIAOffscreen;
|
||||
const inputAssembler = camera.window.swapchain ? pipeline.quadIAOnscreen : pipeline.quadIAOffscreen;
|
||||
let pso: PipelineState | null = null;
|
||||
if (pass != null && shader != null && inputAssembler != null) {
|
||||
pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader, renderPass, inputAssembler);
|
||||
|
||||
@@ -48,8 +48,6 @@ export class ForwardFlow extends RenderFlow {
|
||||
* @en The shared initialization information of forward render flow
|
||||
* @zh 共享的前向渲染流程初始化参数
|
||||
*/
|
||||
private postProcessStage: PostProcessStage | null = null;
|
||||
private bloomStage: BloomStage | null = null;
|
||||
public static initInfo: IRenderFlowInfo = {
|
||||
name: PIPELINE_FLOW_FORWARD,
|
||||
priority: ForwardFlowPriority.FORWARD,
|
||||
@@ -62,28 +60,17 @@ export class ForwardFlow extends RenderFlow {
|
||||
const forwardStage = new ForwardStage();
|
||||
forwardStage.initialize(ForwardStage.initInfo);
|
||||
this._stages.push(forwardStage);
|
||||
const bloomStage = new BloomStage();
|
||||
bloomStage.initialize(BloomStage.initInfo);
|
||||
this._stages.push(bloomStage);
|
||||
const postProcessStage = new PostProcessStage();
|
||||
postProcessStage.initialize(PostProcessStage.initInfo);
|
||||
this._stages.push(postProcessStage);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected _addPostStage () {
|
||||
if (!(this._stages[this._stages.length - 1] instanceof PostProcessStage)) {
|
||||
this.postProcessStage = new PostProcessStage();
|
||||
this.postProcessStage.initialize(PostProcessStage.initInfo);
|
||||
this._stages.push(this.postProcessStage);
|
||||
}
|
||||
}
|
||||
|
||||
protected _addBloomStage () {
|
||||
this.bloomStage = new BloomStage();
|
||||
this.bloomStage.initialize(BloomStage.initInfo);
|
||||
this.bloomStage.enabled = false;
|
||||
this._stages.push(this.bloomStage);
|
||||
}
|
||||
|
||||
public activate (pipeline: RenderPipeline) {
|
||||
this._addBloomStage();
|
||||
this._addPostStage();
|
||||
super.activate(pipeline);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
let newWidth = this._width;
|
||||
let newHeight = this._height;
|
||||
for (let i = 0; i < cameras.length; ++i) {
|
||||
const window = cameras[i].window!;
|
||||
const window = cameras[i].window;
|
||||
newWidth = Math.max(window.width, newWidth);
|
||||
newHeight = Math.max(window.height, newHeight);
|
||||
}
|
||||
@@ -175,14 +175,14 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
if (!this._postRenderPass) {
|
||||
const colorAttachment = new ColorAttachment();
|
||||
colorAttachment.format = Format.BGRA8;
|
||||
colorAttachment.format = swapchain.colorTexture.format;
|
||||
colorAttachment.loadOp = LoadOp.CLEAR; // should clear color attachment
|
||||
colorAttachment.storeOp = StoreOp.STORE;
|
||||
colorAttachment.endAccesses = [AccessType.COLOR_ATTACHMENT_READ];
|
||||
colorAttachment.endAccesses = [AccessType.COLOR_ATTACHMENT_WRITE];
|
||||
|
||||
const depthStencilAttachment = new DepthStencilAttachment();
|
||||
depthStencilAttachment.format = Format.DEPTH_STENCIL;
|
||||
depthStencilAttachment.format = swapchain.depthStencilTexture.format;
|
||||
depthStencilAttachment.depthLoadOp = LoadOp.CLEAR;
|
||||
depthStencilAttachment.depthStoreOp = StoreOp.STORE;
|
||||
depthStencilAttachment.stencilLoadOp = LoadOp.CLEAR;
|
||||
@@ -209,7 +209,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
data.outputRenderTargets.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.BGRA8,
|
||||
Format.RGBA8,
|
||||
this._width,
|
||||
this._height,
|
||||
)));
|
||||
|
||||
@@ -81,7 +81,7 @@ export class ForwardPipeline extends nr.ForwardPipeline implements IPipelineEven
|
||||
public init () {
|
||||
this.setPipelineSharedSceneData(this.pipelineSceneData.native);
|
||||
for (let i = 0; i < this._flows.length; i++) {
|
||||
this._flows[i].init();
|
||||
this._flows[i].init(this);
|
||||
}
|
||||
const info = new nr.RenderPipelineInfo(this._tag, this._flows);
|
||||
this.initialize(info);
|
||||
@@ -127,9 +127,9 @@ export class ForwardFlow extends nr.ForwardFlow {
|
||||
this._tag = 0;
|
||||
this._stages = [];
|
||||
}
|
||||
init() {
|
||||
init(pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init();
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
const info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
this.initialize(info);
|
||||
@@ -144,9 +144,9 @@ export class ShadowFlow extends nr.ShadowFlow {
|
||||
this._tag = 0;
|
||||
this._stages = [];
|
||||
}
|
||||
init() {
|
||||
init(pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init();
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
const info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
this.initialize(info);
|
||||
@@ -161,7 +161,7 @@ export class ForwardStage extends nr.ForwardStage {
|
||||
this._tag = 0;
|
||||
this.renderQueues = [];
|
||||
}
|
||||
public init() {
|
||||
public init(pipeline) {
|
||||
const queues = [];
|
||||
for (let i = 0; i < this.renderQueues.length; i++) {
|
||||
queues.push(this.renderQueues[i].init());
|
||||
@@ -178,7 +178,7 @@ export class ShadowStage extends nr.ShadowStage {
|
||||
this._priority = 0;
|
||||
this._tag = 0;
|
||||
}
|
||||
public init() {
|
||||
public init(pipeline) {
|
||||
const info = new nr.RenderStageInfo(this._name, this._priority, this._tag, []);
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -72,15 +72,13 @@ export class PipelineUBO {
|
||||
const sceneData = pipeline.pipelineSceneData;
|
||||
const ambient = sceneData.ambient;
|
||||
const fog = sceneData.fog;
|
||||
const shadingWidth = Math.floor(root.mainWindow.width);
|
||||
const shadingHeight = Math.floor(root.mainWindow.height);
|
||||
const cv = bufferView;
|
||||
const exposure = camera.exposure;
|
||||
const isHDR = sceneData.isHDR;
|
||||
|
||||
// update camera ubo
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET] = camera.width / shadingWidth;
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET + 1] = camera.height / shadingHeight;
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET] = sceneData.shadingScale;
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET + 1] = sceneData.shadingScale;
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET + 2] = 1.0 / cv[UBOCamera.SCREEN_SCALE_OFFSET];
|
||||
cv[UBOCamera.SCREEN_SCALE_OFFSET + 3] = 1.0 / cv[UBOCamera.SCREEN_SCALE_OFFSET + 1];
|
||||
|
||||
|
||||
@@ -326,10 +326,8 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
public generateRenderArea (camera: Camera, out?: Rect): Rect {
|
||||
const res = out || new Rect();
|
||||
const vp = camera.viewport;
|
||||
// render area is not oriented
|
||||
const swapchain = camera.window!.swapchain;
|
||||
const w = swapchain && swapchain.surfaceTransform % 2 ? camera.height : camera.width;
|
||||
const h = swapchain && swapchain.surfaceTransform % 2 ? camera.width : camera.height;
|
||||
const w = camera.window.width;
|
||||
const h = camera.window.height;
|
||||
res.x = vp.x * w;
|
||||
res.y = vp.y * h;
|
||||
res.width = vp.width * w;
|
||||
@@ -395,7 +393,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
if (camera.scene) {
|
||||
this.emit(PipelineEventType.RENDER_CAMERA_BEGIN, camera);
|
||||
sceneCulling(this, camera);
|
||||
this._pipelineUBO.updateGlobalUBO(camera.window!);
|
||||
this._pipelineUBO.updateGlobalUBO(camera.window);
|
||||
this._pipelineUBO.updateCameraUBO(camera);
|
||||
for (let j = 0; j < this._flows.length; j++) {
|
||||
this._flows[j].render(camera);
|
||||
@@ -635,7 +633,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
|
||||
// create renderPass
|
||||
const colorAttachment = new ColorAttachment();
|
||||
colorAttachment.format = Format.BGRA8;
|
||||
colorAttachment.format = Format.RGBA8;
|
||||
colorAttachment.loadOp = LoadOp.CLEAR;
|
||||
colorAttachment.storeOp = StoreOp.STORE;
|
||||
colorAttachment.endAccesses = [AccessType.COLOR_ATTACHMENT_WRITE];
|
||||
@@ -648,7 +646,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
bloom.prefiterTex = device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.BGRA8,
|
||||
Format.RGBA8,
|
||||
curWidth >> 1,
|
||||
curHeight >> 1,
|
||||
));
|
||||
@@ -664,7 +662,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
bloom.downsampleTexs.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.BGRA8,
|
||||
Format.RGBA8,
|
||||
curWidth >> 1,
|
||||
curHeight >> 1,
|
||||
)));
|
||||
@@ -676,7 +674,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
bloom.upsampleTexs.push(device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.BGRA8,
|
||||
Format.RGBA8,
|
||||
curWidth,
|
||||
curHeight,
|
||||
)));
|
||||
@@ -693,7 +691,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent {
|
||||
bloom.combineTex = device.createTexture(new TextureInfo(
|
||||
TextureType.TEX2D,
|
||||
TextureUsageBit.COLOR_ATTACHMENT | TextureUsageBit.SAMPLED,
|
||||
Format.BGRA8,
|
||||
Format.RGBA8,
|
||||
this._width,
|
||||
this._height,
|
||||
));
|
||||
|
||||
@@ -96,7 +96,7 @@ export class ShadowFlow extends RenderFlow {
|
||||
const globalDS = isMainLight ? pipeline.descriptorSet : pipeline.globalDSManager.getOrCreateDescriptorSet(l - 1)!;
|
||||
|
||||
if (!shadowFrameBufferMap.has(light)) {
|
||||
this._initShadowFrameBuffer(pipeline, light, camera.window!.swapchain);
|
||||
this._initShadowFrameBuffer(pipeline, light, camera.window.swapchain);
|
||||
}
|
||||
|
||||
const shadowFrameBuffer = shadowFrameBufferMap.get(light);
|
||||
|
||||
@@ -53,16 +53,18 @@ const orientationMap: Record<Orientation, SurfaceTransform> = {
|
||||
*/
|
||||
export class RenderWindow {
|
||||
/**
|
||||
* @en Get window width.
|
||||
* @zh 窗口宽度。
|
||||
* @en Get window width. Pre-rotated (i.e. rotationally invariant, always in identity/portrait mode) if possible.
|
||||
* If you want to get oriented size instead, you should use [[Camera.width]] which corresponds to the current screen rotation.
|
||||
* @zh 获取窗口宽度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[Camera.width]]。
|
||||
*/
|
||||
get width (): number {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get window height.
|
||||
* @zh 窗口高度。
|
||||
* @en Get window height. Pre-rotated (i.e. rotationally invariant, always in identity/portrait mode) if possible.
|
||||
* If you want to get oriented size instead, you should use [[Camera.width]] which corresponds to the current screen rotation.
|
||||
* @zh 获取窗口高度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[Camera.height]]。
|
||||
*/
|
||||
get height (): number {
|
||||
return this._height;
|
||||
@@ -219,9 +221,7 @@ export class RenderWindow {
|
||||
}
|
||||
|
||||
for (const camera of this._cameras) {
|
||||
if (camera.isWindowSize) {
|
||||
camera.resize(width, height);
|
||||
}
|
||||
camera.resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import { legacyCC } from '../../global-exports';
|
||||
import { RenderWindow } from '../core/render-window';
|
||||
import { preTransforms } from '../../math/mat4';
|
||||
import { NativeCamera } from './native-scene';
|
||||
import { warnID } from '../../platform/debug';
|
||||
|
||||
export enum CameraFOVAxis {
|
||||
VERTICAL,
|
||||
@@ -203,6 +204,19 @@ export class Camera {
|
||||
}
|
||||
}
|
||||
|
||||
private _updateAspect (oriented = true) {
|
||||
this._aspect = (this.window.width * this._viewport.width) / (this.window.height * this._viewport.height);
|
||||
// window size/viewport is pre-rotated, but aspect should be oriented to acquire the correct projection
|
||||
if (oriented) {
|
||||
const swapchain = this.window.swapchain;
|
||||
const orientation = swapchain && swapchain.surfaceTransform || SurfaceTransform.IDENTITY;
|
||||
if (orientation % 2) this._aspect = 1 / this._aspect;
|
||||
}
|
||||
this._isProjDirty = true;
|
||||
|
||||
if (JSB) this._nativeObj!.aspect = this._aspect;
|
||||
}
|
||||
|
||||
protected _init (info: ICameraInfo) {
|
||||
if (JSB) {
|
||||
this._nativeObj = new NativeCamera();
|
||||
@@ -248,7 +262,7 @@ export class Camera {
|
||||
public destroy () {
|
||||
if (this._window) {
|
||||
this._window.detachCamera(this);
|
||||
this.window = null;
|
||||
this.window = null!;
|
||||
}
|
||||
this._name = null;
|
||||
this._destroy();
|
||||
@@ -269,20 +283,13 @@ export class Camera {
|
||||
|
||||
this._setWidth(width);
|
||||
this._setHeight(height);
|
||||
this._aspect = (width * this._viewport.width) / (height * this._viewport.height);
|
||||
if (JSB) {
|
||||
this._nativeObj!.aspect = this._aspect;
|
||||
}
|
||||
this._isProjDirty = true;
|
||||
this._updateAspect();
|
||||
}
|
||||
|
||||
public setFixedSize (width: number, height: number) {
|
||||
this._setWidth(width);
|
||||
this._setHeight(height);
|
||||
this._aspect = (width * this._viewport.width) / (height * this._viewport.height);
|
||||
if (JSB) {
|
||||
this._nativeObj!.aspect = this._aspect;
|
||||
}
|
||||
this._updateAspect(false);
|
||||
this.isWindowSize = false;
|
||||
}
|
||||
|
||||
@@ -330,7 +337,7 @@ export class Camera {
|
||||
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; // aspect is already oriented
|
||||
const x = this._orthoHeight * this._aspect;
|
||||
const y = this._orthoHeight;
|
||||
Mat4.ortho(this._matProj, -x, x, -y, y, this._nearClip, this._farClip,
|
||||
this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation);
|
||||
@@ -456,11 +463,22 @@ export class Camera {
|
||||
return this._clearColor as IVec4Like;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-rotated (i.e. always in identity/portrait mode) if possible.
|
||||
*/
|
||||
get viewport () {
|
||||
return this._viewport;
|
||||
}
|
||||
|
||||
set viewport (val) {
|
||||
warnID(8302);
|
||||
this.setViewportInOrientedSpace(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the viewport in oriented space (local to screen rotations)
|
||||
*/
|
||||
public setViewportInOrientedSpace (val: Rect) {
|
||||
const { x, width, height } = val;
|
||||
const y = this._device.capabilities.screenSpaceSignY < 0 ? 1 - val.y - height : val.y;
|
||||
|
||||
@@ -554,12 +572,12 @@ export class Camera {
|
||||
set window (val) {
|
||||
this._window = val;
|
||||
if (JSB && val) {
|
||||
this._nativeObj!.window = this._window!.native;
|
||||
this._nativeObj!.window = this._window.native;
|
||||
}
|
||||
}
|
||||
|
||||
get window () {
|
||||
return this._window;
|
||||
return this._window!;
|
||||
}
|
||||
|
||||
set forward (val) {
|
||||
@@ -701,7 +719,12 @@ export class Camera {
|
||||
if (win) {
|
||||
win.attachCamera(this);
|
||||
this.window = win;
|
||||
this.resize(win.width, win.height);
|
||||
|
||||
// window size is pre-rotated
|
||||
const swapchain = win.swapchain;
|
||||
const orientation = swapchain && swapchain.surfaceTransform || SurfaceTransform.IDENTITY;
|
||||
if (orientation % 2) this.resize(win.height, win.width);
|
||||
else this.resize(win.width, win.height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,8 +740,8 @@ export class Camera {
|
||||
public screenPointToRay (out: Ray, x: number, y: number): Ray {
|
||||
if (!this._node) return null!;
|
||||
|
||||
const width = this.width;
|
||||
const height = this.height;
|
||||
const width = this.window.width;
|
||||
const height = this.window.height;
|
||||
const cx = this._viewport.x * width;
|
||||
const cy = this._viewport.y * height;
|
||||
const cw = this._viewport.width * width;
|
||||
@@ -750,8 +773,8 @@ export class Camera {
|
||||
* transform a screen position (in oriented space) to world space
|
||||
*/
|
||||
public screenToWorld (out: Vec3, screenPos: Vec3): Vec3 {
|
||||
const width = this.width;
|
||||
const height = this.height;
|
||||
const width = this.window.width;
|
||||
const height = this.window.height;
|
||||
const cx = this._viewport.x * width;
|
||||
const cy = this._viewport.y * height;
|
||||
const cw = this._viewport.width * width;
|
||||
@@ -796,8 +819,8 @@ export class Camera {
|
||||
* transform a world space position to screen space
|
||||
*/
|
||||
public worldToScreen (out: Vec3, worldPos: Vec3 | Readonly<Vec3>): Vec3 {
|
||||
const width = this.width;
|
||||
const height = this.height;
|
||||
const width = this.window.width;
|
||||
const height = this.window.height;
|
||||
const cx = this._viewport.x * width;
|
||||
const cy = this._viewport.y * height;
|
||||
const cw = this._viewport.width * width;
|
||||
|
||||
@@ -90,6 +90,19 @@ export class Fog {
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 是否启用精确雾效(像素雾)计算
|
||||
* @en Enable accurate fog (pixel fog)
|
||||
*/
|
||||
set accurate (val: boolean) {
|
||||
this._setAccurate(val);
|
||||
this._updatePipeline();
|
||||
}
|
||||
|
||||
get accurate (): boolean {
|
||||
return this._accurate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 全局雾颜色
|
||||
* @en Global fog color
|
||||
@@ -219,6 +232,7 @@ export class Fog {
|
||||
protected _fogColor = new Color('#C8C8C8');
|
||||
protected _colorArray: Float32Array = new Float32Array([0.2, 0.2, 0.2, 1.0]);
|
||||
protected _enabled = false;
|
||||
protected _accurate = false;
|
||||
protected _type = 0;
|
||||
protected _fogDensity = 0.3;
|
||||
protected _fogStart = 0.5;
|
||||
@@ -252,9 +266,17 @@ export class Fog {
|
||||
}
|
||||
}
|
||||
|
||||
protected _setAccurate (val) {
|
||||
this._accurate = val;
|
||||
if (JSB) {
|
||||
this._nativeObj!.accurate = val;
|
||||
}
|
||||
}
|
||||
|
||||
public initialize (fogInfo : FogInfo) {
|
||||
this.fogColor = fogInfo.fogColor;
|
||||
this._setEnable(fogInfo.enabled);
|
||||
this._setAccurate(fogInfo.accurate);
|
||||
this._setType(fogInfo.type);
|
||||
this.fogDensity = fogInfo.fogDensity;
|
||||
this.fogStart = fogInfo.fogStart;
|
||||
@@ -271,9 +293,13 @@ export class Fog {
|
||||
protected _updatePipeline () {
|
||||
const root = legacyCC.director.root;
|
||||
const value = this.enabled ? this.type : FOG_TYPE_NONE;
|
||||
const accurateValue = this.accurate ? 1 : 0;
|
||||
const pipeline = root.pipeline;
|
||||
if (pipeline.macros.CC_USE_FOG === value) { return; }
|
||||
if (pipeline.macros.CC_USE_FOG === value && pipeline.macros.CC_USE_ACCURATE_FOG === accurateValue) {
|
||||
return;
|
||||
}
|
||||
pipeline.macros.CC_USE_FOG = value;
|
||||
pipeline.macros.CC_USE_ACCURATE_FOG = accurateValue;
|
||||
root.onGlobalPipelineStateChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ export type NaitveSkybox = InstanceType<typeof NaitveSkybox>;
|
||||
export const NativeFog: Constructor<{
|
||||
type: number;
|
||||
enabled: boolean;
|
||||
accurate: boolean;
|
||||
color: Color;
|
||||
density: number;
|
||||
start: number;
|
||||
|
||||
@@ -103,6 +103,15 @@ export class AmbientInfo {
|
||||
* @en Sky lighting color configurable in editor with color picker
|
||||
* @zh 编辑器中可配置的天空光照颜色(通过颜色拾取器)
|
||||
*/
|
||||
@visible(() => {
|
||||
const scene = legacyCC.director.getScene();
|
||||
const skybox = scene.globals.skybox;
|
||||
if (skybox.useIBL && skybox.applyDiffuseMap) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
@editable
|
||||
set skyLightingColor (val: Color) {
|
||||
let result;
|
||||
@@ -159,6 +168,15 @@ export class AmbientInfo {
|
||||
* @en Ground lighting color configurable in editor with color picker
|
||||
* @zh 编辑器中可配置的地面光照颜色(通过颜色拾取器)
|
||||
*/
|
||||
@visible(() => {
|
||||
const scene = legacyCC.director.getScene();
|
||||
const skybox = scene.globals.skybox;
|
||||
if (skybox.useIBL && skybox.applyDiffuseMap) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
@editable
|
||||
set groundLightingColor (val: Color) {
|
||||
let result;
|
||||
@@ -411,6 +429,8 @@ export class FogInfo {
|
||||
protected _fogTop = 1.5;
|
||||
@serializable
|
||||
protected _fogRange = 1.2;
|
||||
@serializable
|
||||
protected _accurate = false;
|
||||
protected _resource: Fog | null = null;
|
||||
/**
|
||||
* @zh 是否启用全局雾效
|
||||
@@ -432,6 +452,26 @@ export class FogInfo {
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 是否启用精确雾效(像素雾)计算
|
||||
* @en Enable accurate fog (pixel fog)
|
||||
*/
|
||||
@editable
|
||||
set accurate (val: boolean) {
|
||||
if (this._accurate === val) return;
|
||||
this._accurate = val;
|
||||
if (this._resource) {
|
||||
this._resource.accurate = val;
|
||||
if (val) {
|
||||
this._resource.type = this._type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get accurate () {
|
||||
return this._accurate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 全局雾颜色
|
||||
* @en Global fog color
|
||||
@@ -483,10 +523,10 @@ export class FogInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 雾效起始位置,只适用于线性雾
|
||||
* @en Global fog start position, only for linear fog
|
||||
* @zh 雾效起始位置
|
||||
* @en Global fog start position
|
||||
*/
|
||||
@visible(function (this: FogInfo) { return this._type === FogType.LINEAR; })
|
||||
@visible(function (this: FogInfo) { return this._type !== FogType.LAYERED; })
|
||||
@type(CCFloat)
|
||||
@rangeStep(0.01)
|
||||
@displayOrder(4)
|
||||
|
||||
@@ -667,7 +667,7 @@ export class TerrainBlock {
|
||||
* @en 地形块的可见性
|
||||
* @zh block visible
|
||||
*/
|
||||
set visible (val) {
|
||||
set visible (val) {
|
||||
if (this._renderable._model !== null) {
|
||||
if (val) {
|
||||
if (this._renderable._model.scene == null) {
|
||||
|
||||
@@ -19,8 +19,9 @@ float LinearFog(vec4 pos) {
|
||||
float ExpFog(vec4 pos) {
|
||||
vec4 wPos = pos;
|
||||
float fogAtten = cc_fogAdd.z;
|
||||
float fogStart = cc_fogBase.x;
|
||||
float fogDensity = cc_fogBase.z;
|
||||
float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;
|
||||
float cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;
|
||||
float f = exp(-cam_dis * fogDensity);
|
||||
return f;
|
||||
}
|
||||
@@ -28,8 +29,9 @@ float ExpFog(vec4 pos) {
|
||||
float ExpSquaredFog(vec4 pos) {
|
||||
vec4 wPos = pos;
|
||||
float fogAtten = cc_fogAdd.z;
|
||||
float fogStart = cc_fogBase.x;
|
||||
float fogDensity = cc_fogBase.z;
|
||||
float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;
|
||||
float cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;
|
||||
float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);
|
||||
return f;
|
||||
}
|
||||
@@ -74,19 +76,21 @@ float LayeredFog(vec4 pos) {
|
||||
return f;
|
||||
}
|
||||
|
||||
#define CC_TRANSFER_FOG_BASE(pos, factor) \
|
||||
#if CC_USE_FOG == CC_FOG_LINEAR \
|
||||
factor = LinearFog(pos); \
|
||||
#elif CC_USE_FOG == CC_FOG_EXP \
|
||||
factor = ExpFog(pos); \
|
||||
#elif CC_USE_FOG == CC_FOG_EXP_SQUARED \
|
||||
factor = ExpSquaredFog(pos); \
|
||||
#elif CC_USE_FOG == CC_FOG_LAYERED \
|
||||
factor = LayeredFog(pos); \
|
||||
#else \
|
||||
factor = 1.0; \
|
||||
#endif \
|
||||
#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
|
||||
void CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)
|
||||
{
|
||||
#if CC_USE_FOG == CC_FOG_LINEAR
|
||||
factor = LinearFog(pos);
|
||||
#elif CC_USE_FOG == CC_FOG_EXP
|
||||
factor = ExpFog(pos);
|
||||
#elif CC_USE_FOG == CC_FOG_EXP_SQUARED
|
||||
factor = ExpSquaredFog(pos);
|
||||
#elif CC_USE_FOG == CC_FOG_LAYERED
|
||||
factor = LayeredFog(pos);
|
||||
#else
|
||||
factor = 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma define CC_FORWARD_ADD
|
||||
#define CC_APPLY_FOG_BASE(color, factor) color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor), color.a)
|
||||
void CC_APPLY_FOG_BASE(inout vec4 color, float factor) {
|
||||
color = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,28 @@
|
||||
|
||||
#include <cc-fog-base>
|
||||
|
||||
#if !CC_USE_ACCURATE_FOG
|
||||
in float v_fog_factor;
|
||||
#endif
|
||||
|
||||
#define CC_FOG_FACTOR v_fog_factor
|
||||
#define CC_APPLY_FOG(color) CC_APPLY_FOG_BASE(color, v_fog_factor)
|
||||
|
||||
// Just to be compatible with old projects only
|
||||
// Do not support accurate fog
|
||||
vec4 CC_APPLY_FOG(vec4 color) {
|
||||
#if !CC_USE_ACCURATE_FOG
|
||||
CC_APPLY_FOG_BASE(color, CC_FOG_FACTOR);
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 CC_APPLY_FOG(vec4 color, vec3 worldPos) {
|
||||
#if CC_USE_ACCURATE_FOG
|
||||
float factor;
|
||||
CC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);
|
||||
#else
|
||||
float factor = CC_FOG_FACTOR;
|
||||
#endif
|
||||
CC_APPLY_FOG_BASE(color, factor);
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
|
||||
#include <cc-fog-base>
|
||||
|
||||
#if !CC_USE_ACCURATE_FOG
|
||||
out float v_fog_factor;
|
||||
#endif
|
||||
|
||||
#define CC_FOG_FACTOR v_fog_factor
|
||||
#define CC_TRANSFER_FOG(pos) CC_TRANSFER_FOG_BASE(pos, v_fog_factor)
|
||||
|
||||
void CC_TRANSFER_FOG(vec4 pos) {
|
||||
#if !CC_USE_ACCURATE_FOG
|
||||
CC_TRANSFER_FOG_BASE(pos, CC_FOG_FACTOR);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ layout(location = 5) in vec4 a_weights;
|
||||
*/
|
||||
#define CCGetJointTextureCoords(pixelsPerJoint, jointIdx, temp, x, y, invSize) \
|
||||
#if USE_INSTANCING \
|
||||
highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z; \
|
||||
highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z; \
|
||||
#else \
|
||||
highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z; \
|
||||
#endif \
|
||||
|
||||
@@ -39,6 +39,32 @@ vec3 BRDFApprox (vec3 specular, float roughness, float NoV) {
|
||||
return specular * AB.x + AB.y;
|
||||
}
|
||||
|
||||
#if USE_REFLECTION_DENOISE
|
||||
vec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {
|
||||
#if CC_USE_IBL
|
||||
float mip = roughness * mipCount;
|
||||
float delta = (dot(dFdx(R), dFdy(R))) * 1000.0;
|
||||
float mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));
|
||||
|
||||
vec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);
|
||||
vec4 filtered = texture(cc_environment, R);
|
||||
|
||||
#if CC_USE_IBL == IBL_RGBE
|
||||
biased.rgb = unpackRGBE(biased);
|
||||
filtered.rgb = unpackRGBE(filtered);
|
||||
#else
|
||||
biased.rgb = SRGBToLinear(biased.rgb);
|
||||
filtered.rgb = SRGBToLinear(filtered.rgb);
|
||||
#endif
|
||||
|
||||
return mix(biased.rgb, filtered.rgb, denoiseIntensity);
|
||||
#else
|
||||
return vec3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct StandardSurface {
|
||||
// albedo
|
||||
vec4 albedo;
|
||||
@@ -113,12 +139,17 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {
|
||||
#endif
|
||||
|
||||
vec3 R = normalize(reflect(-V, N));
|
||||
vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);
|
||||
|
||||
#if CC_USE_IBL == IBL_RGBE
|
||||
vec3 env = unpackRGBE(envmap);
|
||||
#if USE_REFLECTION_DENOISE
|
||||
vec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);
|
||||
#else
|
||||
vec3 env = SRGBToLinear(envmap.rgb);
|
||||
vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);
|
||||
|
||||
#if CC_USE_IBL == IBL_RGBE
|
||||
vec3 env = unpackRGBE(envmap);
|
||||
#else
|
||||
vec3 env = SRGBToLinear(envmap.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
finalColor += env * cc_ambientSky.w * specular * s.occlusion;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#else \
|
||||
vec4 color = CCStandardShadingAdditive(s, CC_SHADOW_POSITION); \
|
||||
#endif \
|
||||
CC_APPLY_FOG(color); \
|
||||
CC_APPLY_FOG(color, s.position.xyz); \
|
||||
fragColorX = CCFragOutput(color); \
|
||||
} \
|
||||
\
|
||||
@@ -33,7 +33,7 @@
|
||||
void main () { \
|
||||
StandardSurface s; surf(s); \
|
||||
vec4 color = CCStandardShadingBase(s, CC_SHADOW_POSITION); \
|
||||
CC_APPLY_FOG(color); \
|
||||
CC_APPLY_FOG(color, s.position.xyz); \
|
||||
fragColorX = CCFragOutput(color); \
|
||||
} \
|
||||
\
|
||||
|
||||
@@ -37,7 +37,7 @@ CCProgram unlit-fs %{
|
||||
|
||||
vec4 frag () {
|
||||
vec4 col = mainColor * texture(mainTexture, v_uv);
|
||||
CC_APPLY_FOG(col);
|
||||
CC_APPLY_FOG(col, v_position);
|
||||
return CCFragOutput(col);
|
||||
}
|
||||
}%
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
"__id__": 3
|
||||
}
|
||||
],
|
||||
"renderTextures": [],
|
||||
"materials": []
|
||||
"renderTextures": []
|
||||
},
|
||||
{
|
||||
"__type__": "ShadowFlow",
|
||||
@@ -41,6 +40,12 @@
|
||||
"_stages": [
|
||||
{
|
||||
"__id__": 4
|
||||
},
|
||||
{
|
||||
"__id__": 7
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -73,5 +78,20 @@
|
||||
"stages": [
|
||||
"default"
|
||||
]
|
||||
},
|
||||
{
|
||||
"__type__": "BloomStage",
|
||||
"_name": "BloomStage",
|
||||
"_priority": 0,
|
||||
"_tag": 0,
|
||||
"_bloomMaterial": null
|
||||
},
|
||||
{
|
||||
"__type__": "PostProcessStage",
|
||||
"_name": "PostProcessStage",
|
||||
"_priority": 0,
|
||||
"_tag": 0,
|
||||
"_postProcessMaterial": null,
|
||||
"renderQueues": []
|
||||
}
|
||||
]
|
||||
@@ -231,7 +231,7 @@ CCProgram standard-fs %{
|
||||
void main () {
|
||||
StandardSurface s; surf(s);
|
||||
vec4 color = CCStandardShadingBase(s, CC_SHADOW_POSITION);
|
||||
CC_APPLY_FOG(color);
|
||||
CC_APPLY_FOG(color, s.position.xyz);
|
||||
vec4 baseColor = CCFragOutput(color);
|
||||
|
||||
vec2 noise = v_normal.xy * 0.02;
|
||||
|
||||
@@ -7,26 +7,23 @@ CCEffect %{
|
||||
- vert: standard-vs
|
||||
frag: standard-fs
|
||||
properties: &props
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
SpecularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
normalStrenth: { value: 1.0, target: miscParams.x, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
emissive: { value: [0.0, 0.0, 0.0, 1.0], editor: { type: color } }
|
||||
emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
normalMap: { value: normal }
|
||||
pbrMap: { value: grey }
|
||||
metallicRoughnessMap: { value: grey }
|
||||
occlusionMap: { value: white }
|
||||
emissiveMap: { value: grey }
|
||||
migrations:
|
||||
properties:
|
||||
pbrParams: { removeImmediately: true }
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
SpecularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
|
||||
emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } }
|
||||
emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz }
|
||||
normalStrenth: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
normalMap: { value: normal }
|
||||
pbrMap: { value: grey }
|
||||
metallicRoughnessMap: { value: grey }
|
||||
occlusionMap: { value: white }
|
||||
emissiveMap: { value: grey }
|
||||
- &forward-add
|
||||
vert: standard-vs
|
||||
frag: standard-fs
|
||||
@@ -44,7 +41,6 @@ CCEffect %{
|
||||
blendDst: one
|
||||
blendSrcAlpha: zero
|
||||
blendDstAlpha: one
|
||||
properties: *props
|
||||
- &shadow-caster
|
||||
vert: shadow-caster-vs:vert
|
||||
frag: shadow-caster-fs:frag
|
||||
@@ -52,18 +48,6 @@ CCEffect %{
|
||||
propertyIndex: 0
|
||||
rasterizerState:
|
||||
cullMode: front
|
||||
properties:
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
occlusion: { value: 1.0, target: pbrParams.x }
|
||||
roughness: { value: 0.8, target: pbrParams.y }
|
||||
metallic: { value: 0.6, target: pbrParams.z }
|
||||
normalStrenth: { value: 1.0, target: pbrParams.w, editor: { parent: USE_NORMAL_MAP } }
|
||||
emissive: { value: [0.0, 0.0, 0.0, 1.0], editor: { type: color } }
|
||||
emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
@@ -89,7 +73,6 @@ CCProgram shared-ubos %{
|
||||
vec4 albedo;
|
||||
vec4 albedoScaleAndCutoff;
|
||||
vec4 pbrParams;
|
||||
vec4 miscParams;
|
||||
vec4 emissive;
|
||||
vec4 emissiveScaleParam;
|
||||
};
|
||||
@@ -138,7 +121,7 @@ CCProgram standard-vs %{
|
||||
|
||||
v_position = pos.xyz;
|
||||
v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);
|
||||
|
||||
|
||||
#if USE_TWOSIDE
|
||||
vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);
|
||||
v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;
|
||||
@@ -171,7 +154,6 @@ CCProgram standard-vs %{
|
||||
CCLightingMapCaclUV();
|
||||
#endif
|
||||
|
||||
|
||||
gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;
|
||||
}
|
||||
}%
|
||||
@@ -220,11 +202,10 @@ CCProgram standard-fs %{
|
||||
#pragma define EMISSIVE_UV options([v_uv, v_uv1])
|
||||
#endif
|
||||
|
||||
#define OCCLUSION_CHANNEL r
|
||||
#define ROUGHNESS_CHANNEL g
|
||||
#define METALLIC_CHANNEL b
|
||||
#define SPECULARINTENSITY_CHANNEL w
|
||||
|
||||
#define OCCLUSION_CHANNEL r
|
||||
#define ROUGHNESS_CHANNEL g
|
||||
#define METALLIC_CHANNEL b
|
||||
#define SPECULAR_INTENSITY_CHANNEL a
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
#pragma define ALPHA_TEST_CHANNEL options([a, r])
|
||||
@@ -233,7 +214,7 @@ CCProgram standard-fs %{
|
||||
void surf (out StandardSurface s) {
|
||||
vec4 baseColor = albedo;
|
||||
#if USE_VERTEX_COLOR
|
||||
baseColor.rgb *= SRGBToLinear(v_color.rgb);//use linear
|
||||
baseColor.rgb *= SRGBToLinear(v_color.rgb); // use linear
|
||||
baseColor.a *= v_color.a;
|
||||
#endif
|
||||
#if USE_ALBEDO_MAP
|
||||
@@ -258,8 +239,8 @@ CCProgram standard-fs %{
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
s.normal =
|
||||
(nmmp.x * miscParams.x) * normalize(v_tangent) +
|
||||
(nmmp.y * miscParams.x) * normalize(v_bitangent) +
|
||||
(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent) +
|
||||
(nmmp.y * emissiveScaleParam.w) * normalize(v_bitangent) +
|
||||
nmmp.z * normalize(s.normal);
|
||||
#endif
|
||||
|
||||
@@ -271,7 +252,7 @@ CCProgram standard-fs %{
|
||||
pbr.x *= res.OCCLUSION_CHANNEL;
|
||||
pbr.y *= res.ROUGHNESS_CHANNEL;
|
||||
pbr.z *= res.METALLIC_CHANNEL;
|
||||
pbr.w *= res.SPECULARINTENSITY_CHANNEL;
|
||||
pbr.w *= res.SPECULAR_INTENSITY_CHANNEL;
|
||||
#endif
|
||||
#if USE_METALLIC_ROUGHNESS_MAP
|
||||
vec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);
|
||||
|
||||
@@ -25,14 +25,8 @@ exports.$ = {
|
||||
};
|
||||
|
||||
exports.ready = function() {
|
||||
this.$.button.addEventListener('click', async () => {
|
||||
await Editor.Message.request('scene', 'execute-scene-script', {
|
||||
name: 'animation-graph',
|
||||
method: 'edit',
|
||||
args: [this.asset.uuid],
|
||||
});
|
||||
|
||||
Editor.Panel.open('animation-graph');
|
||||
this.$.button.addEventListener('click', () => {
|
||||
Editor.Message.request('asset-db', 'open-asset', this.asset.uuid);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { TouchCallback } from 'pal/input';
|
||||
import { minigame } from 'pal/minigame';
|
||||
import { screenAdapter } from 'pal/screen-adapter';
|
||||
import { VIVO } from 'internal:constants';
|
||||
import { Size, Vec2 } from '../../../cocos/core/math';
|
||||
import { EventTarget } from '../../../cocos/core/event';
|
||||
import { EventTouch, Touch } from '../../../cocos/input/types';
|
||||
@@ -55,7 +56,9 @@ export class TouchInputSource {
|
||||
}
|
||||
|
||||
private _getLocation (touch: globalThis.Touch, windowSize: Size): Vec2 {
|
||||
const dpr = screenAdapter.devicePixelRatio;
|
||||
// NOTE: touch position on vivo platform is in physical pixel.
|
||||
// No need to multiply with DPR.
|
||||
const dpr = VIVO ? 1 : screenAdapter.devicePixelRatio;
|
||||
const x = touch.clientX * dpr;
|
||||
const y = windowSize.height - touch.clientY * dpr;
|
||||
return new Vec2(x, y);
|
||||
|
||||
@@ -54,7 +54,9 @@ class ScreenAdapter extends EventTarget {
|
||||
|
||||
public get windowSize (): Size {
|
||||
const sysInfo = minigame.getSystemInfoSync();
|
||||
const dpr = this.devicePixelRatio;
|
||||
// NOTE: screen size info on these platforms is in physical pixel.
|
||||
// No need to multiply with DPR.
|
||||
const dpr = ((ALIPAY && systemInfo.os === OS.ANDROID) || VIVO) ? 1 : this.devicePixelRatio;
|
||||
let screenWidth = sysInfo.screenWidth;
|
||||
let screenHeight = sysInfo.screenHeight;
|
||||
if ((COCOSPLAY || ALIPAY) && rotateLandscape && screenWidth < screenHeight) {
|
||||
@@ -142,16 +144,8 @@ class ScreenAdapter extends EventTarget {
|
||||
private _updateResolution () {
|
||||
const windowSize = this.windowSize;
|
||||
// update resolution
|
||||
this._resolution.width = windowSize.width;
|
||||
this._resolution.height = windowSize.height;
|
||||
// NOTE: on Alipay iOS end, the resolution size need forcing to be screenSize * dpr.
|
||||
if (ALIPAY && systemInfo.os === OS.IOS) {
|
||||
this._resolution.width *= this.devicePixelRatio;
|
||||
this._resolution.height *= this.devicePixelRatio;
|
||||
} else {
|
||||
this._resolution.width *= this.resolutionScale;
|
||||
this._resolution.height *= this.resolutionScale;
|
||||
}
|
||||
this._resolution.width = windowSize.width * this.resolutionScale;
|
||||
this._resolution.height = windowSize.height * this.resolutionScale;
|
||||
this._cbToUpdateFrameBuffer?.();
|
||||
this.emit('resolution-change');
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ describe('render-texture', () => {
|
||||
expect(rt.width).toBe(1);
|
||||
expect(rt.height).toBe(1);
|
||||
rt.initialize({ width: 256, height: 256 });
|
||||
rt.setWrapMode(WrapMode.MIRRORED_REPEAT, WrapMode.CLAMP_TO_EDGE);
|
||||
rt.setWrapMode(WrapMode.MIRRORED_REPEAT, WrapMode.CLAMP_TO_EDGE, WrapMode.REPEAT);
|
||||
rt.setFilters(Filter.LINEAR, Filter.NEAREST);
|
||||
expect(rt.getSamplerInfo()).toStrictEqual(new SamplerInfo(GFXFilter.LINEAR, GFXFilter.POINT, GFXFilter.NONE, Address.MIRROR, Address.CLAMP, Address.WRAP, 0));
|
||||
expect(rt.getGFXTexture().width).toBe(256);
|
||||
@@ -31,7 +31,7 @@ describe('render-texture', () => {
|
||||
rt.name = 'test';
|
||||
rt.setAnisotropy(16);
|
||||
rt.setFilters(Filter.NEAREST, Filter.NEAREST);
|
||||
rt.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE);
|
||||
rt.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE);
|
||||
const rtData2 = rt._serialize(null);
|
||||
expect(rtData2).toStrictEqual({ base: '1,1,2,2,0,16', w: 256, h: 128, n: 'test' });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user