fix skybox update (#5529)

This commit is contained in:
Yun Hsiao Wu
2019-10-13 15:26:31 +08:00
committed by pandamicro
parent dca0b0cf72
commit da629db464
5 changed files with 37 additions and 29 deletions
File diff suppressed because one or more lines are too long
+4
View File
@@ -58,6 +58,10 @@ export class SimpleTexture extends TextureBase {
protected _gfxTextureView: GFXTextureView | null = null;
private _mipmapLevel = 1;
get mipmapLevel () {
return this._mipmapLevel;
}
/**
* 获取此贴图底层的 GFX 贴图对象。
*/
+1 -1
View File
@@ -54,7 +54,7 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
gpuRenderPass: (info.renderPass as WebGLGFXRenderPass).gpuRenderPass,
gpuColorViews: [],
gpuDepthStencilView: null,
isOffscreen: info.isOffscreen,
isOffscreen: false,
glFramebuffer: null,
};
}
+22 -20
View File
@@ -12,36 +12,33 @@ export class Skybox extends Model {
set useIBL (val) {
this._useIBL = val;
const pipeline = this._scene.root.pipeline;
if (!!pipeline.macros.CC_USE_IBL === val) { return; }
pipeline.macros.CC_USE_IBL = val;
this._scene.onPipelineChange();
this._updateGlobalBinding();
this._updatePipeline();
}
get useIBL () {
return this._useIBL;
}
set envmap (val: TextureCube | null) {
const newEnvmap = val || this._default;
this._envmap = newEnvmap;
this._updateGlobalBinding();
}
get envmap () {
return this._envmap;
}
set isRGBE (val: boolean) {
if (val === this._isRGBE) { return; }
set isRGBE (val) {
this._isRGBE = val;
this._material.recompileShaders({ USE_RGBE_CUBEMAP: this._isRGBE });
this.setSubModelMaterial(0, this._material);
this._updateGlobalBinding();
this._updatePipeline();
}
get isRGBE () {
return this._isRGBE;
}
set envmap (val: TextureCube | null) {
const newEnvmap = val || this._default;
this._envmap = newEnvmap;
this._scene.ambient.groundAlbedo[3] = this._envmap.mipmapLevel;
this._updateGlobalBinding();
}
get envmap () {
return this._envmap;
}
protected _default = builtinResMgr.get<TextureCube>('default-cube-texture');
protected _envmap = this._default;
protected _isRGBE = false;
@@ -53,10 +50,7 @@ export class Skybox extends Model {
constructor (scene: RenderScene) {
super(scene, null!);
this._scene = scene;
this._material.initialize({
effectName: 'pipeline/skybox',
defines: { USE_RGBE_CUBEMAP: this._isRGBE },
});
this._material.initialize({ effectName: 'pipeline/skybox', defines: { USE_RGBE_CUBEMAP: this._isRGBE } });
this._globalBinding = this._scene.root.pipeline.globalBindings.get(UNIFORM_ENVIRONMENT.name)!;
const mesh = createMesh(box({ width: 2, height: 2, length: 2 }));
@@ -64,6 +58,14 @@ export class Skybox extends Model {
this.initSubModel(0, subMeshData, this._material);
}
protected _updatePipeline () {
const value = this._useIBL ? this._isRGBE ? 2 : 1 : 0;
const pipeline = this._scene.root.pipeline;
if (pipeline.macros.CC_USE_IBL === value) { return; }
pipeline.macros.CC_USE_IBL = value;
this._scene.onPipelineChange();
}
protected _updateGlobalBinding () {
const textureView = this._envmap.getGFXTextureView()!;
const sampler = samplerLib.getSampler(this._device, this._envmap.getSamplerHash());
+2 -1
View File
@@ -85,7 +85,8 @@ export class AmbientInfo {
@property({ type: Color })
set groundAlbedo (val: Color) {
this._groundAlbedo.set(val);
if (this._resource) { Color.toArray(this._resource.groundAlbedo, this.groundAlbedo); }
// only RGB channels are used, alpha channel are intensionally left unchanged here
if (this._resource) { Vec3.toArray(this._resource.groundAlbedo, this.groundAlbedo); }
}
get groundAlbedo () {
return this._groundAlbedo;