@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
81 lines (80 loc) • 3.24 kB
JavaScript
"use strict";
import { PrecisionGLDefinition } from "./utils/GLDefinition";
import { TypedGlNode } from "./_Base";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { ThreeToGl } from "../../../core/ThreeToGl";
import { UniformGLDefinition } from "./utils/GLDefinition";
import { ParamConfigsController } from "../utils/code/controllers/ParamConfigsController";
import { ParamType } from "../../poly/ParamType";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlParamConfig } from "./code/utils/GLParamConfig";
import { UNIFORM_TEXTURE_PREFIX } from "../../../core/material/uniform";
class Texture2DArrayGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.paramName = ParamConfig.STRING("texture3D1");
// defaultValue = ParamConfig.STRING('');
this.uv = ParamConfig.VECTOR2([0, 0]);
this.layer = ParamConfig.INTEGER(4, {
range: [1, 31]
});
}
}
const ParamsConfig = new Texture2DArrayGlParamsConfig();
const _Texture2DArrayGlNode = class extends TypedGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "texture2DArray";
}
initializeNode() {
this.addPostDirtyHook("_setMatToRecompile", this._setMatToRecompile.bind(this));
this.lifecycle.onAfterAdded(this._setMatToRecompile.bind(this));
this.lifecycle.onBeforeDeleted(this._setMatToRecompile.bind(this));
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(_Texture2DArrayGlNode.OUTPUT_NAME, GlConnectionPointType.VEC4)
]);
this.io.connection_points.spare_params.setInputlessParamNames(["tblur", "resolution"]);
}
setLines(shaders_collection_controller) {
const uv = ThreeToGl.vector2(this.variableForInputParam(this.p.uv));
const layer = ThreeToGl.float(this.variableForInputParam(this.p.layer));
const rgba = this.glVarName(_Texture2DArrayGlNode.OUTPUT_NAME);
const map = this.uniformName();
const definitions = [
new PrecisionGLDefinition(this, GlConnectionPointType.SAMPLER_2D_ARRAY, "highp"),
new UniformGLDefinition(this, GlConnectionPointType.SAMPLER_2D_ARRAY, map)
];
const bodyLines = [`vec4 ${rgba} = texture(${map}, vec3(${uv},${layer}))`];
shaders_collection_controller.addDefinitions(this, definitions);
shaders_collection_controller.addBodyLines(this, bodyLines);
}
paramsGenerating() {
return true;
}
setParamConfigs() {
this._param_configs_controller = this._param_configs_controller || new ParamConfigsController();
this._param_configs_controller.reset();
const param_config = new GlParamConfig(
ParamType.NODE_PATH,
this.pv.paramName,
"",
//this.pv.defaultValue,
this.uniformName()
);
this._param_configs_controller.push(param_config);
}
// override glVarName(name?: string) {
// if (name) {
// return super.glVarName(name);
// }
// return `v_POLY_texture_${this.pv.paramName}`;
// }
uniformName() {
return `${UNIFORM_TEXTURE_PREFIX}${this.pv.paramName}`;
}
};
export let Texture2DArrayGlNode = _Texture2DArrayGlNode;
Texture2DArrayGlNode.OUTPUT_NAME = "rgba";