Skip to content

Commit

Permalink
feat(GBuff): compressed GBuff data. (#412)
Browse files Browse the repository at this point in the history
* feat: v0.8

add reflection renderer
add reflection sphere
add ibl specular
add ibl diffuse
add lun light
add graphic
fix shadow back
fix passType
fix light parameters.
fix blend mode.
fix Resize Context3D.
fix Csm shadow bias.
Fix: Sample of Grass. Sample of SpotLight.
fix ibl diffuse use SH
Fix: Gtao
Fix: remove SH color.

---------

Co-authored-by: ZenderJK <vvn.plus.site@gmail.com>
Co-authored-by: ShuangLiu <liu.shuang@huasheng.io>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent 7b2169d commit 4649add
Show file tree
Hide file tree
Showing 288 changed files with 10,146 additions and 2,624 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/core",
"version": "0.7.3",
"version": "0.8.0",
"author": "Orillusion",
"description": "Orillusion WebGPU Engine",
"type": "module",
Expand Down
9 changes: 8 additions & 1 deletion packages/debug/GUIHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,16 @@ class _GUIHelp {
}

_addLabel(gui: GUI, label: string) {
GUIHelp._add(gui, { label: label }, 'label');
return GUIHelp._add(gui, { label: label }, 'label');
}

_addLabelValue(gui: GUI, label: string, value: number) {
let obj = {};
obj[label] = value;
return GUIHelp._add(gui, obj, label);
}


_addButton(gui: GUI, label: string, fun: Function) {
var controls = new (function () {
this[label] = fun;
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/grass/shader/GrassBaseShader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export let GrassBaseShader = /*wgsl*/ `
#include "GlobalUniform"
#include "ColorPassFragmentOutput"
#include "FragmentOutput"
#include "ShadingInput"
struct FragmentVarying {
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/grass/shader/GrassCastShadowShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export let GrassCastShadowShader = /* wgsl */`
let grassPivot = localMatrix[3].xyz ;
let bound = materialUniform.windBound ;
let time = TIME.y * 0.001 ;
let time = TIME_time() * 0.001 ;
let cycleTime = sin(time) ;
//sampler wind noise texture by vertex shader
Expand Down
6 changes: 4 additions & 2 deletions packages/effect/grass/shader/GrassShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export let GrassShader = /* wgsl */`
#include "MatrixShader"
#include "BrdfLut_frag"
#include "LightingFunction_frag"
#include "ReflectionCG"
struct MaterialUniform {
baseColor: vec4<f32>,
Expand Down Expand Up @@ -43,6 +44,7 @@ export let GrassShader = /* wgsl */`
const DEGREES_TO_RADIANS : f32 = 3.1415926 / 180.0 ;
const PI : f32 = 3.1415926 ;
const LUMEN = 10.764;
@vertex
fn VertMain( vertex:VertexAttributes ) -> VertexOutput {
Expand All @@ -60,7 +62,7 @@ export let GrassShader = /* wgsl */`
let grassPivot = localMatrix[3].xyz ;
let bound = materialUniform.windBound ;
let time = TIME.y * 0.001 ;
let time = TIME_time() * 0.001 ;
let cycleTime = sin(time) ;
//sampler wind noise texture by vertex shader
Expand Down Expand Up @@ -155,7 +157,7 @@ export let GrassShader = /* wgsl */`
var irradiance = LinearToGammaSpace(globalUniform.skyExposure * textureSampleLevel(prefilterMap, prefilterMapSampler, fragData.N.xyz, 0.8 * (MAX_REFLECTION_LOD) ).rgb);
let specular = vec3<f32>( pow(max(dot(viewDir, reflectDir), 0.0), (1.0 - roughness + 0.001) * 200.0 ) ) * mainLightColor * materialUniform.specular;
var diffuse = color.rgb / PI * grassColor.rgb * shadowStrut.directShadowVisibility[0] ;
var diffuse = color.rgb / PI * grassColor.rgb * directShadowVisibility[0] ;
var finalColor = diffuse + specular + irradiance * grassColor.rgb * sunLight.quadratic;//+ backColor;
ORI_ShadingInput.BaseColor = vec4<f32>(finalColor.rgb,1.0) ;
Expand Down
2 changes: 2 additions & 0 deletions packages/graphic/compute/grass/GrassAnimCompute_cs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export let GrassAnimCompute_cs = /*wgsl*/`
`
66 changes: 66 additions & 0 deletions packages/graphic/compute/grass/GrassGeometryCompute_cs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export let GrassGeometryCompute_cs = /*wgsl*/`
struct GrassNode {
grassCount: f32,
grassHSegment: f32,
grassWight: f32,
grassHeigh: f32,
grassX: f32,
grassY: f32,
grassZ: f32,
grassRotation: f32
}
@group(0) @binding(3) var<storage, read> nodeBuffer : array<GrassNode> ;
var<private> zero_pos : vec3f = vec3f(0.0,0.0,0.0);
var<private> zero_uv : vec2f = vec2f(0.0,0.0);
fn compute(workgroup_id:vec3<u32>,local_invocation_id:vec3<u32>) {
// Grass geometry compute code goes here
var time = globalUniform.time * 0.005;
let globalIndex = workgroup_id.x * 256u + local_invocation_id.x ;
if(globalIndex < drawBuffer.skipFace2 * 12u){
// if(globalIndex == 0u){
// }
let nodeInfo = nodeBuffer[globalIndex];
let posWs = vec3f(nodeInfo.grassX, nodeInfo.grassY, nodeInfo.grassZ) ;
if(IsOutofFrustum(posWs.xyz,0.1)){
// drawCube(globalIndex,posWs,nodeInfo.grassWight,nodeInfo.grassWight,nodeInfo.grassWight,0.0,time,0.0);
let mat = buildYRotateXMat4(nodeInfo.grassRotation,posWs.x, posWs.y, posWs.z);
let vertexOffset = vec4f(sin(time + f32(local_invocation_id.x) / 16.0 ) ,0.0,0.0,0.0);
let width = nodeInfo.grassWight * 0.5 ;
let height = nodeInfo.grassHeigh * 0.5 ;
// var p0 = (mat * vec4f(-width, height, 0.0,1.0)) + vertexOffset;
// var p1 = (mat * vec4f(width, height, 0.0,1.0)) + vertexOffset;
// var p2 = mat * vec4f(width, 0.0, 0.0,1.0) ;
// var p3 = mat * vec4f(-width, 0.0, 0.0,1.0) ;
// let u0 = vec2f(0.0, 0.0);
// let u1 = vec2f(1.0, 0.0);
// let u2 = vec2f(1.0, 1.0);
// let u3 = vec2f(0.0, 1.0);
// drawFace(globalIndex,p0.xyz,p1.xyz,p2.xyz,u0,u1,u2);
// drawFace(globalIndex,p0.xyz,p2.xyz,p3.xyz,u0,u2,u3);
var p0 = (mat * vec4f(width * 0.5, height, 0.0,1.0)) + vertexOffset;
var p1 = (mat * vec4f(-width, 0.0, 0.0,1.0)) ;// + vertexOffset;
var p2 = mat * vec4f(width, 0.0, 0.0,1.0) ;
let u0 = vec2f(0.5, 0.0);
let u1 = vec2f(1.0, 1.0);
let u2 = vec2f(0.0, 1.0);
drawFace(globalIndex,p0.xyz,p1.xyz,p2.xyz,u0,u1,u2);
}else{
// drawCube(globalIndex,zero_pos,0.0,0.0,0.0,0.0,0.0,0.0);
drawFace(globalIndex,zero_pos,zero_pos,zero_pos,zero_uv,zero_uv,zero_uv);
}
}
}
`
4 changes: 2 additions & 2 deletions packages/graphic/compute/shape3d/Path2DShape3DCode_cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ fn drawPath2DCorner(shapeData:Path2DShape3D, currentPoint:Path3DKeyPoint){
var rotateFrom:vec3<f32>;
if(isPositive){
rotateFrom = -prevPoint.right;
rotateMat = buildRotateYMat3(-cornerAngle * 2.0 / f32(cornerPointExt));
rotateMat = buildRotateZ(-cornerAngle * 2.0 / f32(cornerPointExt));
}else{
rotateFrom = prevPoint.right;
rotateMat = buildRotateYMat3(cornerAngle * 2.0 / f32(cornerPointExt));
rotateMat = buildRotateZ(cornerAngle * 2.0 / f32(cornerPointExt));
}
tempV = currentPoint.overallLength - cornerUVLength * lastLengthUVRatio;
Expand Down
5 changes: 4 additions & 1 deletion packages/graphic/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./compute/grass/GrassAnimCompute_cs"
export * from "./compute/grass/GrassGeometryCompute_cs"
export * from "./renderer/GrassRenderer"
export * from "./renderer/Shape3DRenderer"
export * from "./renderer/Shape3DMaker"
export * from "./renderer/shape3d/RoundRectShape3D"
Expand All @@ -8,4 +11,4 @@ export * from "./renderer/shape3d/CurveShape3D"
export * from "./renderer/shape3d/LineShape3D"
export * from "./renderer/shape3d/Shape3D"
export * from "./renderer/shape3d/Path3DShape3D"
export * from "./renderer/shape3d/Path2DShape3D"
export * from "./renderer/shape3d/Path2DShape3D"
2 changes: 1 addition & 1 deletion packages/graphic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
"build:clean": "mv dist/packages/graphic/* dist && rm -rf dist/src && rm -rf dist/packages",
"docs": "npm run docs:typedoc ../../docs/graphic index.ts",
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.cjs --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.js --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
},
"license": "MIT",
"repository": {
Expand Down
36 changes: 36 additions & 0 deletions packages/graphic/renderer/GrassRenderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

import { ComputeShader, DynamicDrawStruct, DynamicFaceRenderer, Struct, graphicDynamicCompute } from "@orillusion/core";
import { GrassGeometryCompute_cs } from "../compute/grass/GrassGeometryCompute_cs";

export class GrassNodeStruct extends DynamicDrawStruct {
grassCount: number = 1;
grassHSegment: number = 1;
grassWight: number = 2;
grassHeigh: number = 4;
grassX: number = 0;
grassY: number = 0;
grassZ: number = 0;
grassRotation: number = 0;
}

export class GrassRenderer extends DynamicFaceRenderer {
grassGeometryCompute: ComputeShader;

constructor() {
super();
}

public init(param?: any): void {
super.init(param);
}

protected createComputeKernel(): void {
console.log("createComputeKernel");


this.grassGeometryCompute = new ComputeShader(graphicDynamicCompute(GrassGeometryCompute_cs));
this.grassGeometryCompute.workerSizeX = Math.floor(this.maxNodeCount / 256) + 1;
// this._onStartKernel.push(this.grassGeometryCompute);
this._onFrameKernelGroup.push(this.grassGeometryCompute);
}
}
2 changes: 1 addition & 1 deletion packages/graphic/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export default defineConfig({
}
}
}
})
})
2 changes: 1 addition & 1 deletion packages/media-extention/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
"build:clean": "mv dist/packages/media-extention/* dist && rm -rf dist/src && rm -rf dist/packages",
"docs": "npm run docs:typedoc ../../docs/media-extention index.ts",
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.cjs --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.js --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
},
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/particle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
"build:clean": "mv dist/packages/particle dist/types && rm -rf dist/src && rm -rf dist/packages",
"docs": "npm run docs:typedoc ../../docs/particle index.ts",
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.cjs --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.js --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
},
"license": "MIT",
"repository": {
Expand Down
102 changes: 51 additions & 51 deletions packages/particle/shader/FastMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@
* @internal
*/
export let FastMath_shader = /* wgsl*/ `
fn sqrtFast( x : f32 ) -> f32
{
var i = i32(x);
i = 0x1FBD1DF5 + (i / 2 );
return f32(i);
}
fn lengthFast( v :vec3<f32> ) -> f32
{
var LengthSqr = dot(v,v);
return sqrtFast( LengthSqr );
}
fn asinFast( x:f32 )-> f32
{
return (0.5 * PI) - acosFast(x);
}
fn acosFast( inX: f32 ) -> f32
{
var x = abs(inX);
var res = -0.156583 * x + (0.5 * PI);
res *= sqrt(1.0 - x);
if(inX >= 0.0){
return res ;
}else{
return PI - res ;
}
}
fn acosFast4( inX : f32 )
{
var x1 = abs(inX);
var x2 = x1 * x1;
var x3 = x2 * x1;
var s;
s = -0.2121144 * x1 + 1.5707288;
s = 0.0742610 * x2 + s;
s = -0.0187293 * x3 + s;
s = sqrt(1.0 - x1) * s;
// acos function mirroring
// check per platform if compiles to a selector - no branch neeeded
if(inX >= 0.0){
return s ;
}else{
return PI - s ;
}
}
// fn sqrtFast( x : f32 ) -> f32
// {
// var i = i32(x);
// i = 0x1FBD1DF5 + (i / 2 );
// return f32(i);
// }
// fn lengthFast( v :vec3<f32> ) -> f32
// {
// var LengthSqr = dot(v,v);
// return sqrtFast( LengthSqr );
// }
// fn asinFast( x:f32 )-> f32
// {
// return (0.5 * PI) - acosFast(x);
// }
// fn acosFast( inX: f32 ) -> f32
// {
// var x = abs(inX);
// var res = -0.156583 * x + (0.5 * PI);
// res *= sqrt(1.0 - x);
// if(inX >= 0.0){
// return res ;
// }else{
// return PI - res ;
// }
// }
// fn acosFast4( inX : f32 )
// {
// var x1 = abs(inX);
// var x2 = x1 * x1;
// var x3 = x2 * x1;
// var s;
// s = -0.2121144 * x1 + 1.5707288;
// s = 0.0742610 * x2 + s;
// s = -0.0187293 * x3 + s;
// s = sqrt(1.0 - x1) * s;
// // acos function mirroring
// // check per platform if compiles to a selector - no branch neeeded
// if(inX >= 0.0){
// return s ;
// }else{
// return PI - s ;
// }
// }
`;
2 changes: 1 addition & 1 deletion packages/stats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.json",
"build:clean": "mv dist/packages/stats/* dist && rm -rf dist/src && rm -rf dist/packages",
"docs": "npm run docs:typedoc ../../docs/stats index.ts",
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.cjs --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --plugin ../../script/typedoc-plugin-not-exported.js --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs true --allReflectionsHaveOwnDocument true --readme none --excludeInternal --excludePrivate --excludeProtected --sort source-order --out"
},
"license": "MIT",
"repository": {
Expand Down
Loading

0 comments on commit 4649add

Please sign in to comment.