forked from layabox/LayaAir
-
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.
test: Add custom material examples and configure 2D sample content.
测试示例: 增加自定义材质示例,配置2D示例内容.
- Loading branch information
Showing
5 changed files
with
963 additions
and
881 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Laya } from "Laya" | ||
import { Sprite } from "laya/display/Sprite"; | ||
import { Stage } from "laya/display/Stage"; | ||
import { Stat } from "laya/utils/Stat"; | ||
import { Main } from "../Main"; | ||
import { Scene } from "laya/display/Scene"; | ||
import { Material } from "laya/resource/Material"; | ||
import { Graphics } from "laya/display/Graphics"; | ||
import { Shader3D } from "laya/RenderEngine/RenderShader/Shader3D"; | ||
import { ShaderDataType } from "laya/RenderDriver/DriverDesign/RenderDevice/ShaderData"; | ||
import { Color } from "laya/maths/Color"; | ||
|
||
export class Material2DDemo { | ||
Main: typeof Main = null; | ||
scene: Scene; | ||
|
||
constructor(mainClass: typeof Main) { | ||
this.Main = mainClass; | ||
Laya.init(0, 0).then(() => { | ||
Laya.stage.scaleMode = Stage.SCALE_FULL; | ||
Laya.stage.screenMode = Stage.SCREEN_NONE; | ||
Stat.show(); | ||
Laya.stage.bgColor = "#232628"; | ||
//提前加载CustomShader1与其对应的material | ||
let res: string[] = ["res/2DRender/custom2DShader_1.shader", "res/apes/monkey3.png"]; | ||
this.scene = new Scene(); | ||
this.Main.box2D.addChild(this.scene); | ||
Laya.loader.load(res).then(() => { | ||
this.set2DCustomMaterial(); | ||
}); | ||
}); | ||
} | ||
|
||
set2DCustomMaterial(): void { | ||
// 自定义shader与全局2D uniform变量使用 | ||
let customShaderSp = new Sprite(); | ||
customShaderSp.loadImage("res/apes/monkey3.png"); | ||
this.scene.addChild(customShaderSp); | ||
this.loadCustom2DShader(customShaderSp); | ||
|
||
// 自定义2d材质使用 | ||
Laya.loader.load("res/2DRender/customMaterial_1.lmat").then((mat: Material) => { | ||
let customMaterialSp = new Sprite(); | ||
customMaterialSp.pos(100, 0); | ||
this.scene.addChild(customMaterialSp); | ||
customMaterialSp.loadImage("res/apes/monkey3.png"); | ||
customMaterialSp.graphics.material = mat; | ||
}); | ||
} | ||
|
||
loadCustom2DShader(sp: Sprite): void { | ||
Laya.loader.load("res/2DRender/custom2DShader_0.shader").then(() => { | ||
let mat = new Material(); | ||
mat.setShaderName("custom2DShader_0"); | ||
// 设置2D全局uniform变量 | ||
Graphics.add2DGlobalUniformData(Shader3D.propertyNameToID("u_GlobalColor"), "u_GlobalColor", ShaderDataType.Color); | ||
(this.scene as Scene).sceneShaderData.setColor(Shader3D.propertyNameToID("u_GlobalColor"), new Color(0.0, 1.0, 0.0, 1.0)); | ||
sp.graphics.material = mat; | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.