super-hero/extensions/shader-graph/shader-node/assets/operation/manual/input/texture/sample-cubemap.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-05-29 19:24:12 -07:00
import InputNode from '../input-node';
import { NormalMapSpace, NormalSpace, ConcretePrecisionType, ViewDirSpace } from '../../../type';
import PropertyNode from '../property-node';
export default class SampleTexture2D extends InputNode {
generateCode() {
const cubeSlot = this.getSlotWithSlotName('Cube');
const node = cubeSlot?.connectSlot && cubeSlot?.connectSlot.node as PropertyNode;
if (!node) {
return '';
}
let V = 'view';
let N = 'normal';
const viewSlot = this.getSlotWithSlotName('ViewDir');
if (viewSlot?.connectSlot) {
V = viewSlot?.connectSlot.varName;
}
const normalSlot = this.getSlotWithSlotName('Normal');
if (normalSlot?.connectSlot) {
N = normalSlot?.connectSlot.varName;
}
const R = `${this.getOutputVarName(0)}_R`;
let code = '';
code += `vec3 ${R} = reflect( -normalize( ${V} ), ${N} );\n`;
code += `${this.getOutputVarDefine(0)} = texture(${node.property?.name}, ${R});\n`;
return code;
}
}