mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
samplers can be specified in effect too (#4066)
This commit is contained in:
committed by
Weiliang Wang
parent
bcede42719
commit
fdafb1e52a
@@ -10,7 +10,7 @@ export interface IPropertyInfo {
|
||||
type: number; // auto-extracted if not specified
|
||||
value?: number[] | string;
|
||||
displayName?: string;
|
||||
sampler?: IGFXSamplerInfo;
|
||||
sampler?: number[];
|
||||
}
|
||||
export interface IPassStates {
|
||||
priority?: number;
|
||||
|
||||
Vendored
+42
-94
File diff suppressed because one or more lines are too long
@@ -32,6 +32,7 @@ import { GFXAddress, GFXBufferTextureCopy, GFXFilter, GFXFormat,
|
||||
import { GFXDevice } from '../gfx/device';
|
||||
import { GFXTexture, IGFXTextureInfo } from '../gfx/texture';
|
||||
import { GFXTextureView, IGFXTextureViewInfo } from '../gfx/texture-view';
|
||||
import { SamplerInfoIndex } from '../renderer/core/sampler-lib';
|
||||
import { Asset } from './asset';
|
||||
import { ImageAsset } from './image-asset';
|
||||
|
||||
@@ -313,10 +314,10 @@ export class TextureBase extends EventTargetFactory(Asset) {
|
||||
* @param wrapR
|
||||
*/
|
||||
public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) {
|
||||
if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[3] = wrapS; }
|
||||
if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[4] = wrapT; }
|
||||
if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[SamplerInfoIndex.addressU] = wrapS; }
|
||||
if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[SamplerInfoIndex.addressV] = wrapT; }
|
||||
if (wrapR === undefined) { return; }
|
||||
if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[5] = wrapR; }
|
||||
if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[SamplerInfoIndex.addressW] = wrapR; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,8 +327,8 @@ export class TextureBase extends EventTargetFactory(Asset) {
|
||||
* @param magFilter
|
||||
*/
|
||||
public setFilters (minFilter: Filter, magFilter: Filter) {
|
||||
if (minFilter !== this._minFilter) { this._minFilter = minFilter; this._samplerInfo[0] = minFilter; }
|
||||
if (magFilter !== this._magFilter) { this._magFilter = magFilter; this._samplerInfo[1] = magFilter; }
|
||||
if (minFilter !== this._minFilter) { this._minFilter = minFilter; this._samplerInfo[SamplerInfoIndex.minFilter] = minFilter; }
|
||||
if (magFilter !== this._magFilter) { this._magFilter = magFilter; this._samplerInfo[SamplerInfoIndex.magFilter] = magFilter; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +337,7 @@ export class TextureBase extends EventTargetFactory(Asset) {
|
||||
* @param mipFilter
|
||||
*/
|
||||
public setMipFilter (mipFilter: Filter) {
|
||||
if (mipFilter !== this._mipFilter) { this._mipFilter = mipFilter; this._samplerInfo[2] = mipFilter; }
|
||||
if (mipFilter !== this._mipFilter) { this._mipFilter = mipFilter; this._samplerInfo[SamplerInfoIndex.mipFilter] = mipFilter; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +366,7 @@ export class TextureBase extends EventTargetFactory(Asset) {
|
||||
* @param anisotropy
|
||||
*/
|
||||
public setAnisotropy (anisotropy: number) {
|
||||
if (anisotropy !== this._anisotropy) { this._anisotropy = anisotropy; this._samplerInfo[6] = anisotropy; }
|
||||
if (anisotropy !== this._anisotropy) { this._anisotropy = anisotropy; this._samplerInfo[SamplerInfoIndex.maxAnisotropy] = anisotropy; }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -172,11 +172,13 @@ export class Pass {
|
||||
for (const u of shaderInfo.samplers) {
|
||||
this._handleMap[u.name] = genHandle(GFXBindingType.SAMPLER, u.type, u.binding);
|
||||
const inf = info.properties && info.properties[u.name];
|
||||
if (inf && inf.sampler) { this._samplers[u.binding] = samplerLib.getSampler(device, inf.sampler); }
|
||||
const texName = inf && inf.value ? inf.value + '-texture' : _type2default[u.type];
|
||||
const texture = builtinResMgr.get<TextureBase>(texName);
|
||||
if (texture) {
|
||||
this._textureViews[u.binding] = texture.getGFXTextureView()!;
|
||||
this._samplers[u.binding] = samplerLib.getSampler(device, texture.getGFXSamplerInfo());
|
||||
const samplerInfo = texture.getGFXSamplerInfo();
|
||||
if (!this._samplers[u.binding] || samplerInfo.length) { this._samplers[u.binding] = samplerLib.getSampler(device, samplerInfo); }
|
||||
}
|
||||
else { console.warn('illegal texture default value ' + texName); }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { GFXSampler, IGFXSamplerInfo } from '../../gfx/sampler';
|
||||
|
||||
export enum SamplerInfoIndex {
|
||||
minFilter,
|
||||
magFilter,
|
||||
mipFilter,
|
||||
addressU,
|
||||
addressV,
|
||||
addressW,
|
||||
maxAnisotropy,
|
||||
cmpFunc,
|
||||
minLOD,
|
||||
maxLOD,
|
||||
mipLODBias,
|
||||
borderColor,
|
||||
total = borderColor + 4,
|
||||
}
|
||||
|
||||
const gfxInfo: IGFXSamplerInfo = {};
|
||||
|
||||
class SamplerLib {
|
||||
@@ -12,19 +28,22 @@ class SamplerLib {
|
||||
const hash = info.toString();
|
||||
const cache = this._cache[hash];
|
||||
if (cache) { return cache; }
|
||||
gfxInfo.minFilter = info[0];
|
||||
gfxInfo.magFilter = info[1];
|
||||
gfxInfo.mipFilter = info[2];
|
||||
gfxInfo.addressU = info[3];
|
||||
gfxInfo.addressV = info[4];
|
||||
gfxInfo.addressW = info[5];
|
||||
gfxInfo.maxAnisotropy = info[6];
|
||||
if (info.length > 7) {
|
||||
gfxInfo.cmpFunc = info[7];
|
||||
gfxInfo.borderColor = { r: info[8], g: info[9], b: info[10], a: info[11] };
|
||||
gfxInfo.minLOD = info[12];
|
||||
gfxInfo.maxLOD = info[13];
|
||||
gfxInfo.mipLODBias = info[14];
|
||||
gfxInfo.minFilter = info[SamplerInfoIndex.minFilter];
|
||||
gfxInfo.magFilter = info[SamplerInfoIndex.magFilter];
|
||||
gfxInfo.mipFilter = info[SamplerInfoIndex.mipFilter];
|
||||
gfxInfo.addressU = info[SamplerInfoIndex.addressU];
|
||||
gfxInfo.addressV = info[SamplerInfoIndex.addressV];
|
||||
gfxInfo.addressW = info[SamplerInfoIndex.addressW];
|
||||
gfxInfo.maxAnisotropy = info[SamplerInfoIndex.maxAnisotropy];
|
||||
if (info.length > SamplerInfoIndex.cmpFunc) {
|
||||
gfxInfo.cmpFunc = info[SamplerInfoIndex.cmpFunc];
|
||||
gfxInfo.minLOD = info[SamplerInfoIndex.minLOD];
|
||||
gfxInfo.maxLOD = info[SamplerInfoIndex.maxLOD];
|
||||
gfxInfo.mipLODBias = info[SamplerInfoIndex.mipLODBias];
|
||||
if (info.length >= SamplerInfoIndex.total) {
|
||||
const ofs = SamplerInfoIndex.borderColor;
|
||||
gfxInfo.borderColor = { r: info[ofs], g: info[ofs + 1], b: info[ofs + 2], a: info[ofs + 3] };
|
||||
}
|
||||
}
|
||||
const sampler = this._cache[hash] = device.createSampler(gfxInfo);
|
||||
return sampler;
|
||||
@@ -32,4 +51,3 @@ class SamplerLib {
|
||||
}
|
||||
|
||||
export const samplerLib = new SamplerLib();
|
||||
cc.samplerLib = samplerLib;
|
||||
|
||||
@@ -7,6 +7,10 @@ export { addStage };
|
||||
export { RenderQueue, PassStage } from './core/constants';
|
||||
export { Pass } from './core/pass';
|
||||
export { Effect } from './core/effect';
|
||||
export { programLib } from './core/program-lib';
|
||||
import { samplerLib } from './core/sampler-lib';
|
||||
cc.samplerLib = samplerLib;
|
||||
export { samplerLib };
|
||||
|
||||
export { Light } from './scene/light';
|
||||
export { Camera } from './scene/camera';
|
||||
|
||||
@@ -21,7 +21,7 @@ export class Skybox extends Model {
|
||||
if (val === this._isRGBE) { return; }
|
||||
this._isRGBE = val;
|
||||
this._material.destroy();
|
||||
this._material.initialize({ defines: { USE_RGBE_CUBEMAP: val } });
|
||||
this._initMaterial();
|
||||
this.setSubModelMaterial(0, this._material);
|
||||
this._updateBindingLayout();
|
||||
}
|
||||
@@ -33,18 +33,12 @@ export class Skybox extends Model {
|
||||
protected _cubemap = this._default;
|
||||
protected _isRGBE = false;
|
||||
|
||||
protected _material: Material;
|
||||
protected _material = new Material();
|
||||
|
||||
constructor (scene: RenderScene) {
|
||||
super(scene, null);
|
||||
this._scene = scene;
|
||||
|
||||
this._material = new Material();
|
||||
this._material.initialize({
|
||||
effectName: 'builtin-skybox',
|
||||
defines: { USE_RGBE_CUBEMAP: this._isRGBE },
|
||||
});
|
||||
this._material.setProperty('cubeMap', this._cubemap);
|
||||
this._initMaterial();
|
||||
|
||||
const mesh = createMesh(box({ width: 2, height: 2, length: 2 }));
|
||||
const subMeshData = mesh.renderingMesh!.getSubmesh(0)!;
|
||||
@@ -52,6 +46,14 @@ export class Skybox extends Model {
|
||||
this._updateBindingLayout();
|
||||
}
|
||||
|
||||
protected _initMaterial () {
|
||||
this._material.initialize({
|
||||
effectName: 'builtin-skybox',
|
||||
defines: { USE_RGBE_CUBEMAP: this._isRGBE },
|
||||
});
|
||||
this._material.setProperty('cubeMap', this._cubemap);
|
||||
}
|
||||
|
||||
protected _updateBindingLayout () {
|
||||
this._matPSORecord.get(this._material)![0].pipelineLayout.layouts[0].update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user