ncca-ngl 0.3.5__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ncca/ngl/PrimData/pack_arrays.py +2 -3
- ncca/ngl/__init__.py +3 -4
- ncca/ngl/base_mesh.py +28 -20
- ncca/ngl/image.py +1 -3
- ncca/ngl/mat2.py +79 -53
- ncca/ngl/mat3.py +104 -185
- ncca/ngl/mat4.py +144 -309
- ncca/ngl/prim_data.py +42 -36
- ncca/ngl/primitives.py +2 -2
- ncca/ngl/pyside_event_handling_mixin.py +0 -108
- ncca/ngl/quaternion.py +69 -36
- ncca/ngl/shader.py +0 -116
- ncca/ngl/shader_program.py +94 -117
- ncca/ngl/texture.py +5 -2
- ncca/ngl/util.py +0 -2
- ncca/ngl/vec2.py +59 -302
- ncca/ngl/vec2_array.py +79 -28
- ncca/ngl/vec3.py +60 -350
- ncca/ngl/vec3_array.py +76 -23
- ncca/ngl/vec4.py +90 -200
- ncca/ngl/vec4_array.py +78 -27
- ncca/ngl/vector_base.py +542 -0
- ncca/ngl/webgpu/__init__.py +20 -0
- ncca/ngl/webgpu/__main__.py +640 -0
- ncca/ngl/webgpu/__main__.py.backup +640 -0
- ncca/ngl/webgpu/base_webgpu_pipeline.py +354 -0
- ncca/ngl/webgpu/custom_shader_pipeline.py +288 -0
- ncca/ngl/webgpu/instanced_geometry_pipeline.py +594 -0
- ncca/ngl/webgpu/line_pipeline.py +405 -0
- ncca/ngl/webgpu/pipeline_factory.py +190 -0
- ncca/ngl/webgpu/pipeline_shaders.py +497 -0
- ncca/ngl/webgpu/point_list_pipeline.py +349 -0
- ncca/ngl/webgpu/point_pipeline.py +336 -0
- ncca/ngl/webgpu/triangle_pipeline.py +419 -0
- ncca/ngl/webgpu/webgpu_constants.py +31 -0
- ncca/ngl/webgpu/webgpu_widget.py +322 -0
- ncca/ngl/webgpu/wip/REFACTORING_SUMMARY.md +82 -0
- ncca/ngl/webgpu/wip/UNIFIED_SYSTEM.md +314 -0
- ncca/ngl/webgpu/wip/buffer_manager.py +396 -0
- ncca/ngl/webgpu/wip/pipeline_config.py +463 -0
- ncca/ngl/webgpu/wip/shader_constants.py +328 -0
- ncca/ngl/webgpu/wip/shader_templates.py +563 -0
- ncca/ngl/webgpu/wip/unified_examples.py +390 -0
- ncca/ngl/webgpu/wip/unified_factory.py +449 -0
- ncca/ngl/webgpu/wip/unified_pipeline.py +469 -0
- ncca/ngl/widgets/__init__.py +18 -2
- ncca/ngl/widgets/__main__.py +2 -1
- ncca/ngl/widgets/lookatwidget.py +2 -1
- ncca/ngl/widgets/mat4widget.py +2 -2
- ncca/ngl/widgets/vec2widget.py +1 -1
- ncca/ngl/widgets/vec3widget.py +1 -0
- {ncca_ngl-0.3.5.dist-info → ncca_ngl-0.5.0.dist-info}/METADATA +3 -2
- ncca_ngl-0.5.0.dist-info/RECORD +105 -0
- ncca/ngl/widgets/transformation_widget.py +0 -299
- ncca_ngl-0.3.5.dist-info/RECORD +0 -82
- {ncca_ngl-0.3.5.dist-info → ncca_ngl-0.5.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shared shader constants for WebGPU pipelines to eliminate duplication.
|
|
3
|
+
Contains common shader code patterns and templates.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# Common uniform structures
|
|
7
|
+
MVP_UNIFORM = """struct Uniforms {
|
|
8
|
+
MVP: mat4x4<f32>,
|
|
9
|
+
};"""
|
|
10
|
+
|
|
11
|
+
MVP_VIEW_UNIFORM = """struct Uniforms {
|
|
12
|
+
MVP: mat4x4<f32>,
|
|
13
|
+
ViewMatrix: mat4x4<f32>,
|
|
14
|
+
};"""
|
|
15
|
+
|
|
16
|
+
MVP_COLOUR_UNIFORM = """struct Uniforms {
|
|
17
|
+
MVP: mat4x4<f32>,
|
|
18
|
+
colour: vec3<f32>,
|
|
19
|
+
padding: f32,
|
|
20
|
+
};"""
|
|
21
|
+
|
|
22
|
+
MVP_VIEW_SIZE_UNIFORM = """struct Uniforms {
|
|
23
|
+
MVP: mat4x4<f32>,
|
|
24
|
+
ViewMatrix: mat4x4<f32>,
|
|
25
|
+
size: f32,
|
|
26
|
+
padding: u32,
|
|
27
|
+
padding2: u32,
|
|
28
|
+
padding3: u32,
|
|
29
|
+
};"""
|
|
30
|
+
|
|
31
|
+
MVP_VIEW_COLOURSIZE_UNIFORM = """struct Uniforms {
|
|
32
|
+
MVP: mat4x4<f32>,
|
|
33
|
+
ViewMatrix: mat4x4<f32>,
|
|
34
|
+
ColourSize: vec4<f32>,
|
|
35
|
+
};"""
|
|
36
|
+
|
|
37
|
+
MVP_INSTANCED_UNIFORM = """struct Uniforms {
|
|
38
|
+
MVP: mat4x4<f32>,
|
|
39
|
+
ViewMatrix: mat4x4<f32>,
|
|
40
|
+
instance_transform: mat4x4<f32>,
|
|
41
|
+
};"""
|
|
42
|
+
|
|
43
|
+
MVP_INSTANCED_COLOUR_UNIFORM = """struct Uniforms {
|
|
44
|
+
MVP: mat4x4<f32>,
|
|
45
|
+
ViewMatrix: mat4x4<f32>,
|
|
46
|
+
colour: vec3<f32>,
|
|
47
|
+
padding: f32,
|
|
48
|
+
instance_transform: mat4x4<f32>,
|
|
49
|
+
};"""
|
|
50
|
+
|
|
51
|
+
# Common vertex structures
|
|
52
|
+
POSITION_VERTEX = """struct VertexIn {
|
|
53
|
+
@location(0) position: vec3<f32>,
|
|
54
|
+
};"""
|
|
55
|
+
|
|
56
|
+
POSITION_COLOUR_VERTEX = """struct VertexIn {
|
|
57
|
+
@location(0) position: vec3<f32>,
|
|
58
|
+
@location(1) colour: vec3<f32>,
|
|
59
|
+
};"""
|
|
60
|
+
|
|
61
|
+
POSITION_INSTANCED_VERTEX = """struct InstanceData {
|
|
62
|
+
@location(0) position: vec3<f32>,
|
|
63
|
+
@location(1) colour: vec3<f32>,
|
|
64
|
+
@location(2) instance_id: f32,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
struct GeometryVertex {
|
|
68
|
+
@location(3) geometry_position: vec3<f32>,
|
|
69
|
+
@location(4) geometry_normal: vec3<f32>,
|
|
70
|
+
@location(5) geometry_uv: vec2<f32>,
|
|
71
|
+
};"""
|
|
72
|
+
|
|
73
|
+
# Common vertex output structures
|
|
74
|
+
BASIC_VERTEX_OUT = """struct VertexOut {
|
|
75
|
+
@builtin(position) position: vec4<f32>,
|
|
76
|
+
};"""
|
|
77
|
+
|
|
78
|
+
COLOUR_VERTEX_OUT = """struct VertexOut {
|
|
79
|
+
@builtin(position) position: vec4<f32>,
|
|
80
|
+
@location(0) fragColour: vec3<f32>,
|
|
81
|
+
};"""
|
|
82
|
+
|
|
83
|
+
LIT_VERTEX_OUT = """struct VertexOut {
|
|
84
|
+
@builtin(position) position: vec4<f32>,
|
|
85
|
+
@location(0) fragColour: vec3<f32>,
|
|
86
|
+
@location(1) fragNormal: vec3<f32>,
|
|
87
|
+
@location(2) fragUV: vec2<f32>,
|
|
88
|
+
@location(3) worldPos: vec3<f32>,
|
|
89
|
+
};"""
|
|
90
|
+
|
|
91
|
+
INSTANCED_VERTEX_OUT = """struct VertexOut {
|
|
92
|
+
@builtin(position) position: vec4<f32>,
|
|
93
|
+
@location(0) fragColour: vec3<f32>,
|
|
94
|
+
@location(1) fragNormal: vec3<f32>,
|
|
95
|
+
@location(2) fragUV: vec2<f32>,
|
|
96
|
+
@location(3) worldPos: vec3<f32>,
|
|
97
|
+
};"""
|
|
98
|
+
|
|
99
|
+
# Point rendering constants
|
|
100
|
+
QUAD_OFFSETS = """let quad_offsets = array<vec2<f32>, 4>(
|
|
101
|
+
vec2<f32>(-1.0, -1.0), // bottom-left
|
|
102
|
+
vec2<f32>(1.0, -1.0), // bottom-right
|
|
103
|
+
vec2<f32>(-1.0, 1.0), // top-left
|
|
104
|
+
vec2<f32>(1.0, 1.0) // top-right
|
|
105
|
+
);"""
|
|
106
|
+
|
|
107
|
+
# Circle clipping for points
|
|
108
|
+
CIRCLE_CLIP = """
|
|
109
|
+
let center = vec2<f32>(0.5, 0.5);
|
|
110
|
+
let dist = distance(fragData.uv, center);
|
|
111
|
+
let radius = 0.5;
|
|
112
|
+
|
|
113
|
+
if (dist > radius) {
|
|
114
|
+
discard;
|
|
115
|
+
}
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
# Basic lighting
|
|
119
|
+
BASIC_LIGHTING = """
|
|
120
|
+
// Basic diffuse lighting
|
|
121
|
+
let light_direction = normalize(vec3<f32>(0.5, 1.0, 0.3));
|
|
122
|
+
let light_color = vec3<f32>(1.0, 1.0, 1.0);
|
|
123
|
+
let ambient_intensity = 0.15;
|
|
124
|
+
let diffuse_intensity = 0.85;
|
|
125
|
+
|
|
126
|
+
// Ambient component
|
|
127
|
+
let ambient = vec3<f32>(ambient_intensity);
|
|
128
|
+
|
|
129
|
+
// Diffuse component (Lambertian reflection)
|
|
130
|
+
let normal = normalize(fragData.fragNormal);
|
|
131
|
+
let n_dot_l = max(dot(normal, light_direction), 0.0);
|
|
132
|
+
let diffuse = light_color * n_dot_l * diffuse_intensity;
|
|
133
|
+
|
|
134
|
+
// Combine lighting components
|
|
135
|
+
let final_lighting = ambient + diffuse;
|
|
136
|
+
|
|
137
|
+
// Apply lighting to fragment color
|
|
138
|
+
let lit_color = fragColor * final_lighting;
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
# Billboard generation
|
|
142
|
+
BILLBOARD_LOGIC = """
|
|
143
|
+
// Extract camera right and up vectors from view matrix
|
|
144
|
+
let cameraRight = normalize(vec3<f32>(uniforms.ViewMatrix[0][0], uniforms.ViewMatrix[1][0], uniforms.ViewMatrix[2][0]));
|
|
145
|
+
let cameraUp = normalize(vec3<f32>(uniforms.ViewMatrix[0][1], uniforms.ViewMatrix[1][1], uniforms.ViewMatrix[2][1]));
|
|
146
|
+
|
|
147
|
+
// Calculate billboard offset in world space
|
|
148
|
+
let offset2D = quad_offsets[vertex_index] * uniforms.size;
|
|
149
|
+
let offset3D = cameraRight * offset2D.x + cameraUp * offset2D.y;
|
|
150
|
+
let worldPos = input.position + offset3D;
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
# Instanced geometry transforms
|
|
154
|
+
INSTANCED_TRANSFORM_LOGIC = """
|
|
155
|
+
// Transform geometry vertex by instance transform and position
|
|
156
|
+
let transformed_vertex = uniforms.instance_transform * vec4<f32>(geom_vertex.geometry_position, 1.0);
|
|
157
|
+
let world_position = transformed_vertex.xyz + instance_data.position;
|
|
158
|
+
|
|
159
|
+
output.position = uniforms.MVP * vec4<f32>(world_position, 1.0);
|
|
160
|
+
output.fragColour = instance_data.colour;
|
|
161
|
+
|
|
162
|
+
// Transform normal by instance transform (skip translation)
|
|
163
|
+
let normal_matrix = mat3x3<f32>(
|
|
164
|
+
uniforms.instance_transform[0].xyz,
|
|
165
|
+
uniforms.instance_transform[1].xyz,
|
|
166
|
+
uniforms.instance_transform[2].xyz
|
|
167
|
+
);
|
|
168
|
+
output.fragNormal = normalize(normal_matrix * geom_vertex.geometry_normal);
|
|
169
|
+
output.fragUV = geom_vertex.geometry_uv;
|
|
170
|
+
output.worldPos = world_position;
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
# Complete shader constants for pipelines
|
|
174
|
+
# Point pipeline shaders
|
|
175
|
+
POINT_SHADER_MULTI_COLOURED = {
|
|
176
|
+
"vertex": POSITION_COLOUR_VERTEX
|
|
177
|
+
+ MVP_VIEW_SIZE_UNIFORM
|
|
178
|
+
+ QUAD_OFFSETS
|
|
179
|
+
+ COLOUR_VERTEX_OUT
|
|
180
|
+
+ """
|
|
181
|
+
@vertex
|
|
182
|
+
fn vs_main(@builtin(vertex_index) vertex_index: u32, input: VertexIn) -> VertexOut {
|
|
183
|
+
var output: VertexOut;
|
|
184
|
+
|
|
185
|
+
// Extract camera right and up vectors from view matrix
|
|
186
|
+
let cameraRight = normalize(vec3<f32>(uniforms.ViewMatrix[0][0], uniforms.ViewMatrix[1][0], uniforms.ViewMatrix[2][0]));
|
|
187
|
+
let cameraUp = normalize(vec3<f32>(uniforms.ViewMatrix[0][1], uniforms.ViewMatrix[1][1], uniforms.ViewMatrix[2][1]));
|
|
188
|
+
|
|
189
|
+
// Calculate billboard offset in world space
|
|
190
|
+
let offset2D = quad_offsets[vertex_index] * uniforms.size;
|
|
191
|
+
let offset3D = cameraRight * offset2D.x + cameraUp * offset2D.y;
|
|
192
|
+
let worldPos = input.position + offset3D;
|
|
193
|
+
|
|
194
|
+
output.position = uniforms.MVP * vec4<f32>(worldPos, 1.0);
|
|
195
|
+
output.fragColour = input.colour;
|
|
196
|
+
return output;
|
|
197
|
+
}
|
|
198
|
+
""",
|
|
199
|
+
"fragment": COLOUR_VERTEX_OUT
|
|
200
|
+
+ """
|
|
201
|
+
@fragment
|
|
202
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
203
|
+
return vec4<f32>(input.fragColour, 1.0);
|
|
204
|
+
}
|
|
205
|
+
""",
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
POINT_SHADER_SINGLE_COLOUR = {
|
|
209
|
+
"vertex": POSITION_VERTEX
|
|
210
|
+
+ MVP_VIEW_COLOURSIZE_UNIFORM
|
|
211
|
+
+ QUAD_OFFSETS
|
|
212
|
+
+ COLOUR_VERTEX_OUT
|
|
213
|
+
+ """
|
|
214
|
+
@vertex
|
|
215
|
+
fn vs_main(@builtin(vertex_index) vertex_index: u32, input: VertexIn) -> VertexOut {
|
|
216
|
+
var output: VertexOut;
|
|
217
|
+
|
|
218
|
+
// Extract camera right and up vectors from view matrix
|
|
219
|
+
let cameraRight = normalize(vec3<f32>(uniforms.ViewMatrix[0][0], uniforms.ViewMatrix[1][0], uniforms.ViewMatrix[2][0]));
|
|
220
|
+
let cameraUp = normalize(vec3<f32>(uniforms.ViewMatrix[0][1], uniforms.ViewMatrix[1][1], uniforms.ViewMatrix[2][1]));
|
|
221
|
+
|
|
222
|
+
// Calculate billboard offset in world space
|
|
223
|
+
let offset2D = quad_offsets[vertex_index] * uniforms.ColourSize.w;
|
|
224
|
+
let offset3D = cameraRight * offset2D.x + cameraUp * offset2D.y;
|
|
225
|
+
let worldPos = input.position + offset3D;
|
|
226
|
+
|
|
227
|
+
output.position = uniforms.MVP * vec4<f32>(worldPos, 1.0);
|
|
228
|
+
output.fragColour = uniforms.ColourSize.rgb;
|
|
229
|
+
return output;
|
|
230
|
+
}
|
|
231
|
+
""",
|
|
232
|
+
"fragment": COLOUR_VERTEX_OUT
|
|
233
|
+
+ """
|
|
234
|
+
@fragment
|
|
235
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
236
|
+
return vec4<f32>(input.fragColour, 1.0);
|
|
237
|
+
}
|
|
238
|
+
""",
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
# Line pipeline shaders
|
|
242
|
+
LINE_SHADER_MULTI_COLOURED = {
|
|
243
|
+
"vertex": POSITION_COLOUR_VERTEX
|
|
244
|
+
+ MVP_VIEW_UNIFORM
|
|
245
|
+
+ COLOUR_VERTEX_OUT
|
|
246
|
+
+ """
|
|
247
|
+
@vertex
|
|
248
|
+
fn vs_main(input: VertexIn) -> VertexOut {
|
|
249
|
+
var output: VertexOut;
|
|
250
|
+
output.position = uniforms.MVP * vec4<f32>(input.position, 1.0);
|
|
251
|
+
output.fragColour = input.colour;
|
|
252
|
+
return output;
|
|
253
|
+
}
|
|
254
|
+
""",
|
|
255
|
+
"fragment": COLOUR_VERTEX_OUT
|
|
256
|
+
+ """
|
|
257
|
+
@fragment
|
|
258
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
259
|
+
return vec4<f32>(input.fragColour, 1.0);
|
|
260
|
+
}
|
|
261
|
+
""",
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
LINE_SHADER_SINGLE_COLOUR = {
|
|
265
|
+
"vertex": POSITION_VERTEX
|
|
266
|
+
+ MVP_COLOUR_UNIFORM
|
|
267
|
+
+ COLOUR_VERTEX_OUT
|
|
268
|
+
+ """
|
|
269
|
+
@vertex
|
|
270
|
+
fn vs_main(input: VertexIn) -> VertexOut {
|
|
271
|
+
var output: VertexOut;
|
|
272
|
+
output.position = uniforms.MVP * vec4<f32>(input.position, 1.0);
|
|
273
|
+
output.fragColour = uniforms.colour;
|
|
274
|
+
return output;
|
|
275
|
+
}
|
|
276
|
+
""",
|
|
277
|
+
"fragment": COLOUR_VERTEX_OUT
|
|
278
|
+
+ """
|
|
279
|
+
@fragment
|
|
280
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
281
|
+
return vec4<f32>(input.fragColour, 1.0);
|
|
282
|
+
}
|
|
283
|
+
""",
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
# Triangle pipeline shaders (basic placeholders to fix imports)
|
|
287
|
+
TRIANGLE_SHADER_SINGLE_COLOUR = {
|
|
288
|
+
"vertex": POSITION_VERTEX
|
|
289
|
+
+ MVP_UNIFORM
|
|
290
|
+
+ BASIC_VERTEX_OUT
|
|
291
|
+
+ """
|
|
292
|
+
@vertex
|
|
293
|
+
fn vs_main(input: VertexIn) -> VertexOut {
|
|
294
|
+
var output: VertexOut;
|
|
295
|
+
output.position = uniforms.MVP * vec4<f32>(input.position, 1.0);
|
|
296
|
+
return output;
|
|
297
|
+
}
|
|
298
|
+
""",
|
|
299
|
+
"fragment": BASIC_VERTEX_OUT
|
|
300
|
+
+ """
|
|
301
|
+
@fragment
|
|
302
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
303
|
+
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
|
304
|
+
}
|
|
305
|
+
""",
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
TRIANGLE_SHADER_MULTI_COLOURED = {
|
|
309
|
+
"vertex": POSITION_COLOUR_VERTEX
|
|
310
|
+
+ MVP_UNIFORM
|
|
311
|
+
+ COLOUR_VERTEX_OUT
|
|
312
|
+
+ """
|
|
313
|
+
@vertex
|
|
314
|
+
fn vs_main(input: VertexIn) -> VertexOut {
|
|
315
|
+
var output: VertexOut;
|
|
316
|
+
output.position = uniforms.MVP * vec4<f32>(input.position, 1.0);
|
|
317
|
+
output.fragColour = input.colour;
|
|
318
|
+
return output;
|
|
319
|
+
}
|
|
320
|
+
""",
|
|
321
|
+
"fragment": COLOUR_VERTEX_OUT
|
|
322
|
+
+ """
|
|
323
|
+
@fragment
|
|
324
|
+
fn fs_main(input: VertexOut) -> @location(0) vec4<f32> {
|
|
325
|
+
return vec4<f32>(input.fragColour, 1.0);
|
|
326
|
+
}
|
|
327
|
+
""",
|
|
328
|
+
}
|