Skip to content

Commit

Permalink
fix(effect): fix grass get uniform data
Browse files Browse the repository at this point in the history
  • Loading branch information
lslzl3000 committed Jul 10, 2024
1 parent 538ec2d commit 588721f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
20 changes: 10 additions & 10 deletions packages/effect/grass/material/GrassMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class GrassMaterial extends Material {
}

public get windBound(): Vector4 {
return this.shader.getUniform("windBound").data;
return this.shader.getUniformVector4("windBound");
}

public set grassBaseColor(v: Color) {
Expand All @@ -117,70 +117,70 @@ export class GrassMaterial extends Material {
}

public get windDirection(): Vector2 {
return this.shader.getUniform("windDirection").data;
return this.shader.getUniformVector2("windDirection");
}

public set windPower(v: number) {
this.shader.setUniformFloat("windPower", v);
}

public get windPower(): number {
return this.shader.getUniform("windPower").data;
return this.shader.getUniformFloat("windPower");
}

public set windSpeed(v: number) {
this.shader.setUniformFloat("windSpeed", v);
}

public get windSpeed(): number {
return this.shader.getUniform("windSpeed").data;
return this.shader.getUniformFloat("windSpeed");
}

public set grassHeight(v: number) {
this.shader.setUniformFloat("grassHeight", v);
}

public get grassHeight(): number {
return this.shader.getUniform("grassHeight").data;
return this.shader.getUniformFloat("grassHeight");
}

public set curvature(v: number) {
this.shader.setUniformFloat("curvature", v);
}

public get curvature(): number {
return this.shader.getUniform("curvature").data;
return this.shader.getUniformFloat("curvature");
}

public set roughness(v: number) {
this.shader.setUniformFloat("roughness", v);
}

public get roughness(): number {
return this.shader.getUniform("roughness").data;
return this.shader.getUniformFloat("roughness");
}

public set translucent(v: number) {
this.shader.setUniformFloat("translucent", v);
}

public get translucent(): number {
return this.shader.getUniform("translucent").data;
return this.shader.getUniformFloat("translucent");
}

public set soft(v: number) {
this.shader.setUniformFloat("soft", v);
}

public get soft(): number {
return this.shader.getUniform("soft").data;
return this.shader.getUniformFloat("soft");
}

public set specular(v: number) {
this.shader.setUniformFloat("specular", v);
}

public get specular(): number {
return this.shader.getUniform("specular").data;
return this.shader.getUniformFloat("specular");
}
}
56 changes: 29 additions & 27 deletions samples/ext/Sample_Grass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class Sample_Grass {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.updateFrameRate = 1;
Engine3D.setting.shadow.shadowBound = 500;
Engine3D.setting.shadow.shadowSize = 1024;
Engine3D.setting.shadow.shadowSize = 2048;
Engine3D.setting.shadow.shadowBias = 0.01;
// Engine3D.setting.render.zPrePass = true;

GUIHelp.init();
Expand Down Expand Up @@ -122,32 +123,33 @@ export class Sample_Grass {
scene.addChild(grass);
}

// GUIHelp.addFolder("grass-wind");
// GUIHelp.addColor(grassCom.grassMaterial, "grassBaseColor");
// GUIHelp.addColor(grassCom.grassMaterial, "grassTopColor");
// GUIHelp.add(grassCom.grassMaterial.windDirection, "x", -1.0, 1, 0.0001).onChange((v) => {
// let tv = grassCom.grassMaterial.windDirection;
// tv.x = v;
// grassCom.grassMaterial.windDirection = tv;
// });
// GUIHelp.add(grassCom.grassMaterial.windDirection, "y", -1.0, 1, 0.0001).onChange((v) => {
// let tv = grassCom.grassMaterial.windDirection;
// tv.y = v;
// grassCom.grassMaterial.windDirection = tv;
// });
// GUIHelp.add(grassCom.grassMaterial, "windPower", 0.0, 20, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "windSpeed", 0.0, 20, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "curvature", 0.0, 1, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "grassHeight", 0.0, 100, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "roughness", 0.0, 1, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "translucent", 0.0, 1, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "soft", 0.0, 10, 0.0001);
// GUIHelp.add(grassCom.grassMaterial, "specular", 0.0, 10, 0.0001);
// GUIHelp.endFolder();

// GUIHelp.addFolder("shadow");
// GUIHelp.add(Engine3D.setting.shadow, "shadowBound", 0.0, 3000, 0.0001);
// GUIHelp.endFolder();
GUIHelp.addFolder("grass-wind");
GUIHelp.addColor(grassCom.grassMaterial, "grassBaseColor");
GUIHelp.addColor(grassCom.grassMaterial, "grassTopColor");
console.log(grassCom.grassMaterial)
GUIHelp.add(grassCom.grassMaterial.windDirection, "x", -1.0, 1, 0.0001).onChange(v=>{
let tv = grassCom.grassMaterial.windDirection;
tv.x = v;
grassCom.grassMaterial.windDirection = tv;
});
GUIHelp.add(grassCom.grassMaterial.windDirection, "y", -1.0, 1, 0.0001).onChange(v=>{
let tv = grassCom.grassMaterial.windDirection;
tv.y = v;
grassCom.grassMaterial.windDirection = tv;
});
GUIHelp.add(grassCom.grassMaterial, "windPower", 0.0, 5, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "windSpeed", 0.0, 5, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "curvature", 0.0, 1, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "grassHeight", 0.0, 100, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "roughness", 0.0, 1, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "translucent", 0.0, 1, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "soft", 0.0, 10, 0.0001);
GUIHelp.add(grassCom.grassMaterial, "specular", 0.0, 10, 0.0001);
GUIHelp.endFolder();

GUIHelp.addFolder("shadow");
GUIHelp.add(Engine3D.setting.shadow, "shadowBound", 100, 1000, 1);
GUIHelp.endFolder();
}

}
Expand Down

0 comments on commit 588721f

Please sign in to comment.