high precision calculation in standard shader has been moved into cpu

This commit is contained in:
jerrywwl
2019-04-17 14:40:01 +08:00
parent a568f5adb0
commit 7c540554d7
4 changed files with 54 additions and 42 deletions
+20 -17
View File
File diff suppressed because one or more lines are too long
+12 -13
View File
@@ -136,24 +136,20 @@ export class ForwardPipeline extends RenderPipeline {
protected updateUBOs (view: RenderView) {
super.updateUBOs(view);
const exposure = view.camera.exposure;
for (let i = 0; i < this._renderObjects.length; i++) {
this._uboLights.view.fill(0);
const nextLightIndex = i + 1 < this._renderObjects.length ? this._lightIndexOffset[i + 1] : this._lightIndices.length;
if (!this._renderObjects[i].model.localBindings.get(UBOForwardLight.BLOCK.name)) {
continue;
}
const dirNum = 0;
let sphereNum = 0;
let spotNum = 0;
for (let l = this._lightIndexOffset[i]; l < nextLightIndex; l++) {
const light = this._validLights[this._lightIndices[l]];
if (light && light.enabled) {
switch (light.type) {
// case LightType.DIRECTIONAL:
// this._uboLights.view.set((light as DirectionalLight).directionArray, UBOForwardLight.DIR_LIGHT_DIR_OFFSET + dirNum * 4);
// this._uboLights.view.set(light.color, UBOForwardLight.DIR_LIGHT_COLOR_OFFSET + dirNum * 4);
// dirNum++;
// break;
case LightType.SPHERE:
if (sphereNum >= UBOForwardLight.MAX_SPHERE_LIGHTS) {
continue;
@@ -176,6 +172,11 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[2] *= tempRGB.z;
}
_vec4Array[3] = sphereLit.luminance * this._lightMeterScale;
if (this._isHDR) {
_vec4Array[3] = sphereLit.luminance * this._fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = sphereLit.luminance * exposure * this._lightMeterScale;
}
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPHERE_LIGHT_COLOR_OFFSET + sphereNum * 4);
sphereNum++;
break;
@@ -205,7 +206,11 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[1] *= tempRGB.y;
_vec4Array[2] *= tempRGB.z;
}
_vec4Array[3] = spotLit.luminance * this._lightMeterScale;
if (this._isHDR) {
_vec4Array[3] = spotLit.luminance * this._fpScale * this._lightMeterScale;
} else {
_vec4Array[3] = spotLit.luminance * exposure * this._lightMeterScale;
}
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPOT_LIGHT_COLOR_OFFSET + spotNum * 4);
spotNum++;
break;
@@ -220,12 +225,6 @@ export class ForwardPipeline extends RenderPipeline {
protected sceneCulling (view: RenderView) {
super.sceneCulling(view);
this._validLights.splice(0);
// for (const light of view.camera.scene.directionalLights) {
// if (light.enabled) {
// light.update();
// this._validLights.push(light);
// }
// }
for (const light of view.camera.scene.sphereLights) {
if (light.enabled) {
light.update();
+1 -1
View File
@@ -110,7 +110,7 @@ export class ForwardStage extends RenderStage {
colors[0] = camera.clearColor;
if (this._pipeline.isHDR) {
colors[0] = SRGBToLinear(colors[0]);
const scale = 1.0 / (camera.exposure * this._pipeline.fpScaleInv);
const scale = this._pipeline.fpScale / camera.exposure;
colors[0].r *= scale;
colors[0].g *= scale;
colors[0].b *= scale;
+21 -11
View File
@@ -322,7 +322,7 @@ export abstract class RenderPipeline {
this._usePostProcess = info.enablePostProcess;
} else {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
this._usePostProcess = false;
this._usePostProcess = true;
} else {
this._usePostProcess = true;
}
@@ -739,7 +739,7 @@ export abstract class RenderPipeline {
}
protected updateMacros () {
this._macros.CC_USE_HDR = this._isHDR;
this._macros.CC_USE_HDR = (this._isHDR);
programLib.destroyShaderByDefines(this._macros);
for (const scene of this._root.scenes) {
scene.onPipelineChange();
@@ -939,10 +939,11 @@ export abstract class RenderPipeline {
_vec4Array[3] = 1.0;
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET);
_vec4Array[0] = camera.exposure;
_vec4Array[1] = 1.0 / _vec4Array[0];
const exposure = camera.exposure;
_vec4Array[0] = exposure;
_vec4Array[1] = 1.0 / exposure;
_vec4Array[2] = this._isHDR ? 1.0 : 0.0;
_vec4Array[3] = _vec4Array[1] * this._fpScale;
_vec4Array[3] = this._fpScale / exposure;
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET);
vec3.array(_vec4Array, mainLight.direction);
@@ -951,19 +952,28 @@ export abstract class RenderPipeline {
if (mainLight.enabled) {
vec3.array(_vec4Array, mainLight.color);
if (mainLight.useColorTemperature) {
const tempRGB = mainLight.colorTemperatureRGB;
_vec4Array[0] *= tempRGB.x;
_vec4Array[1] *= tempRGB.y;
_vec4Array[2] *= tempRGB.z;
const colorTempRGB = mainLight.colorTemperatureRGB;
_vec4Array[0] *= colorTempRGB.x;
_vec4Array[1] *= colorTempRGB.y;
_vec4Array[2] *= colorTempRGB.z;
}
if (this._isHDR) {
_vec4Array[3] = mainLight.illuminance * this._fpScale;
} else {
_vec4Array[3] = mainLight.illuminance * exposure;
}
_vec4Array[3] = mainLight.illuminance;
} else {
_vec4Array.set(_vec4ArrayZero);
}
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
_vec4Array.set(ambient.skyColor);
_vec4Array[3] = ambient.skyIllum;
if (this._isHDR) {
_vec4Array[3] = ambient.skyIllum * this._fpScale;
} else {
_vec4Array[3] = ambient.skyIllum * exposure;
}
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_SKY_OFFSET);
_vec4Array.set(ambient.groundAlbedo);