/** * @file ShaderGraph.ts * @description Visual Shader Graph Editor System * PRO-1.4: Professional Editor Features * * Features: * - Node-based shader editing * - GLSL/WGSL/HLSL generation * - Real-time preview * - Material templates * - Custom node creation * - Subgraph support * - PBR and unlit workflows */ export type ShaderTarget = 'glsl' | 'wgsl' | 'hlsl' | 'metal' | 'spirv'; export type ShaderStage = 'vertex' | 'fragment' | 'compute'; export type ShaderPrecision = 'lowp' | 'mediump' | 'highp'; export type ShaderDataType = 'float' | 'vec2' | 'vec3' | 'vec4' | 'int' | 'ivec2' | 'ivec3' | 'ivec4' | 'bool' | 'bvec2' | 'bvec3' | 'bvec4' | 'mat2' | 'mat3' | 'mat4' | 'sampler2D' | 'samplerCube' | 'sampler3D' | 'void'; export type ShaderBlendMode = 'opaque' | 'alpha' | 'additive' | 'multiply' | 'premultiplied'; export type ShaderCullMode = 'none' | 'front' | 'back'; export type ShaderDepthTest = 'always' | 'never' | 'less' | 'lequal' | 'greater' | 'gequal' | 'equal' | 'notequal'; export interface ShaderPortDef { name: string; type: ShaderDataType; description?: string; default?: number | number[]; min?: number; max?: number; hidden?: boolean; } export interface ShaderNodeDef { id: string; name: string; category: ShaderNodeCategory; description?: string; inputs: ShaderPortDef[]; outputs: ShaderPortDef[]; /** GLSL code template with {{input}}, {{output}} placeholders */ glsl?: string; /** WGSL code template */ wgsl?: string; /** HLSL code template */ hlsl?: string; /** Preview function name */ previewFunc?: string; /** Custom properties */ properties?: ShaderPropertyDef[]; /** Whether this node is a master/output node */ isMaster?: boolean; /** Stage restriction */ stage?: ShaderStage; } export type ShaderNodeCategory = 'input' | 'output' | 'math' | 'vector' | 'matrix' | 'texture' | 'uv' | 'color' | 'lighting' | 'channel' | 'procedural' | 'utility' | 'custom' | 'subgraph'; export interface ShaderPropertyDef { name: string; type: 'float' | 'int' | 'bool' | 'color' | 'texture' | 'dropdown' | 'vec2' | 'vec3' | 'vec4'; default?: unknown; options?: string[]; min?: number; max?: number; } export interface ShaderPort { nodeId: string; portName: string; } export interface ShaderConnection { id: string; from: ShaderPort; to: ShaderPort; } export interface ShaderNodeInstance { id: string; type: string; position: { x: number; y: number; }; properties: Record; /** Collapsed state */ collapsed?: boolean; /** Preview enabled */ previewEnabled?: boolean; /** Custom title override */ title?: string; /** Comment/note */ comment?: string; } export interface ShaderSubgraph { id: string; name: string; description?: string; nodes: ShaderNodeInstance[]; connections: ShaderConnection[]; inputs: ShaderPortDef[]; outputs: ShaderPortDef[]; } export interface ShaderGraphDef { id: string; name: string; description?: string; target: ShaderTarget; stage: ShaderStage; nodes: ShaderNodeInstance[]; connections: ShaderConnection[]; /** Exposed properties for material instances */ properties: ShaderExposedProperty[]; /** Graph-level settings */ settings: ShaderGraphSettings; /** Subgraphs */ subgraphs?: ShaderSubgraph[]; /** Custom functions */ customFunctions?: ShaderCustomFunction[]; /** Metadata */ metadata?: Record; } export interface ShaderExposedProperty { id: string; name: string; displayName: string; type: ShaderDataType; default: unknown; min?: number; max?: number; group?: string; tooltip?: string; } export interface ShaderGraphSettings { precision: ShaderPrecision; blendMode: ShaderBlendMode; cullMode: ShaderCullMode; depthWrite: boolean; depthTest: ShaderDepthTest; alphaClip?: number; castShadows: boolean; receiveShadows: boolean; doubleSided: boolean; /** Surface type */ surfaceType: 'opaque' | 'transparent'; /** Render queue */ renderQueue: number; /** Custom defines */ defines?: Record; } export interface ShaderCustomFunction { name: string; returnType: ShaderDataType; parameters: { name: string; type: ShaderDataType; }[]; body: string; } export declare const SHADER_NODE_LIBRARY: ShaderNodeDef[]; export interface GeneratedShader { vertex: string; fragment: string; uniforms: ShaderUniform[]; defines: string[]; } export interface ShaderUniform { name: string; type: ShaderDataType; value?: unknown; } export declare class ShaderCodeGenerator { private graph; private nodeLibrary; private generatedCode; private uniforms; private defines; private nodeCounter; constructor(graph: ShaderGraphDef); generate(): GeneratedShader; private generateNode; private defaultValue; private formatValue; private buildVertexShader; private buildFragmentShader; } export interface ShaderGraphEditorState { graph: ShaderGraphDef; selectedNodes: string[]; hoveredNode: string | null; hoveredPort: ShaderPort | null; draggingConnection: { from: ShaderPort; toPosition: { x: number; y: number; }; } | null; viewOffset: { x: number; y: number; }; zoom: number; previewEnabled: boolean; generatedShader: GeneratedShader | null; compileErrors: string[]; } export declare function createShaderGraphEditorState(graph?: ShaderGraphDef): ShaderGraphEditorState; export declare function createEmptyShaderGraph(): ShaderGraphDef; export declare function createShaderGraph(name: string, target?: ShaderTarget): ShaderGraphDef; export declare function generateShader(graph: ShaderGraphDef): GeneratedShader; export declare function getNodeLibrary(): ShaderNodeDef[]; export declare function getNodesByCategory(category: ShaderNodeCategory): ShaderNodeDef[]; export declare function findNodeDef(nodeType: string): ShaderNodeDef | undefined;