gamengine3d 1.2.0__tar.gz → 1.3.0__tar.gz

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.
Files changed (22) hide show
  1. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/PKG-INFO +1 -1
  2. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/engine.py +1 -0
  3. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/helper.py +124 -105
  4. gamengine3d-1.3.0/gamengine3d/shaders/default.frag +63 -0
  5. gamengine3d-1.3.0/gamengine3d/shaders/default.vert +24 -0
  6. gamengine3d-1.3.0/gamengine3d/shaders/depth.frag +2 -0
  7. gamengine3d-1.3.0/gamengine3d/shaders/depth.vert +9 -0
  8. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d.egg-info/PKG-INFO +1 -1
  9. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d.egg-info/SOURCES.txt +3 -1
  10. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/pyproject.toml +1 -1
  11. gamengine3d-1.2.0/gamengine3d/shaders/default.frag +0 -33
  12. gamengine3d-1.2.0/gamengine3d/shaders/default.vert +0 -20
  13. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/LICENSE.txt +0 -0
  14. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/README.md +0 -0
  15. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/__init__.py +0 -0
  16. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/context.py +0 -0
  17. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/game_objects.py +0 -0
  18. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d/shaders/__init__.py +0 -0
  19. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d.egg-info/dependency_links.txt +0 -0
  20. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d.egg-info/requires.txt +0 -0
  21. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/gamengine3d.egg-info/top_level.txt +0 -0
  22. {gamengine3d-1.2.0 → gamengine3d-1.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamengine3d
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A Unity-like 3D engine in Python using pygame
5
5
  Author-email: Samarth Javagal <samarthjavagal@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -128,6 +128,7 @@ class Engine:
128
128
  self.context.keys_released = keys_released
129
129
  self.context.update(dt)
130
130
 
131
+ self.renderer.render_shadow_pass(self.gameobjects)
131
132
  self.renderer.clear(self.background_color)
132
133
  self.camera.update_renderer(self.renderer)
133
134
 
@@ -227,11 +227,13 @@ class Light:
227
227
  self.show = show
228
228
  self.name = name
229
229
 
230
+
230
231
  class Renderer:
231
232
  def __init__(self, width=800, height=600, flags=DOUBLEBUF | OPENGL):
232
233
  pygame.init()
233
234
  self.screen = pygame.display.set_mode((width, height), flags)
234
235
  self.ctx = moderngl.create_context()
236
+ self.ctx.viewport = (0, 0, width, height)
235
237
  self.samples = 4
236
238
  self.color_tex = self.ctx.texture((width, height), 3, samples=self.samples)
237
239
  self.depth_rbo = self.ctx.depth_renderbuffer((width, height), samples=self.samples)
@@ -241,6 +243,8 @@ class Renderer:
241
243
  self.height = height
242
244
  self.ambient = 0.2
243
245
  self.ctx.enable(moderngl.DEPTH_TEST)
246
+
247
+ # === Main shader ===
244
248
  self.prog = self._load_shader("default.vert", "default.frag")
245
249
  self.prog["model"].write(np.eye(4, dtype="f4").tobytes())
246
250
  self.proj = Matrix44.perspective_projection(60.0, width / height, 0.1, 100.0)
@@ -252,6 +256,22 @@ class Renderer:
252
256
  self.mvp = self.proj * self.view
253
257
  self.prog["mvp"].write(self.mvp.astype("f4").tobytes())
254
258
  self.prog["ambient"].value = self.ambient
259
+
260
+ # === Shadow map setup ===
261
+ self.shadow_size = 2048
262
+ self.shadow_depth_tex = self.ctx.depth_texture((self.shadow_size, self.shadow_size))
263
+ try:
264
+ self.shadow_depth_tex.repeat_x = False
265
+ self.shadow_depth_tex.repeat_y = False
266
+ except Exception:
267
+ pass
268
+ self.shadow_fbo = self.ctx.framebuffer(depth_attachment=self.shadow_depth_tex)
269
+ self.depth_prog = self._load_shader("depth.vert", "depth.frag")
270
+ self.light_space_matrix = np.eye(4, dtype="f4")
271
+
272
+ # ------------------------------------------
273
+ # Window / Resize Handling
274
+ # ------------------------------------------
255
275
  def resize(self, width, height):
256
276
  self.width = width
257
277
  self.height = height
@@ -262,26 +282,93 @@ class Renderer:
262
282
 
263
283
  self.ctx = moderngl.create_context()
264
284
  self.ctx.viewport = (0, 0, width, height)
285
+
286
+ # Recreate framebuffer and textures for new context
265
287
  self.color_tex = self.ctx.texture((width, height), 3, samples=self.samples)
266
288
  self.depth_rbo = self.ctx.depth_renderbuffer((width, height), samples=self.samples)
267
289
  self.fbo = self.ctx.framebuffer(color_attachments=[self.color_tex], depth_attachment=self.depth_rbo)
268
290
 
291
+ # Recreate shaders in new context
269
292
  self.prog = self._load_shader("default.vert", "default.frag")
270
293
  self.prog["model"].write(np.eye(4, dtype="f4").tobytes())
271
-
272
294
  aspect = width / height
273
295
  self.proj = Matrix44.perspective_projection(60.0, aspect, 0.1, 100.0)
274
296
  self.mvp = self.proj * self.view
275
297
  self.prog["mvp"].write(self.mvp.astype("f4").tobytes())
276
298
  self.prog["ambient"].value = self.ambient
277
299
 
300
+ # Recreate shadow map resources for this context
301
+ self.shadow_depth_tex = self.ctx.depth_texture((self.shadow_size, self.shadow_size))
302
+ try:
303
+ self.shadow_depth_tex.repeat_x = False
304
+ self.shadow_depth_tex.repeat_y = False
305
+ except Exception:
306
+ pass
307
+ self.shadow_fbo = self.ctx.framebuffer(depth_attachment=self.shadow_depth_tex)
308
+ self.depth_prog = self._load_shader("depth.vert", "depth.frag")
309
+
278
310
  self._send_lights()
311
+
312
+ # ------------------------------------------
313
+ # Light & Matrix
314
+ # ------------------------------------------
279
315
  def add_light(self, light: Light):
280
316
  self.lights.append(light)
317
+
281
318
  def _compute_normal(self, p1, p2, p3):
282
319
  u = p2 - p1
283
320
  v = p3 - p1
284
321
  return u.cross(v).normalized
322
+
323
+ def compute_light_matrix(self, light: Light):
324
+ """Compute light-space projection * view for shadow mapping."""
325
+ light_proj = Matrix44.orthogonal_projection(-10, 10, -10, 10, 1, 30)
326
+ light_view = Matrix44.look_at(
327
+ eye=light.position.totuple(),
328
+ target=(0, 0, 0),
329
+ up=(0, 1, 0)
330
+ )
331
+ return light_proj * light_view
332
+
333
+ # ------------------------------------------
334
+ # Shadow Pass
335
+ # ------------------------------------------
336
+ def render_shadow_pass(self, objects):
337
+ """Render depth map from light's POV."""
338
+ if not self.lights:
339
+ return
340
+ light = self.lights[0]
341
+ self.light_space_matrix = self.compute_light_matrix(light)
342
+
343
+ self.shadow_fbo.clear(depth=1.0)
344
+ self.shadow_fbo.use()
345
+ self.ctx.enable(moderngl.DEPTH_TEST)
346
+
347
+ for obj in objects:
348
+ if not hasattr(obj, "get_corners"):
349
+ continue
350
+ corners = obj.get_corners()
351
+ vertices = []
352
+ for face in obj.faces:
353
+ p1, p2, p3, p4 = [corners[i] for i in face]
354
+ vertices.extend([
355
+ *p1.totuple(), *p2.totuple(), *p3.totuple(),
356
+ *p1.totuple(), *p3.totuple(), *p4.totuple()
357
+ ])
358
+ vertices = np.array(vertices, dtype="f4")
359
+ vbo = self.ctx.buffer(vertices.tobytes())
360
+ vao = self.ctx.vertex_array(self.depth_prog, [(vbo, "3f", "in_vert")])
361
+ self.depth_prog["model"].write(np.eye(4, dtype="f4").tobytes())
362
+ self.depth_prog["light_space_matrix"].write(self.light_space_matrix.astype("f4").tobytes())
363
+ vao.render()
364
+ vao.release()
365
+ vbo.release()
366
+
367
+ self.ctx.screen.use()
368
+
369
+ # ------------------------------------------
370
+ # Render Functions
371
+ # ------------------------------------------
285
372
  def render_plane(self, p1, p2, p3, color):
286
373
  normal = self._compute_normal(p1, p2, p3)
287
374
  vertices = np.array([
@@ -291,13 +378,16 @@ class Renderer:
291
378
  ], dtype="f4")
292
379
  vbo = self.ctx.buffer(vertices.tobytes())
293
380
  vao = self.ctx.vertex_array(
294
- self.prog,
295
- [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
381
+ self.prog, [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
296
382
  )
297
383
  self._send_lights()
384
+ self.prog["light_space_matrix"].write(self.light_space_matrix.astype("f4").tobytes())
385
+ self.shadow_depth_tex.use(location=0)
386
+ self.prog["shadow_map"].value = 0
298
387
  vao.render()
299
388
  vao.release()
300
389
  vbo.release()
390
+
301
391
  def render_quad(self, p1, p2, p3, p4, color):
302
392
  normal = self._compute_normal(p1, p2, p3)
303
393
  vertices = np.array([
@@ -310,42 +400,36 @@ class Renderer:
310
400
  ], dtype="f4")
311
401
  vbo = self.ctx.buffer(vertices.tobytes())
312
402
  vao = self.ctx.vertex_array(
313
- self.prog,
314
- [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
403
+ self.prog, [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
315
404
  )
316
405
  self._send_lights()
406
+ self.prog["light_space_matrix"].write(self.light_space_matrix.astype("f4").tobytes())
407
+ self.shadow_depth_tex.use(location=0)
408
+ self.prog["shadow_map"].value = 0
317
409
  vao.render()
318
410
  vao.release()
319
411
  vbo.release()
412
+
320
413
  def render_sphere(self, center, radius, color, segments=32, rings=16):
321
414
  vertices = []
322
- normals = []
323
415
  for i in range(rings):
324
416
  theta1 = math.pi * i / rings
325
417
  theta2 = math.pi * (i + 1) / rings
326
418
  for j in range(segments):
327
419
  phi1 = 2 * math.pi * j / segments
328
420
  phi2 = 2 * math.pi * (j + 1) / segments
329
- p1 = vector3d(
330
- radius * math.sin(theta1) * math.cos(phi1),
331
- radius * math.cos(theta1),
332
- radius * math.sin(theta1) * math.sin(phi1)
333
- ) + center
334
- p2 = vector3d(
335
- radius * math.sin(theta2) * math.cos(phi1),
336
- radius * math.cos(theta2),
337
- radius * math.sin(theta2) * math.sin(phi1)
338
- ) + center
339
- p3 = vector3d(
340
- radius * math.sin(theta2) * math.cos(phi2),
341
- radius * math.cos(theta2),
342
- radius * math.sin(theta2) * math.sin(phi2)
343
- ) + center
344
- p4 = vector3d(
345
- radius * math.sin(theta1) * math.cos(phi2),
346
- radius * math.cos(theta1),
347
- radius * math.sin(theta1) * math.sin(phi2)
348
- ) + center
421
+ p1 = vector3d(radius * math.sin(theta1) * math.cos(phi1),
422
+ radius * math.cos(theta1),
423
+ radius * math.sin(theta1) * math.sin(phi1)) + center
424
+ p2 = vector3d(radius * math.sin(theta2) * math.cos(phi1),
425
+ radius * math.cos(theta2),
426
+ radius * math.sin(theta2) * math.sin(phi1)) + center
427
+ p3 = vector3d(radius * math.sin(theta2) * math.cos(phi2),
428
+ radius * math.cos(theta2),
429
+ radius * math.sin(theta2) * math.sin(phi2)) + center
430
+ p4 = vector3d(radius * math.sin(theta1) * math.cos(phi2),
431
+ radius * math.cos(theta1),
432
+ radius * math.sin(theta1) * math.sin(phi2)) + center
349
433
  for tri in [(p1, p2, p3), (p1, p3, p4)]:
350
434
  n1 = (tri[0] - center).normalized
351
435
  n2 = (tri[1] - center).normalized
@@ -358,88 +442,19 @@ class Renderer:
358
442
  vertices = np.array(vertices, dtype="f4")
359
443
  vbo = self.ctx.buffer(vertices.tobytes())
360
444
  vao = self.ctx.vertex_array(
361
- self.prog,
362
- [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
363
- )
364
- self._send_lights()
365
- vao.render()
366
- vao.release()
367
- vbo.release()
368
- def render_cylinder(self, center, height, radius, color, segments=32, rotation=vector3d.zero):
369
- vertices = []
370
- half_h = height / 2.0
371
- rx, ry, rz = map(math.radians, (rotation.x, rotation.y, rotation.z))
372
- rot_x = np.array([
373
- [1, 0, 0],
374
- [0, math.cos(rx), -math.sin(rx)],
375
- [0, math.sin(rx), math.cos(rx)]
376
- ], dtype="f4")
377
- rot_y = np.array([
378
- [ math.cos(ry), 0, math.sin(ry)],
379
- [0, 1, 0],
380
- [-math.sin(ry), 0, math.cos(ry)]
381
- ], dtype="f4")
382
- rot_z = np.array([
383
- [math.cos(rz), -math.sin(rz), 0],
384
- [math.sin(rz), math.cos(rz), 0],
385
- [0, 0, 1]
386
- ], dtype="f4")
387
- # Combined rotation matrix (Z * Y * X)
388
- rotation_matrix = rot_z @ rot_y @ rot_x
389
- def apply_rotation(v: vector3d):
390
- vec = np.array([[v.x], [v.y], [v.z]], dtype="f4")
391
- rotated = rotation_matrix @ vec
392
- return vector3d(rotated[0][0], rotated[1][0], rotated[2][0])
393
- for i in range(segments):
394
- theta1 = 2 * math.pi * i / segments
395
- theta2 = 2 * math.pi * (i + 1) / segments
396
- x1, z1 = radius * math.cos(theta1), radius * math.sin(theta1)
397
- x2, z2 = radius * math.cos(theta2), radius * math.sin(theta2)
398
- # Cylinder face vertices
399
- p1 = vector3d(x1, -half_h, z1)
400
- p2 = vector3d(x2, -half_h, z2)
401
- p3 = vector3d(x2, half_h, z2)
402
- p4 = vector3d(x1, half_h, z1)
403
- # Apply rotation
404
- p1 = apply_rotation(p1) + center
405
- p2 = apply_rotation(p2) + center
406
- p3 = apply_rotation(p3) + center
407
- p4 = apply_rotation(p4) + center
408
- n1 = apply_rotation(vector3d(x1, 0, z1).normalized)
409
- n2 = apply_rotation(vector3d(x2, 0, z2).normalized)
410
- # Side faces
411
- vertices.extend([
412
- *p1.totuple(), *color.to_rgb(), *n1.totuple(),
413
- *p2.totuple(), *color.to_rgb(), *n2.totuple(),
414
- *p3.totuple(), *color.to_rgb(), *n2.totuple(),
415
- *p1.totuple(), *color.to_rgb(), *n1.totuple(),
416
- *p3.totuple(), *color.to_rgb(), *n2.totuple(),
417
- *p4.totuple(), *color.to_rgb(), *n1.totuple(),
418
- ])
419
- # Base
420
- base_normal = apply_rotation(vector3d(0, -1, 0))
421
- vertices.extend([
422
- *apply_rotation(vector3d(0, -half_h, 0) + center).totuple(), *color.to_rgb(), *base_normal.totuple(),
423
- *p2.totuple(), *color.to_rgb(), *base_normal.totuple(),
424
- *p1.totuple(), *color.to_rgb(), *base_normal.totuple(),
425
- ])
426
- # Top
427
- top_normal = apply_rotation(vector3d(0, 1, 0))
428
- vertices.extend([
429
- *apply_rotation(vector3d(0, half_h, 0) + center).totuple(), *color.to_rgb(), *top_normal.totuple(),
430
- *p4.totuple(), *color.to_rgb(), *top_normal.totuple(),
431
- *p3.totuple(), *color.to_rgb(), *top_normal.totuple(),
432
- ])
433
- vertices = np.array(vertices, dtype="f4")
434
- vbo = self.ctx.buffer(vertices.tobytes())
435
- vao = self.ctx.vertex_array(
436
- self.prog,
437
- [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
445
+ self.prog, [(vbo, "3f 3f 3f", "in_vert", "in_color", "in_normal")]
438
446
  )
439
447
  self._send_lights()
448
+ self.prog["light_space_matrix"].write(self.light_space_matrix.astype("f4").tobytes())
449
+ self.shadow_depth_tex.use(location=0)
450
+ self.prog["shadow_map"].value = 0
440
451
  vao.render()
441
452
  vao.release()
442
453
  vbo.release()
454
+
455
+ # ------------------------------------------
456
+ # Utility
457
+ # ------------------------------------------
443
458
  def _send_lights(self):
444
459
  max_lights = 8
445
460
  num_lights = min(len(self.lights), max_lights)
@@ -450,18 +465,22 @@ class Renderer:
450
465
  self.prog[f"lights[{i}].position"].value = light.position.totuple()
451
466
  self.prog[f"lights[{i}].color"].value = tuple(c / 255 for c in light.color.to_rgb())
452
467
  self.prog[f"lights[{i}].intensity"].value = light.intensity
468
+
453
469
  def clear(self, color=Color(26, 26, 31)):
454
470
  color_f = np.array(color.to_rgb(), dtype="f4") / 255.0
455
471
  self.fbo.clear(*color_f, depth=1.0)
456
472
  self.fbo.use()
473
+
457
474
  def swap(self):
458
475
  self.ctx.copy_framebuffer(dst=self.ctx.screen, src=self.fbo)
459
476
  pygame.display.flip()
477
+
460
478
  def quit(self):
461
479
  pygame.quit()
480
+
462
481
  def _load_shader(self, vert_name, frag_name):
463
- vert_src = pkg_resources.read_text(f"{__package__}.shaders", "default.vert")
464
- frag_src = pkg_resources.read_text(f"{__package__}.shaders", "default.frag")
482
+ vert_src = pkg_resources.read_text(f"{__package__}.shaders", vert_name)
483
+ frag_src = pkg_resources.read_text(f"{__package__}.shaders", frag_name)
465
484
  return self.ctx.program(vertex_shader=vert_src, fragment_shader=frag_src)
466
485
 
467
486
  class Camera:
@@ -0,0 +1,63 @@
1
+
2
+ #version 330
3
+
4
+ struct Light {
5
+ vec3 position;
6
+ vec3 color;
7
+ float intensity;
8
+ };
9
+
10
+ #define MAX_LIGHTS 8
11
+ uniform int num_lights;
12
+ uniform Light lights[MAX_LIGHTS];
13
+ uniform float ambient;
14
+ uniform sampler2DShadow shadow_map; // NOTE: sampler2DShadow
15
+
16
+ in vec3 frag_pos;
17
+ in vec3 frag_normal;
18
+ in vec3 frag_color;
19
+ in vec4 frag_pos_light_space;
20
+
21
+ out vec4 f_color;
22
+
23
+ void main() {
24
+ vec3 normal = normalize(frag_normal);
25
+ vec3 color = frag_color / 255.0;
26
+ vec3 result = ambient * color;
27
+
28
+ for (int i = 0; i < num_lights; i++) {
29
+ vec3 light_dir = normalize(lights[i].position - frag_pos);
30
+ float diff = max(dot(normal, light_dir), 0.0);
31
+
32
+ // Project to [0,1] for shadow sampling
33
+ vec3 proj_coords = frag_pos_light_space.xyz / frag_pos_light_space.w;
34
+ proj_coords = proj_coords * 0.5 + 0.5;
35
+
36
+ // Hardware PCF shadow sampling
37
+ float shadow = 0.0;
38
+ if (proj_coords.x >= 0.0 && proj_coords.x <= 1.0 &&
39
+ proj_coords.y >= 0.0 && proj_coords.y <= 1.0) {
40
+
41
+ float bias = max(0.02 * (1.0 - dot(normal, light_dir)), 0.005);
42
+
43
+ // Simple 3x3 PCF
44
+ ivec2 texSize = textureSize(shadow_map, 0);
45
+ float texelSizeX = 1.0 / float(texSize.x);
46
+ float texelSizeY = 1.0 / float(texSize.y);
47
+
48
+ for (int x = -1; x <= 1; ++x) {
49
+ for (int y = -1; y <= 1; ++y) {
50
+ vec2 offset = vec2(float(x) * texelSizeX, float(y) * texelSizeY);
51
+ shadow += texture(shadow_map, vec3(proj_coords.xy + offset, proj_coords.z - bias));
52
+ }
53
+ }
54
+ shadow /= 9.0;
55
+ }
56
+
57
+
58
+ // No inversion needed
59
+ result += shadow * diff * lights[i].intensity * lights[i].color * color;
60
+ }
61
+
62
+ f_color = vec4(result, 1.0);
63
+ }
@@ -0,0 +1,24 @@
1
+
2
+ #version 330
3
+
4
+ in vec3 in_vert;
5
+ in vec3 in_color;
6
+ in vec3 in_normal;
7
+
8
+ out vec3 frag_pos;
9
+ out vec3 frag_normal;
10
+ out vec3 frag_color;
11
+ out vec4 frag_pos_light_space;
12
+
13
+ uniform mat4 mvp;
14
+ uniform mat4 model;
15
+ uniform mat4 light_space_matrix;
16
+
17
+ void main() {
18
+ vec4 world_pos = model * vec4(in_vert, 1.0);
19
+ frag_pos = world_pos.xyz;
20
+ frag_normal = mat3(transpose(inverse(model))) * in_normal;
21
+ frag_color = in_color;
22
+ frag_pos_light_space = light_space_matrix * world_pos;
23
+ gl_Position = mvp * vec4(in_vert, 1.0);
24
+ }
@@ -0,0 +1,2 @@
1
+ #version 330
2
+ void main() { }
@@ -0,0 +1,9 @@
1
+ #version 330
2
+
3
+ layout(location = 0) in vec3 in_vert;
4
+ uniform mat4 light_space_matrix;
5
+ uniform mat4 model;
6
+
7
+ void main() {
8
+ gl_Position = light_space_matrix * model * vec4(in_vert, 1.0);
9
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamengine3d
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A Unity-like 3D engine in Python using pygame
5
5
  Author-email: Samarth Javagal <samarthjavagal@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -13,4 +13,6 @@ gamengine3d.egg-info/requires.txt
13
13
  gamengine3d.egg-info/top_level.txt
14
14
  gamengine3d/shaders/__init__.py
15
15
  gamengine3d/shaders/default.frag
16
- gamengine3d/shaders/default.vert
16
+ gamengine3d/shaders/default.vert
17
+ gamengine3d/shaders/depth.frag
18
+ gamengine3d/shaders/depth.vert
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "gamengine3d"
8
- version = "1.2.0"
8
+ version = "1.3.0"
9
9
  description = "A Unity-like 3D engine in Python using pygame"
10
10
  authors = [
11
11
  { name = "Samarth Javagal", email = "samarthjavagal@gmail.com" }
@@ -1,33 +0,0 @@
1
-
2
- #version 330
3
-
4
- struct Light {
5
- vec3 position;
6
- vec3 color;
7
- float intensity;
8
- };
9
-
10
- #define MAX_LIGHTS 8
11
- uniform int num_lights;
12
- uniform Light lights[MAX_LIGHTS];
13
- uniform float ambient;
14
-
15
- in vec3 frag_pos;
16
- in vec3 frag_normal;
17
- in vec3 frag_color;
18
-
19
- out vec4 f_color;
20
-
21
- void main() {
22
- vec3 normal = normalize(frag_normal);
23
- vec3 color = frag_color / 255.0; // <-- convert vertex color to 0-1
24
- vec3 result = ambient * color;
25
-
26
- for (int i = 0; i < num_lights; i++) {
27
- vec3 light_dir = normalize(lights[i].position - frag_pos);
28
- float diff = max(dot(normal, light_dir), 0.0);
29
- result += diff * lights[i].intensity * lights[i].color * color;
30
- }
31
-
32
- f_color = vec4(result, 1.0);
33
- }
@@ -1,20 +0,0 @@
1
-
2
- #version 330
3
-
4
- in vec3 in_vert;
5
- in vec3 in_color;
6
- in vec3 in_normal;
7
-
8
- out vec3 frag_pos;
9
- out vec3 frag_normal;
10
- out vec3 frag_color;
11
-
12
- uniform mat4 mvp;
13
- uniform mat4 model; // optional if you want model transforms
14
-
15
- void main() {
16
- frag_pos = vec3(model * vec4(in_vert, 1.0)); // world space position
17
- frag_normal = mat3(transpose(inverse(model))) * in_normal; // transform normal
18
- frag_color = in_color;
19
- gl_Position = mvp * vec4(in_vert, 1.0);
20
- }
File without changes
File without changes
File without changes