/** * WebGPU Renderer Types * * Type definitions for WebGPU-based rendering system */ /** WebGPU initialization options */ export interface IWebGPUInitOptions { /** Canvas element or selector */ canvas: HTMLCanvasElement | string; /** Preferred adapter power preference */ powerPreference?: 'low-power' | 'high-performance'; /** Required features */ requiredFeatures?: GPUFeatureName[]; /** Required limits */ requiredLimits?: Record; /** Enable debug mode */ debug?: boolean; /** Preferred texture format (auto-detected if not specified) */ preferredFormat?: GPUTextureFormat; /** MSAA sample count */ sampleCount?: 1 | 4; /** Alpha mode for canvas */ alphaMode?: GPUCanvasAlphaMode; } /** WebGPU context after initialization */ export interface IWebGPUContext { /** GPU adapter */ adapter: GPUAdapter; /** GPU device */ device: GPUDevice; /** Canvas context */ context: GPUCanvasContext; /** Preferred texture format */ format: GPUTextureFormat; /** Canvas element */ canvas: HTMLCanvasElement; /** Device capabilities */ capabilities: IDeviceCapabilities; } /** Device capabilities and limits */ export interface IDeviceCapabilities { maxTextureDimension2D: number; maxTextureArrayLayers: number; maxBindGroups: number; maxBindingsPerBindGroup: number; maxBufferSize: number; maxUniformBufferBindingSize: number; maxStorageBufferBindingSize: number; maxVertexBuffers: number; maxVertexAttributes: number; maxComputeWorkgroupsPerDimension: number; features: Set; } /** Render pipeline descriptor */ export interface IRenderPipelineDescriptor { /** Pipeline label for debugging */ label?: string; /** Vertex shader module */ vertexShader: IShaderModule; /** Fragment shader module */ fragmentShader: IShaderModule; /** Vertex buffer layouts */ vertexBufferLayouts: IVertexBufferLayout[]; /** Primitive topology */ topology?: GPUPrimitiveTopology; /** Cull mode */ cullMode?: GPUCullMode; /** Front face winding */ frontFace?: GPUFrontFace; /** Depth/stencil state */ depthStencil?: IDepthStencilState; /** Color target states */ colorTargets: IColorTargetState[]; /** Bind group layouts */ bindGroupLayouts?: GPUBindGroupLayout[]; /** MSAA sample count */ sampleCount?: number; } /** Shader module definition */ export interface IShaderModule { /** WGSL source code */ code: string; /** Entry point function name */ entryPoint: string; /** Shader label */ label?: string; } /** Vertex buffer layout */ export interface IVertexBufferLayout { /** Stride in bytes */ arrayStride: number; /** Step mode */ stepMode?: GPUVertexStepMode; /** Vertex attributes */ attributes: IVertexAttribute[]; } /** Vertex attribute definition */ export interface IVertexAttribute { /** Attribute format */ format: GPUVertexFormat; /** Byte offset */ offset: number; /** Shader location */ shaderLocation: number; } /** Depth/stencil state */ export interface IDepthStencilState { /** Depth texture format */ format: GPUTextureFormat; /** Enable depth write */ depthWriteEnabled: boolean; /** Depth comparison function */ depthCompare: GPUCompareFunction; /** Stencil front face */ stencilFront?: IStencilFaceState; /** Stencil back face */ stencilBack?: IStencilFaceState; /** Depth bias */ depthBias?: number; /** Depth bias slope scale */ depthBiasSlopeScale?: number; /** Depth bias clamp */ depthBiasClamp?: number; } /** Stencil face state */ export interface IStencilFaceState { compare?: GPUCompareFunction; failOp?: GPUStencilOperation; depthFailOp?: GPUStencilOperation; passOp?: GPUStencilOperation; } /** Color target state */ export interface IColorTargetState { /** Texture format */ format: GPUTextureFormat; /** Blend state */ blend?: IBlendState; /** Color write mask */ writeMask?: GPUColorWriteFlags; } /** Blend state */ export interface IBlendState { /** Color blend component */ color: IBlendComponent; /** Alpha blend component */ alpha: IBlendComponent; } /** Blend component */ export interface IBlendComponent { operation?: GPUBlendOperation; srcFactor?: GPUBlendFactor; dstFactor?: GPUBlendFactor; } /** GPU buffer descriptor */ export interface IBufferDescriptor { /** Buffer label */ label?: string; /** Size in bytes */ size: number; /** Buffer usage flags */ usage: GPUBufferUsageFlags; /** Map at creation */ mappedAtCreation?: boolean; } /** Uniform buffer data */ export interface IUniformBuffer { /** Buffer handle */ buffer: GPUBuffer; /** Current data */ data: ArrayBuffer; /** Binding index */ binding: number; /** Last update frame */ lastUpdateFrame: number; } /** Vertex buffer data */ export interface IVertexBuffer { /** Buffer handle */ buffer: GPUBuffer; /** Vertex count */ vertexCount: number; /** Stride in bytes */ stride: number; /** Buffer slot */ slot: number; } /** Index buffer data */ export interface IIndexBuffer { /** Buffer handle */ buffer: GPUBuffer; /** Index count */ indexCount: number; /** Index format */ format: GPUIndexFormat; } /** Texture descriptor */ export interface ITextureDescriptor { /** Texture label */ label?: string; /** Width in pixels */ width: number; /** Height in pixels */ height: number; /** Depth or array layers */ depthOrArrayLayers?: number; /** Mip level count */ mipLevelCount?: number; /** Sample count */ sampleCount?: number; /** Texture dimension */ dimension?: GPUTextureDimension; /** Texture format */ format: GPUTextureFormat; /** Texture usage */ usage: GPUTextureUsageFlags; } /** Sampler descriptor */ export interface ISamplerDescriptor { /** Sampler label */ label?: string; /** Address mode U */ addressModeU?: GPUAddressMode; /** Address mode V */ addressModeV?: GPUAddressMode; /** Address mode W */ addressModeW?: GPUAddressMode; /** Mag filter */ magFilter?: GPUFilterMode; /** Min filter */ minFilter?: GPUFilterMode; /** Mipmap filter */ mipmapFilter?: GPUMipmapFilterMode; /** LOD min clamp */ lodMinClamp?: number; /** LOD max clamp */ lodMaxClamp?: number; /** Compare function for shadow maps */ compare?: GPUCompareFunction; /** Max anisotropy */ maxAnisotropy?: number; } /** GPU texture with metadata */ export interface IGPUTexture { /** Texture handle */ texture: GPUTexture; /** Default view */ view: GPUTextureView; /** Sampler */ sampler: GPUSampler; /** Width */ width: number; /** Height */ height: number; /** Format */ format: GPUTextureFormat; /** Mip levels */ mipLevels: number; } /** Render pass descriptor */ export interface IRenderPassDescriptor { /** Pass label */ label?: string; /** Color attachments */ colorAttachments: IRenderPassColorAttachment[]; /** Depth/stencil attachment */ depthStencilAttachment?: IRenderPassDepthStencilAttachment; /** Occlusion query set */ occlusionQuerySet?: GPUQuerySet; /** Timestamp writes */ timestampWrites?: GPURenderPassTimestampWrites; } /** Color attachment */ export interface IRenderPassColorAttachment { /** View to render to */ view: GPUTextureView; /** Resolve target for MSAA */ resolveTarget?: GPUTextureView; /** Clear value */ clearValue?: GPUColor; /** Load operation */ loadOp: GPULoadOp; /** Store operation */ storeOp: GPUStoreOp; } /** Depth/stencil attachment */ export interface IRenderPassDepthStencilAttachment { /** Depth texture view */ view: GPUTextureView; /** Depth clear value */ depthClearValue?: number; /** Depth load op */ depthLoadOp?: GPULoadOp; /** Depth store op */ depthStoreOp?: GPUStoreOp; /** Depth read-only */ depthReadOnly?: boolean; /** Stencil clear value */ stencilClearValue?: number; /** Stencil load op */ stencilLoadOp?: GPULoadOp; /** Stencil store op */ stencilStoreOp?: GPUStoreOp; /** Stencil read-only */ stencilReadOnly?: boolean; } /** Renderable mesh */ export interface IRenderMesh { /** Mesh identifier */ id: string; /** Vertex buffers */ vertexBuffers: IVertexBuffer[]; /** Index buffer (optional) */ indexBuffer?: IIndexBuffer; /** Vertex count (for non-indexed draws) */ vertexCount: number; /** Instance count */ instanceCount: number; /** Bounding box for culling */ boundingBox?: IBoundingBox; } /** Bounding box for frustum culling */ export interface IBoundingBox { min: [number, number, number]; max: [number, number, number]; } /** Material for rendering */ export interface IRenderMaterial { /** Material identifier */ id: string; /** Pipeline to use */ pipelineId: string; /** Bind group for material uniforms */ bindGroup: GPUBindGroup; /** Textures */ textures: Map; /** Uniform data */ uniforms: ArrayBuffer; /** Transparency flag */ transparent: boolean; /** Double-sided flag */ doubleSided: boolean; } /** Draw call */ export interface IDrawCall { /** Mesh to draw */ mesh: IRenderMesh; /** Material to use */ material: IRenderMaterial; /** Model matrix */ modelMatrix: Float32Array; /** Sort key for batching */ sortKey: number; /** Distance from camera (for transparency sorting) */ cameraDistance?: number; } /** Camera uniforms */ export interface ICameraUniforms { /** View matrix */ viewMatrix: Float32Array; /** Projection matrix */ projectionMatrix: Float32Array; /** View-projection matrix */ viewProjectionMatrix: Float32Array; /** Inverse view matrix */ inverseViewMatrix: Float32Array; /** Inverse projection matrix */ inverseProjectionMatrix: Float32Array; /** Camera position */ cameraPosition: Float32Array; /** Near plane */ near: number; /** Far plane */ far: number; /** Field of view (radians) */ fov: number; /** Aspect ratio */ aspectRatio: number; } /** Scene uniforms */ export interface ISceneUniforms { /** Ambient light color */ ambientColor: Float32Array; /** Time since start */ time: number; /** Delta time */ deltaTime: number; /** Frame number */ frameNumber: number; } /** Frame statistics */ export interface IFrameStats { /** Frame time in milliseconds */ frameTime: number; /** GPU time in milliseconds (if available) */ gpuTime?: number; /** Draw calls */ drawCalls: number; /** Triangles rendered */ triangles: number; /** Vertices processed */ vertices: number; /** Pipeline switches */ pipelineSwitches: number; /** Bind group switches */ bindGroupSwitches: number; /** Buffer uploads */ bufferUploads: number; /** Texture uploads */ textureUploads: number; } /** Renderer statistics */ export interface IRendererStats { /** Current frame stats */ currentFrame: IFrameStats; /** Rolling average stats */ average: IFrameStats; /** Total frames rendered */ totalFrames: number; /** FPS */ fps: number; /** GPU memory usage (if available) */ gpuMemory?: number; } /** Standard PBR vertex shader */ export declare const STANDARD_VERTEX_SHADER = "\nstruct VertexInput {\n @location(0) position: vec3,\n @location(1) normal: vec3,\n @location(2) uv: vec2,\n}\n\nstruct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) worldPosition: vec3,\n @location(1) worldNormal: vec3,\n @location(2) uv: vec2,\n}\n\nstruct CameraUniforms {\n viewProjectionMatrix: mat4x4,\n cameraPosition: vec3,\n}\n\nstruct ModelUniforms {\n modelMatrix: mat4x4,\n normalMatrix: mat3x3,\n}\n\n@group(0) @binding(0) var camera: CameraUniforms;\n@group(1) @binding(0) var model: ModelUniforms;\n\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let worldPos = model.modelMatrix * vec4(input.position, 1.0);\n output.position = camera.viewProjectionMatrix * worldPos;\n output.worldPosition = worldPos.xyz;\n output.worldNormal = normalize(model.normalMatrix * input.normal);\n output.uv = input.uv;\n return output;\n}\n"; /** Standard PBR fragment shader */ export declare const STANDARD_FRAGMENT_SHADER = "\nstruct FragmentInput {\n @location(0) worldPosition: vec3,\n @location(1) worldNormal: vec3,\n @location(2) uv: vec2,\n}\n\nstruct MaterialUniforms {\n baseColor: vec4,\n metallic: f32,\n roughness: f32,\n emissive: vec3,\n}\n\nstruct LightUniforms {\n direction: vec3,\n color: vec3,\n intensity: f32,\n}\n\n@group(0) @binding(1) var material: MaterialUniforms;\n@group(0) @binding(2) var light: LightUniforms;\n@group(2) @binding(0) var baseColorTexture: texture_2d;\n@group(2) @binding(1) var baseColorSampler: sampler;\n\nconst PI: f32 = 3.14159265359;\n\nfn fresnelSchlick(cosTheta: f32, F0: vec3) -> vec3 {\n return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);\n}\n\nfn distributionGGX(N: vec3, H: vec3, roughness: f32) -> f32 {\n let a = roughness * roughness;\n let a2 = a * a;\n let NdotH = max(dot(N, H), 0.0);\n let NdotH2 = NdotH * NdotH;\n let nom = a2;\n var denom = (NdotH2 * (a2 - 1.0) + 1.0);\n denom = PI * denom * denom;\n return nom / denom;\n}\n\nfn geometrySchlickGGX(NdotV: f32, roughness: f32) -> f32 {\n let r = roughness + 1.0;\n let k = (r * r) / 8.0;\n let nom = NdotV;\n let denom = NdotV * (1.0 - k) + k;\n return nom / denom;\n}\n\nfn geometrySmith(N: vec3, V: vec3, L: vec3, roughness: f32) -> f32 {\n let NdotV = max(dot(N, V), 0.0);\n let NdotL = max(dot(N, L), 0.0);\n let ggx2 = geometrySchlickGGX(NdotV, roughness);\n let ggx1 = geometrySchlickGGX(NdotL, roughness);\n return ggx1 * ggx2;\n}\n\n@fragment\nfn main(input: FragmentInput) -> @location(0) vec4 {\n let baseColor = textureSample(baseColorTexture, baseColorSampler, input.uv) * material.baseColor;\n let N = normalize(input.worldNormal);\n let V = normalize(-input.worldPosition);\n let L = normalize(-light.direction);\n let H = normalize(V + L);\n \n let F0 = mix(vec3(0.04), baseColor.rgb, material.metallic);\n let F = fresnelSchlick(max(dot(H, V), 0.0), F0);\n let NDF = distributionGGX(N, H, material.roughness);\n let G = geometrySmith(N, V, L, material.roughness);\n \n let numerator = NDF * G * F;\n let denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;\n let specular = numerator / denominator;\n \n let kS = F;\n let kD = (vec3(1.0) - kS) * (1.0 - material.metallic);\n let NdotL = max(dot(N, L), 0.0);\n \n let Lo = (kD * baseColor.rgb / PI + specular) * light.color * light.intensity * NdotL;\n let ambient = vec3(0.03) * baseColor.rgb;\n var color = ambient + Lo + material.emissive;\n \n // Tone mapping (Reinhard)\n color = color / (color + vec3(1.0));\n // Gamma correction\n color = pow(color, vec3(1.0 / 2.2));\n \n return vec4(color, baseColor.a);\n}\n"; /** Unlit vertex shader */ export declare const UNLIT_VERTEX_SHADER = "\nstruct VertexInput {\n @location(0) position: vec3,\n @location(1) uv: vec2,\n @location(2) color: vec4,\n}\n\nstruct VertexOutput {\n @builtin(position) position: vec4,\n @location(0) uv: vec2,\n @location(1) color: vec4,\n}\n\nstruct Uniforms {\n mvpMatrix: mat4x4,\n}\n\n@group(0) @binding(0) var uniforms: Uniforms;\n\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n output.position = uniforms.mvpMatrix * vec4(input.position, 1.0);\n output.uv = input.uv;\n output.color = input.color;\n return output;\n}\n"; /** Unlit fragment shader */ export declare const UNLIT_FRAGMENT_SHADER = "\nstruct FragmentInput {\n @location(0) uv: vec2,\n @location(1) color: vec4,\n}\n\n@group(0) @binding(1) var colorTexture: texture_2d;\n@group(0) @binding(2) var colorSampler: sampler;\n\n@fragment\nfn main(input: FragmentInput) -> @location(0) vec4 {\n let texColor = textureSample(colorTexture, colorSampler, input.uv);\n return texColor * input.color;\n}\n"; //# sourceMappingURL=WebGPUTypes.d.ts.map