Skip to content

Commit

Permalink
fix(bloom): fix bloom uniform data offset
Browse files Browse the repository at this point in the history
fix bloom uniform data offset
  • Loading branch information
ZenderJK committed Sep 6, 2023
1 parent 1cc1515 commit 39819ee
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 165 deletions.
4 changes: 3 additions & 1 deletion samples/base/Sample_AddRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Sample_AddRemove {
clone.transform.x = Math.random() * 100 - 50;
clone.transform.y = Math.random() * 100 - 50;
clone.transform.z = Math.random() * 100 - 50;
clone.transform.localScale.set(20, 20, 20)
clone.transform.scaleX = 20;
clone.transform.scaleY = 20;
clone.transform.scaleZ = 20;

this.view.scene.addChild(clone);
list.push(clone);
Expand Down
1 change: 1 addition & 0 deletions samples/material/Sample_ChangeMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Sample_ChangeMaterial {
blurX: 4,
blurY: 4,
luminosityThreshold: 0.8,
exposure: 1,
strength: 0.86,
radius: 4,
debug: false
Expand Down
1 change: 1 addition & 0 deletions samples/material/Sample_ClearCoat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Sample_ClearCoat {
enable: true,
blurX: 4,
blurY: 4,
exposure: 1,
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
Expand Down
9 changes: 8 additions & 1 deletion samples/material/Sample_PBRMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ class Sample_PBRMaterial {
scene: Scene3D;

async run() {
await Engine3D.init({ canvasConfig: { alpha: true, zIndex: 11, backgroundImage: '/logo/bg.webp' } });

//config settings
Engine3D.setting.render.debug = true;
Engine3D.setting.shadow.shadowBound = 50;
Engine3D.setting.render.postProcessing.bloom = {
enable: true,
blurX: 4,
blurY: 4,
luminosityThreshold: 0.8,
strength: 0.86,
exposure: 1,
radius: 4,
debug: false
};

await Engine3D.init({ canvasConfig: { alpha: true, zIndex: 11, backgroundImage: '/logo/bg.webp' } });

GUIHelp.init(999);

this.scene = new Scene3D();
Expand All @@ -35,6 +38,8 @@ class Sample_PBRMaterial {

Engine3D.startRenderView(view);
await this.initScene();

GUIUtil.renderDebug();
}

async initScene() {
Expand Down Expand Up @@ -67,6 +72,8 @@ class Sample_PBRMaterial {
let material = item.material;
if (material instanceof LitMaterial) {
material.metallic = 1;
material.roughness = 0.35;
material.defaultPass.setDefine("USE_TANGENT", false);
}
}
model.transform.scaleX = 10;
Expand Down
1 change: 1 addition & 0 deletions samples/material/Sample_UVMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Sample_UVMove {
enable: true,
blurX: 4,
blurY: 4,
exposure: 1,
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
Expand Down
29 changes: 9 additions & 20 deletions samples/post/Sample_Bloom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
CameraUtil, webGPUContext, BoxGeometry, TAAPost, AtmosphericComponent, GTAOPost, Color, HDRBloomPost
} from '@orillusion/core';
import { GUIHelp } from '@orillusion/debug/GUIHelp';
import { GUI } from '@orillusion/debug/dat.gui.module';
import { GUIUtil } from '@samples/utils/GUIUtil';

class Sample_Bloom {
lightObj: Object3D;
Expand Down Expand Up @@ -35,11 +37,13 @@ class Sample_Bloom {

let postProcessing = this.scene.addComponent(PostProcessingComponent);
let post = postProcessing.addPost(HDRBloomPost);
post.blurX = 4;
post.blurY = 4;
post.luminosityThreshold = 1.5;
post.strength = 4.0;
this.gui();
post.blurX = 5;
post.blurY = 5;
post.luminosityThreshold = 1.1;
post.strength = 1.0;

GUIHelp.init();
GUIUtil.renderBloom(post, true);
}

async initScene() {
Expand Down Expand Up @@ -131,21 +135,6 @@ class Sample_Bloom {
}
}
}

private gui() {
GUIHelp.init();
let postProcessing = this.scene.getComponent(PostProcessingComponent);
let post = postProcessing.getPost(HDRBloomPost);

GUIHelp.addFolder("Bloom");
GUIHelp.add(post, "blurX", 0.0, 5, 1);
GUIHelp.add(post, "blurY", 0.0, 5, 1);
GUIHelp.add(post, "radius", 0.0, 5, 1);
GUIHelp.add(post, "luminosityThreshold", 0.0, 5, 0.001);
GUIHelp.add(post, "strength", 0.0, 10, 0.001);
GUIHelp.endFolder();
}

}

new Sample_Bloom().run();
9 changes: 5 additions & 4 deletions samples/utils/GUIUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export class GUIUtil {
GUIHelp.add(bloom, 'enable');
GUIHelp.addColor(bloom, 'tintColor');
GUIHelp.add(bloom, 'luminosityThreshold');
GUIHelp.add(bloom, 'strength');
GUIHelp.add(bloom, 'radius');
GUIHelp.add(bloom, 'strength', 0, 3, 0.001);
GUIHelp.add(bloom, 'exposure');
GUIHelp.add(bloom, 'radius', 0, 1.0, 0.001);
GUIHelp.add(bloom, 'blurX');
GUIHelp.add(bloom, 'blurY');
open && GUIHelp.open();
Expand Down Expand Up @@ -376,9 +377,9 @@ export class GUIUtil {
let debugChanel = {
PositionView: 0,
ColorView: 1,
NormalView: 2,
normalView: 2,
IrradianceView: 3,
LightView: 4,
tangentView: 4,
FinalView: 5,
EmissiveView: 6,
specularRadiance: 7,
Expand Down
1 change: 1 addition & 0 deletions src/Engine3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class Engine3D {
blurX: 4,
blurY: 4,
strength: 0.25,
exposure: 1,
radius: 1.3,
luminosityThreshold: 0.98,
debug: false,
Expand Down
2 changes: 1 addition & 1 deletion src/assets/shader/lighting/BxDF_frag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export let BxDF_frag: string = /*wgsl*/ `
fragData.Irradiance = LinearToGammaSpace(irradiance.rgb) ;
#if USE_TANGENT
fragData.TangentChannel = ORI_VertexVarying.TANGENT.xyz * ORI_VertexVarying.TANGENT.w ;
fragData.TangentChannel = vec3<f32>(ORI_VertexVarying.TANGENT.w);// ORI_VertexVarying.TANGENT.xyz * ORI_VertexVarying.TANGENT.w ;
#endif
//***********lighting-PBR part*********
Expand Down
2 changes: 1 addition & 1 deletion src/assets/shader/materials/PBRLItShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export let PBRLItShader: string = /*wgsl*/ `
ORI_ShadingInput.Roughness = clamp(ORI_ShadingInput.Roughness,0.084,1.0);
ORI_ShadingInput.Specular = 0.5 ;
var emissiveColor = textureSample(emissiveMap, emissiveMapSampler , ORI_VertexVarying.fragUV1.xy) ;
var emissiveColor = textureSample(emissiveMap, emissiveMapSampler , ORI_VertexVarying.fragUV0.xy) ;
emissiveColor = vec4<f32>(gammaToLiner(emissiveColor.rgb),emissiveColor.w);
ORI_ShadingInput.EmissiveColor = vec4<f32>(materialUniform.emissiveColor.rgb * emissiveColor.rgb * materialUniform.emissiveIntensity,1.0);
Expand Down
4 changes: 2 additions & 2 deletions src/assets/shader/materials/program/BxdfDebug_frag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export let BxdfDebug_frag: string = /*wgsl*/ `
debugIrradiance();
}
case 4: {
debugDiffuse();
debugTangent();
}
case 5: {
// debugTangent();
Expand Down Expand Up @@ -140,7 +140,7 @@ export let BxdfDebug_frag: string = /*wgsl*/ `
debugIrradiance();
}
case 4: {
debugDiffuse();
debugTangent();
}
case 5: {
// debugTangent();
Expand Down
2 changes: 2 additions & 0 deletions src/assets/shader/materials/program/NormalMap_frag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export let NormalMap_frag: string = /*wgsl*/ `
var N = surf_norm;
var q1perp = cross( q1, N );
var q0perp = cross( N, q0 );
#if USE_TANGENT
var T = ORI_VertexVarying.TANGENT.xyz ;
#else
var T = q1perp * st0.x + q0perp * st1.x;
#endif
var B = q1perp * st0.y + q0perp * st1.y;
var det = max( dot( T, T ), dot( B, B ) );
Expand Down

0 comments on commit 39819ee

Please sign in to comment.