forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add grass system fix render pass frame time wrong fix grass segment fix pbr shader fix clear coat lighting specular fix clear coat lighting specular fix grass size and vertex animation fix grass size and vertex animation fix muilt layer clearcoat fix clear coat shader add physic car sample add terrain sample change collect render node add lambert material commit gpu buffer by buffer mapasync fix shadow render node fix point shadow remove ssh chore transform fix fog shader. fix pbr metallic map and ao map add draw call sample fix shadow maping at mac error fix transform notifyLocalChange error fix instanceDraw fix pbr color fix change material not use
- Loading branch information
Showing
102 changed files
with
3,499 additions
and
755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ dist | |
/js | ||
|
||
/.vscode | ||
/.labe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ | |
"vite": "^4.3.9", | ||
"xvfb-maybe": "^0.2.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Transform } from "@orillusion/core"; | ||
|
||
export class GrassNode extends Transform { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { BoundingBox, Color, ComponentBase, GPUPrimitiveTopology, LightingFunction_frag, MeshRenderer, Texture, UnLitMaterial, Vector3, VertexAttributeName } from "@orillusion/core"; | ||
import { GrassMaterial } from "../material/GrassMaterial"; | ||
import { GrassGeometry } from "../geometry/GrassGeometry"; | ||
import { GrassNode } from "../GrassNode"; | ||
|
||
export class GrassComponent extends MeshRenderer { | ||
|
||
|
||
public grassMaterial: GrassMaterial; | ||
public grassGeometry: GrassGeometry; | ||
|
||
constructor() { | ||
super(); | ||
this.grassMaterial = new GrassMaterial(); | ||
this.alwaysRender = true; | ||
} | ||
|
||
public init(param?: any): void { | ||
super.init(); | ||
} | ||
|
||
public setGrass(grassWidth: number, grassHeight: number, segment: number, density: number, count: number = 1000) { | ||
this.grassGeometry = this.geometry = new GrassGeometry(grassWidth, grassHeight, 1, segment, count); | ||
this.material = this.grassMaterial; | ||
// this.material.topology = GPUPrimitiveTopology.line_list; | ||
// this.material = this.grassMaterial; | ||
} | ||
|
||
setWindNoiseTexture(gustNoiseTexture: Texture) { | ||
this.grassMaterial.windMap = gustNoiseTexture; | ||
} | ||
|
||
|
||
public setMinMax(min: Vector3, max: Vector3) { | ||
this.grassGeometry.bounds = new BoundingBox(new Vector3(), new Vector3(1, 1, 1)); | ||
this.grassGeometry.bounds.setFromMinMax(min, max); | ||
} | ||
|
||
public setGrassTexture(grassTexture: Texture) { | ||
this.grassMaterial.baseMap = grassTexture; | ||
} | ||
|
||
public get nodes(): GrassNode[] { | ||
return this.grassGeometry.nodes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { BoundingBox, GeometryBase, Vector3, VertexAttributeName } from "@orillusion/core"; | ||
import { GrassNode } from "../GrassNode"; | ||
|
||
|
||
|
||
|
||
export class GrassGeometry extends GeometryBase { | ||
public width: number; | ||
public height: number; | ||
public segmentW: number; | ||
public segmentH: number; | ||
public nodes: GrassNode[]; | ||
|
||
constructor(width: number, height: number, segmentW: number = 1, segmentH: number = 1, count: number) { | ||
super(); | ||
this.width = width; | ||
this.height = height; | ||
this.segmentW = segmentW; | ||
this.segmentH = segmentH; | ||
this.nodes = []; | ||
this.buildGrass(count); | ||
} | ||
|
||
private buildGrass(count: number) { | ||
var tw: number = this.segmentW + 1; | ||
var singleCont: number = tw * (this.segmentH + 1); | ||
let vertexCount = singleCont * count; | ||
let position_arr = new Float32Array(vertexCount * 3); | ||
let normal_arr = new Float32Array(vertexCount * 3); | ||
let uv_arr = new Float32Array(vertexCount * 2); | ||
let weights_arr = new Float32Array(vertexCount * 4); | ||
let modelID_arr = new Float32Array(vertexCount); | ||
|
||
let faceIndexCount = this.segmentW * this.segmentH * 2 * 3; | ||
let indexes: Uint32Array = new Uint32Array(faceIndexCount * count); | ||
var indexP: number = 0; | ||
var indexN: number = 0; | ||
var indexU: number = 0; | ||
var indexW: number = 0; | ||
var indexI: number = 0; | ||
let numIndices = 0; | ||
let cacheIndex = 0; | ||
|
||
let pi = 3.1415926 * 0.5; | ||
for (let gi = 0; gi < count; gi++) { | ||
let node = new GrassNode(); | ||
this.nodes.push(node); | ||
|
||
let dir = new Vector3(1 * Math.random() - 0.5, 0.0, 1 * Math.random() - 0.5); | ||
let curvature = 0.5 * Math.random(); | ||
|
||
for (var yi: number = 0; yi <= this.segmentH; ++yi) { | ||
for (var xi: number = 0; xi <= this.segmentW; ++xi) { | ||
let weight = yi / this.segmentH; | ||
let x = this.width * (xi / this.segmentW); | ||
let y = this.height * (weight); | ||
position_arr[indexP++] = (x - this.width * 0.5) * (1.0 - weight); | ||
position_arr[indexP++] = 0; | ||
position_arr[indexP++] = 0; | ||
|
||
normal_arr[indexN++] = 0; | ||
normal_arr[indexN++] = 0; | ||
normal_arr[indexN++] = 1; | ||
|
||
uv_arr[indexU++] = xi / this.segmentW; | ||
uv_arr[indexU++] = 1.0 - yi / this.segmentH; | ||
|
||
weights_arr[indexW++] = dir.x; | ||
weights_arr[indexW++] = dir.y; | ||
weights_arr[indexW++] = dir.z; | ||
weights_arr[indexW++] = curvature; | ||
|
||
modelID_arr[indexI++] = node.worldMatrix.index; | ||
} | ||
} | ||
|
||
for (let i = 0; i < this.segmentH; i++) { | ||
for (let j = 0; j < this.segmentW; j++) { | ||
let base = j + i * tw + cacheIndex; | ||
let i1 = (base + 1); | ||
let i2 = base; | ||
let i3 = (base + tw); | ||
|
||
let i4 = (base + 1);; | ||
let i5 = (base + tw); | ||
let i6 = (base + tw + 1); | ||
|
||
indexes[numIndices++] = i1; | ||
indexes[numIndices++] = i2; | ||
indexes[numIndices++] = i3; | ||
indexes[numIndices++] = i4; | ||
indexes[numIndices++] = i5; | ||
indexes[numIndices++] = i6; | ||
} | ||
} | ||
|
||
cacheIndex += singleCont; | ||
} | ||
|
||
this.setIndices(indexes); | ||
this.setAttribute(VertexAttributeName.position, position_arr); | ||
this.setAttribute(VertexAttributeName.normal, normal_arr); | ||
this.setAttribute(VertexAttributeName.uv, uv_arr); | ||
this.setAttribute(VertexAttributeName.TEXCOORD_1, uv_arr); | ||
this.setAttribute(VertexAttributeName.vIndex, modelID_arr); | ||
this.setAttribute(VertexAttributeName.weights0, weights_arr); | ||
|
||
this.addSubGeometry({ | ||
indexStart: 0, | ||
indexCount: indexes.length, | ||
vertexStart: 0, | ||
index: 0, | ||
}); | ||
|
||
this.bounds = new BoundingBox(Vector3.ZERO, new Vector3(9999, 9999, 9999)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import { BlendMode, Color, Engine3D, GPUAddressMode, MaterialBase, MaterialPass, RendererType, ShaderLib, Texture, Vector2, Vector3, Vector4 } from "@orillusion/core"; | ||
import { GrassShader } from "../shader/GrassShader"; | ||
import { GrassVertexAttributeShader } from "../shader/GrassVertexAttributeShader"; | ||
import { GrassCastShadowShader } from "../shader/GrassCastShadowShader"; | ||
|
||
export class GrassMaterial extends MaterialBase { | ||
constructor() { | ||
super(); | ||
|
||
ShaderLib.register("GrassVertexAttributeShader", GrassVertexAttributeShader); | ||
ShaderLib.register("GrassShader", GrassShader); | ||
|
||
let shader = this.setShader(`GrassShader`, `GrassShader`); | ||
shader.setShaderEntry(`VertMain`, `FragMain`) | ||
shader.setDefine("TRANSFORMVERTEX", true); | ||
let shaderState = shader.shaderState; | ||
shaderState.acceptShadow = true; | ||
shaderState.receiveEnv = true; | ||
shaderState.acceptGI = false; | ||
shaderState.useLight = true; | ||
shaderState.castShadow = false; | ||
shaderState.blendMode = BlendMode.NONE; | ||
|
||
ShaderLib.register("GrassCastShadowShader", GrassCastShadowShader); | ||
let shadowPass = new MaterialBase(); | ||
shadowPass.isPassMaterial = true; | ||
let shadowShader = shadowPass.setShader(`GrassCastShadowShader`, `GrassCastShadowShader`); | ||
shadowPass.setDefine("USE_ALPHACUT", true); | ||
shadowPass.setDefine("TRANSFORMVERTEX", true); | ||
shadowShader.setShaderEntry(`VertMain`) | ||
shadowShader.shaderState.blendMode = BlendMode.NONE; | ||
shadowShader.shaderState.receiveEnv = false; | ||
shader.setPassShader(RendererType.SHADOW, shadowPass); | ||
this.addPass(RendererType.SHADOW, shadowPass); | ||
|
||
|
||
shader.setUniformColor("baseColor", new Color(0.0, 1.0, 0.0, 1.0)); | ||
shader.setUniformColor("grassBottomColor", new Color(3 / 255, 16 / 255, 3 / 255)); | ||
shader.setUniformColor("grassTopColor", new Color(45 / 255, 154 / 255, 74 / 255, 1.0)); | ||
shader.setUniformColor("materialF0", new Color(0.04, 0.04, 0.04, 1.0 - 0.04)); | ||
shader.setUniformVector4("windBound", new Vector4(0, 0, 2000, 2000)); | ||
shader.setUniformVector2("windDirection", new Vector2(0.6, 0.8)); | ||
shader.setUniformFloat("windPower", 0.8); | ||
shader.setUniformFloat("windSpeed", 12); | ||
shader.setUniformFloat("translucent", 0.35); | ||
shader.setUniformFloat("roughness", 0.35); | ||
shader.setUniformFloat("curvature", 0.4068); | ||
shader.setUniformFloat("grassHeight", 10); | ||
shader.setUniformFloat("soft", 5); | ||
shader.setUniformFloat("specular", 0.15); | ||
|
||
shadowShader.setUniformColor("baseColor", new Color(0.0, 1.0, 0.0, 1.0)); | ||
shadowShader.setUniformColor("grassBottomColor", new Color(39 / 255, 87 / 255, 36 / 255)); | ||
shadowShader.setUniformColor("grassTopColor", new Color(74 / 255, 163 / 255, 93 / 255, 1.0)); | ||
shadowShader.setUniformColor("materialF0", new Color(0.04, 0.04, 0.04, 1.0 - 0.04)); | ||
shadowShader.setUniformVector4("windBound", new Vector4(0, 0, 2000, 2000)); | ||
shadowShader.setUniformVector2("windDirection", new Vector2(0.6, 0.8)); | ||
shadowShader.setUniformFloat("windPower", 0.8); | ||
shadowShader.setUniformFloat("windSpeed", 10); | ||
shadowShader.setUniformFloat("translucent", 0.35); | ||
shadowShader.setUniformFloat("roughness", 0.35); | ||
shadowShader.setUniformFloat("curvature", 0.4068); | ||
shadowShader.setUniformFloat("grassHeight", 10); | ||
shadowShader.setUniformFloat("soft", 5); | ||
shadowShader.setUniformFloat("specular", 0.15); | ||
|
||
// default value | ||
// this.baseMap = Engine3D.res.whiteTexture; | ||
this.doubleSide = true; | ||
shadowPass.doubleSide = true; | ||
} | ||
|
||
public set baseMap(texture: Texture) { | ||
texture.visibility = GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT; | ||
super.baseMap = texture; | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.baseMap = texture; | ||
} | ||
|
||
public get baseMap(): Texture { | ||
return super.baseMap; | ||
} | ||
|
||
public set windMap(texture: Texture) { | ||
texture.visibility = GPUShaderStage.VERTEX; | ||
texture.addressModeU = GPUAddressMode.repeat; | ||
texture.addressModeV = GPUAddressMode.repeat; | ||
this.renderShader.setTexture("windMap", texture); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setTexture("windMap", texture); | ||
} | ||
|
||
public set windBound(v: Vector4) { | ||
this.renderShader.setUniformVector4("windBound", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformVector4("windBound", v); | ||
} | ||
|
||
public get windBound(): Vector4 { | ||
return this.renderShader.uniforms["windBound"].vector4; | ||
} | ||
|
||
public set grassBaseColor(v: Color) { | ||
this.renderShader.setUniformColor("grassBottomColor", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformColor("grassBottomColor", v); | ||
} | ||
|
||
public get grassBaseColor(): Color { | ||
return this.renderShader.uniforms["grassBottomColor"].color; | ||
} | ||
|
||
public set grassTopColor(v: Color) { | ||
this.renderShader.setUniformColor("grassTopColor", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformColor("grassTopColor", v); | ||
} | ||
|
||
public get grassTopColor(): Color { | ||
return this.renderShader.uniforms["grassTopColor"].color; | ||
} | ||
|
||
public set windDirection(v: Vector2) { | ||
this.renderShader.setUniformVector2("windDirection", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformVector2("windDirection", v); | ||
} | ||
|
||
public get windDirection(): Vector2 { | ||
return this.renderShader.uniforms["windDirection"].vector2; | ||
} | ||
|
||
public set windPower(v: number) { | ||
this.renderShader.setUniformFloat("windPower", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("windPower", v); | ||
} | ||
|
||
public get windPower(): number { | ||
return this.renderShader.uniforms["windPower"].data; | ||
} | ||
|
||
public set windSpeed(v: number) { | ||
this.renderShader.setUniformFloat("windSpeed", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("windSpeed", v); | ||
} | ||
|
||
public get windSpeed(): number { | ||
return this.renderShader.uniforms["windSpeed"].data; | ||
} | ||
|
||
public set grassHeight(v: number) { | ||
this.renderShader.setUniformFloat("grassHeight", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("grassHeight", v); | ||
} | ||
|
||
public get grassHeight(): number { | ||
return this.renderShader.uniforms["grassHeight"].data; | ||
} | ||
|
||
public set curvature(v: number) { | ||
this.renderShader.setUniformFloat("curvature", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("curvature", v); | ||
} | ||
|
||
public get curvature(): number { | ||
return this.renderShader.uniforms["curvature"].data; | ||
} | ||
|
||
public set roughness(v: number) { | ||
this.renderShader.setUniformFloat("roughness", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("roughness", v); | ||
} | ||
|
||
public get roughness(): number { | ||
return this.renderShader.uniforms["roughness"].data; | ||
} | ||
|
||
public set translucent(v: number) { | ||
this.renderShader.setUniformFloat("translucent", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("translucent", v); | ||
} | ||
|
||
public get translucent(): number { | ||
return this.renderShader.uniforms["translucent"].data; | ||
} | ||
|
||
public set soft(v: number) { | ||
this.renderShader.setUniformFloat("soft", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("soft", v); | ||
} | ||
|
||
public get soft(): number { | ||
return this.renderShader.uniforms["soft"].data; | ||
} | ||
|
||
public set specular(v: number) { | ||
this.renderShader.setUniformFloat("specular", v); | ||
let shadowShader = this.renderShader.getPassShader(RendererType.SHADOW); | ||
shadowShader.renderShader.setUniformFloat("specular", v); | ||
} | ||
|
||
public get specular(): number { | ||
return this.renderShader.uniforms["specular"].data; | ||
} | ||
} |
Oops, something went wrong.