调整点光的部分代码

This commit is contained in:
caizhitao
2020-01-13 22:40:10 +08:00
parent dccf05cfde
commit 6402c68fbc
4 changed files with 20 additions and 24 deletions

View File

@@ -2,7 +2,7 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class PointLightCtrlComponent extends cc.Component {
private _localDiffusionUniform: PointLightUniform = new PointLightUniform();
private _pointLightUBO: PointLightUBO = new PointLightUBO();
onEnable() {
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
@@ -26,7 +26,7 @@ export default class PointLightCtrlComponent extends cc.Component {
// 将触摸点转换为OPENGL坐标系并归一化
// OpenGl 坐标系原点在左上角
this._localDiffusionUniform.certerPoint = cc.v2(
this._pointLightUBO.centerPoint = cc.v2(
this.node.anchorX + touchPointInNodeSpace.x / this.node.width,
1 - (this.node.anchorY + touchPointInNodeSpace.y / this.node.height)
);
@@ -34,28 +34,28 @@ export default class PointLightCtrlComponent extends cc.Component {
this._updateMaterial();
}
private _onPropertyChange(localDiffusionUniform: PointLightUniform) {
this._localDiffusionUniform.centerColor = localDiffusionUniform.centerColor;
this._localDiffusionUniform.radius = localDiffusionUniform.radius;
this._localDiffusionUniform.cropAlpha = localDiffusionUniform.cropAlpha;
this._localDiffusionUniform.enableFog = localDiffusionUniform.enableFog;
private _onPropertyChange(pointLightUBO: PointLightUBO) {
this._pointLightUBO.centerColor = pointLightUBO.centerColor;
this._pointLightUBO.radius = pointLightUBO.radius;
this._pointLightUBO.cropAlpha = pointLightUBO.cropAlpha;
this._pointLightUBO.enableFog = pointLightUBO.enableFog;
this._updateMaterial();
}
private _updateMaterial() {
this.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
material.setProperty("centerColor", this._localDiffusionUniform.centerColor);
material.setProperty("centerPoint", this._localDiffusionUniform.certerPoint);
material.setProperty("radius", this._localDiffusionUniform.radius);
material.setProperty("cropAlpha", this._localDiffusionUniform.cropAlpha);
material.setProperty("enableFog", this._localDiffusionUniform.enableFog);
material.setProperty("centerColor", this._pointLightUBO.centerColor);
material.setProperty("centerPoint", this._pointLightUBO.centerPoint);
material.setProperty("radius", this._pointLightUBO.radius);
material.setProperty("cropAlpha", this._pointLightUBO.cropAlpha);
material.setProperty("enableFog", this._pointLightUBO.enableFog);
renderComponent.setMaterial(0, material);
});
}
}
export class PointLightUniform {
export class PointLightUBO {
/**
* 中心点颜色
*/
@@ -64,7 +64,7 @@ export class PointLightUniform {
/**
* 中心点坐标 ([0.0, 1.0], [0.0, 1.0])
*/
certerPoint: cc.Vec2 = cc.v2(0.5, 0.5);
centerPoint: cc.Vec2 = cc.v2(0.5, 0.5);
/**
* 扩散半径 [0.0, 1.0]

View File

@@ -1,4 +1,4 @@
import PointLightCtrlComponent, { PointLightUniform } from "./PointLightCtrlComponent";
import PointLightCtrlComponent, { PointLightUBO } from "./PointLightCtrlComponent";
const { ccclass, property } = cc._decorator;
@@ -78,7 +78,7 @@ export default class PointLightEffectScene extends cc.Component {
// 通知子节点更新材质
this._examplesParentNode.children.forEach(childNode => {
childNode.emit("on_property_change", <PointLightUniform>{
childNode.emit("on_property_change", <PointLightUBO>{
centerColor: cc.color(
Math.round(255 * this._redSlider.progress),
Math.round(255 * this._greenSlider.progress),