gamengine3d 1.17.2__tar.gz → 1.17.5__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 (132) hide show
  1. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/PKG-INFO +1 -1
  2. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/player_movement.py +2 -2
  3. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/scripts/player_movement.py +11 -8
  4. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/helper.py +21 -10
  5. gamengine3d-1.17.5/gamengine3d/shaders/default.frag +138 -0
  6. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/PKG-INFO +1 -1
  7. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/pyproject.toml +1 -1
  8. gamengine3d-1.17.2/gamengine3d/shaders/default.frag +0 -90
  9. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/LICENSE.txt +0 -0
  10. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/README.md +0 -0
  11. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/__init__.py +0 -0
  12. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/cli.py +0 -0
  13. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/context.py +0 -0
  14. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/engine.py +0 -0
  15. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/__init__.py +0 -0
  16. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/basics.py +0 -0
  17. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/from_obj.py +0 -0
  18. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/load_scene.py +0 -0
  19. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/messages_demo.py +0 -0
  20. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/objects/__init__.py +0 -0
  21. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/objects/icosahedron.obj +0 -0
  22. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/save_scene.py +0 -0
  23. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/scripts/cylinder.py +0 -0
  24. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/scripts/message_receiver.py +0 -0
  25. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/scripts/messanger_script.py +0 -0
  26. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/scripts/settings.py +0 -0
  27. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/examples/the_everything_demo.py +0 -0
  28. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/game_objects.py +0 -0
  29. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/obj_reader.py +0 -0
  30. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/0.obj +0 -0
  31. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/1.obj +0 -0
  32. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/2.obj +0 -0
  33. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/3.obj +0 -0
  34. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/4.obj +0 -0
  35. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/5.obj +0 -0
  36. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/6.obj +0 -0
  37. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/7.obj +0 -0
  38. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/8.obj +0 -0
  39. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/9.obj +0 -0
  40. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/A_capital.obj +0 -0
  41. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/B_capital.obj +0 -0
  42. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/C_capital.obj +0 -0
  43. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/D_capital.obj +0 -0
  44. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/E_capital.obj +0 -0
  45. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/F_capital.obj +0 -0
  46. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/G_capital.obj +0 -0
  47. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/H_capital.obj +0 -0
  48. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/I_capital.obj +0 -0
  49. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/J_capital.obj +0 -0
  50. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/K_capital.obj +0 -0
  51. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/L_capital.obj +0 -0
  52. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/M_capital.obj +0 -0
  53. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/N_capital.obj +0 -0
  54. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/O_capital.obj +0 -0
  55. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/P_capital.obj +0 -0
  56. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/Q_capital.obj +0 -0
  57. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/R_capital.obj +0 -0
  58. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/S_capital.obj +0 -0
  59. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/T_capital.obj +0 -0
  60. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/U_capital.obj +0 -0
  61. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/V_capital.obj +0 -0
  62. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/W_capital.obj +0 -0
  63. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/X_capital.obj +0 -0
  64. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/Y_capital.obj +0 -0
  65. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/Z_capital.obj +0 -0
  66. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/__init__.py +0 -0
  67. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/a.obj +0 -0
  68. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/ampersand.obj +0 -0
  69. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/asterisk.obj +0 -0
  70. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/at.obj +0 -0
  71. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/b.obj +0 -0
  72. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/backslash.obj +0 -0
  73. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/brace_close.obj +0 -0
  74. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/brace_open.obj +0 -0
  75. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/bracket_close.obj +0 -0
  76. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/bracket_open.obj +0 -0
  77. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/c.obj +0 -0
  78. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/caret.obj +0 -0
  79. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/colon.obj +0 -0
  80. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/comma.obj +0 -0
  81. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/d.obj +0 -0
  82. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/dash.obj +0 -0
  83. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/dollar.obj +0 -0
  84. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/dot.obj +0 -0
  85. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/doublequote.obj +0 -0
  86. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/e.obj +0 -0
  87. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/equals.obj +0 -0
  88. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/exclamation.obj +0 -0
  89. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/f.obj +0 -0
  90. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/g.obj +0 -0
  91. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/greater.obj +0 -0
  92. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/h.obj +0 -0
  93. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/hash.obj +0 -0
  94. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/i.obj +0 -0
  95. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/j.obj +0 -0
  96. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/k.obj +0 -0
  97. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/l.obj +0 -0
  98. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/less.obj +0 -0
  99. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/m.obj +0 -0
  100. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/n.obj +0 -0
  101. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/o.obj +0 -0
  102. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/p.obj +0 -0
  103. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/paren_close.obj +0 -0
  104. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/paren_open.obj +0 -0
  105. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/percent.obj +0 -0
  106. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/plus.obj +0 -0
  107. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/q.obj +0 -0
  108. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/question.obj +0 -0
  109. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/r.obj +0 -0
  110. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/s.obj +0 -0
  111. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/semicolon.obj +0 -0
  112. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/singlequote.obj +0 -0
  113. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/slash.obj +0 -0
  114. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/t.obj +0 -0
  115. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/u.obj +0 -0
  116. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/underscore.obj +0 -0
  117. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/v.obj +0 -0
  118. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/w.obj +0 -0
  119. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/x.obj +0 -0
  120. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/y.obj +0 -0
  121. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/objects/z.obj +0 -0
  122. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/renderer.py +0 -0
  123. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/shaders/__init__.py +0 -0
  124. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/shaders/default.vert +0 -0
  125. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/shaders/depth.frag +0 -0
  126. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d/shaders/depth.vert +0 -0
  127. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/SOURCES.txt +0 -0
  128. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/dependency_links.txt +0 -0
  129. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/entry_points.txt +0 -0
  130. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/requires.txt +0 -0
  131. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/gamengine3d.egg-info/top_level.txt +0 -0
  132. {gamengine3d-1.17.2 → gamengine3d-1.17.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamengine3d
3
- Version: 1.17.2
3
+ Version: 1.17.5
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
@@ -69,12 +69,12 @@ engine.add_object(player)
69
69
 
70
70
  # Lights
71
71
  engine.add_light(Light(
72
- vector3d(1/3 * room_size.x, room_size.y, 1),
72
+ vector3d(1/3 * room_size.x, room_size.y, 0),
73
73
  Color.white,
74
74
  light_intensity
75
75
  ))
76
76
  engine.add_light(Light(
77
- vector3d(-1/3 * room_size.x, room_size.y, 1),
77
+ vector3d(-1/3 * room_size.x, room_size.y, 0),
78
78
  Color.white,
79
79
  light_intensity
80
80
  ))
@@ -1,6 +1,5 @@
1
1
  from gamengine3d import vector3d, Context, Cuboid
2
- import math
3
-
2
+ from gamengine3d.helper import get_forward
4
3
 
5
4
  class PlayerMovement: # Class name must match file name in PascalCase
6
5
  def __init__(self, obj: Cuboid, context: Context):
@@ -20,11 +19,13 @@ class PlayerMovement: # Class name must match file name in PascalCase
20
19
  self.context.on_key_held("space", callback=self.handle_controls, dt=True, args=["up"])
21
20
 
22
21
  self.obj.rotation = vector3d(0) # start facing forward
22
+ self.context.camera.set_orbiting(False)
23
23
 
24
24
 
25
25
  def update(self, dt):
26
26
  # Gravity runs every frame
27
27
  self.handle_gravity(dt)
28
+ self.handle_camera()
28
29
 
29
30
 
30
31
  def handle_controls(self, dt, direction):
@@ -85,9 +86,11 @@ class PlayerMovement: # Class name must match file name in PascalCase
85
86
  self.obj.pos += self.velocity * dt # apply gravity motion
86
87
 
87
88
 
88
- def get_forward(rotation):
89
- yaw = math.radians(rotation.z)
90
- fx = -math.sin(yaw)
91
- fy = 0
92
- fz = math.cos(yaw)
93
- return vector3d(fx, fy, fz)
89
+
90
+ def handle_camera(self):
91
+ forward = get_forward(self.obj.rotation).normalized # ensure no zero vector issues
92
+ eye_height = self.obj.size.y * 0.9 # adjust for player height
93
+ cam_pos = self.obj.pos + vector3d(0, eye_height, 0) # camera at eye level
94
+ look_target = cam_pos + forward # look straight ahead
95
+ self.context.camera.move_to(cam_pos)
96
+ self.context.camera.look_at(look_target)
@@ -329,10 +329,21 @@ class Renderer:
329
329
  def add_light(self, light):
330
330
  self.lights.append(light)
331
331
 
332
+ def _safe_normalize(self, v: vector3d, fallback: vector3d = None) -> vector3d:
333
+ """
334
+ Safely normalize a vector3d. If the vector has zero magnitude, return fallback.
335
+ Defaults to vector3d.up if fallback is None.
336
+ """
337
+ if fallback is None:
338
+ fallback = vector3d.up
339
+ if v.magnitude == 0:
340
+ return fallback
341
+ return v.normalized
342
+
332
343
  def _compute_normal(self, p1, p2, p3):
333
344
  u = p2 - p1
334
345
  v = p3 - p1
335
- return u.cross(v).normalized
346
+ return self._safe_normalize(u.cross(v))
336
347
 
337
348
  def compute_light_matrix(self, light):
338
349
  light_proj = Matrix44.orthogonal_projection(-20, 20, -20, 20, 1, 30)
@@ -354,7 +365,7 @@ class Renderer:
354
365
  def apply_matrix_normal(n: vector3d, m: Matrix44) -> vector3d:
355
366
  vec4 = np.array([n.x, n.y, n.z, 0.0], dtype="f4") # w=0 for direction
356
367
  transformed = m @ vec4
357
- return vector3d(*transformed[:3]).normalized
368
+ return self._safe_normalize(vector3d(*transformed[:3]))
358
369
 
359
370
  rot_x = Matrix44.from_x_rotation(math.radians(rotation.x))
360
371
  rot_y = Matrix44.from_y_rotation(math.radians(rotation.y))
@@ -381,9 +392,9 @@ class Renderer:
381
392
 
382
393
  # Side quad
383
394
  for tri in [(top1, bottom1, bottom2), (top1, bottom2, top2)]:
384
- n1 = (tri[0] - center).normalized
385
- n2 = (tri[1] - center).normalized
386
- n3 = (tri[2] - center).normalized
395
+ n1 = self._safe_normalize(tri[0] - center)
396
+ n2 = self._safe_normalize(tri[1] - center)
397
+ n3 = self._safe_normalize(tri[2] - center)
387
398
  vertices.extend([
388
399
  *tri[0].totuple(), *color.to_rgb(), *n1.totuple(),
389
400
  *tri[1].totuple(), *color.to_rgb(), *n2.totuple(),
@@ -433,9 +444,9 @@ class Renderer:
433
444
  radius * math.sin(theta1) * math.sin(phi2)) + center
434
445
 
435
446
  for tri in [(p1, p2, p3), (p1, p3, p4)]:
436
- n1 = (tri[0] - center).normalized
437
- n2 = (tri[1] - center).normalized
438
- n3 = (tri[2] - center).normalized
447
+ n1 = self._safe_normalize(tri[0] - center)
448
+ n2 = self._safe_normalize(tri[1] - center)
449
+ n3 = self._safe_normalize(tri[2] - center)
439
450
  vertices.extend([
440
451
  *tri[0].totuple(), *color.to_rgb(), *n1.totuple(),
441
452
  *tri[1].totuple(), *color.to_rgb(), *n2.totuple(),
@@ -505,7 +516,7 @@ class Renderer:
505
516
  # === Modified render calls to batch ===
506
517
 
507
518
  def render_plane(self, p1, p2, p3, color):
508
- normal = self._compute_normal(p1, p2, p3)
519
+ normal = self._safe_normalize(self._compute_normal(p1, p2, p3))
509
520
  vertices = [
510
521
  *p1.totuple(), *color.to_rgb(), *normal.totuple(),
511
522
  *p2.totuple(), *color.to_rgb(), *normal.totuple(),
@@ -514,7 +525,7 @@ class Renderer:
514
525
  self._append_vertices(vertices)
515
526
 
516
527
  def render_quad(self, p1, p2, p3, p4, color):
517
- normal = self._compute_normal(p1, p2, p3)
528
+ normal = self._safe_normalize(self._compute_normal(p1, p2, p3))
518
529
  vertices = [
519
530
  *p1.totuple(), *color.to_rgb(), *normal.totuple(),
520
531
  *p2.totuple(), *color.to_rgb(), *normal.totuple(),
@@ -0,0 +1,138 @@
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;
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
+ // ---- internal tuning (shader-only, tweak visually) ----
24
+ const float LIGHT_SIZE_APPROX = 0.25; // tune for larger/smaller penumbrae (shader-only)
25
+ const int BLOCKER_SEARCH_RADIUS = 2; // coarse search radius (in samples; 2 -> 5x5)
26
+ const int PCF_MAX_RADIUS = 6; // max PCF radius (in samples; 6 -> 13x13 kernel max)
27
+ const float MIN_BIAS = 0.0005;
28
+ const float MAX_BIAS_SCALE = 0.005;
29
+
30
+ void main() {
31
+ vec3 normal = normalize(frag_normal);
32
+ vec3 color = frag_color / 255.0;
33
+ vec3 result = ambient * color;
34
+
35
+ for (int i = 0; i < num_lights; i++) {
36
+ vec3 light_dir = normalize(lights[i].position - frag_pos);
37
+
38
+ // ----- Physically-correct attenuation -----
39
+ float dist = length(lights[i].position - frag_pos);
40
+ float attenuation = 1.0 / (dist * dist + 0.001);
41
+
42
+ // ----- Diffuse (Lambert) -----
43
+ float diff = max(dot(normal, light_dir), 0.0);
44
+
45
+ // ----- Specular (Blinn-Phong) -----
46
+ vec3 view_dir = normalize(-frag_pos); // camera at origin for now
47
+ vec3 half_dir = normalize(light_dir + view_dir);
48
+
49
+ float shininess = 32.0;
50
+ float spec = pow(max(dot(normal, half_dir), 0.0), shininess);
51
+
52
+ // ----- Shadow (PCSS-like approximation using sampler2DShadow only) -----
53
+ vec3 proj_coords = frag_pos_light_space.xyz / frag_pos_light_space.w;
54
+ proj_coords = proj_coords * 0.5 + 0.5;
55
+
56
+ float shadow = 1.0;
57
+
58
+ if (proj_coords.x >= 0.0 && proj_coords.x <= 1.0 &&
59
+ proj_coords.y >= 0.0 && proj_coords.y <= 1.0) {
60
+
61
+ // normal-dependent bias
62
+ float ndotl = dot(normal, light_dir);
63
+ float bias = max(MAX_BIAS_SCALE * (1.0 - ndotl), MIN_BIAS);
64
+
65
+ ivec2 texSize = textureSize(shadow_map, 0);
66
+ float texelSizeX = 1.0 / float(texSize.x);
67
+ float texelSizeY = 1.0 / float(texSize.y);
68
+
69
+ // --- 1) Blocker search (coarse). Count how many samples are blockers.
70
+ int searchCount = 0;
71
+ int blockerCount = 0;
72
+
73
+ for (int sx = -BLOCKER_SEARCH_RADIUS; sx <= BLOCKER_SEARCH_RADIUS; ++sx) {
74
+ for (int sy = -BLOCKER_SEARCH_RADIUS; sy <= BLOCKER_SEARCH_RADIUS; ++sy) {
75
+ vec2 offset = vec2(float(sx) * texelSizeX, float(sy) * texelSizeY);
76
+ // texture(shadow_map, vec3(uv, refDepth)) returns 1.0 if lit, 0.0 if blocked
77
+ float cmp = texture(shadow_map, vec3(proj_coords.xy + offset, proj_coords.z - bias));
78
+ searchCount++;
79
+ if (cmp < 0.5) { // considered a blocker
80
+ blockerCount++;
81
+ }
82
+ }
83
+ }
84
+
85
+ // If no blockers, fully lit (no shadow)
86
+ if (blockerCount == 0) {
87
+ shadow = 1.0;
88
+ } else {
89
+ // --- 2) Compute a penumbra radius from blocker ratio and distance
90
+ // blockerRatio ranges 0..1
91
+ float blockerRatio = float(blockerCount) / float(searchCount);
92
+
93
+ // Map blockerRatio -> radius in texel samples (approx)
94
+ // Larger distance increases apparent penumbra; scale by LIGHT_SIZE_APPROX and dist
95
+ float radiusFactor = clamp(blockerRatio, 0.0, 1.0);
96
+ // base radius mapped from ratio
97
+ float baseRadius = mix(1.0, float(PCF_MAX_RADIUS), radiusFactor);
98
+
99
+ // scale with fragment-to-light distance (tuneable)
100
+ float distScale = clamp(dist / 10.0, 0.5, 4.0);
101
+ float radiusSamples = clamp(baseRadius * distScale * LIGHT_SIZE_APPROX * 4.0, 1.0, float(PCF_MAX_RADIUS));
102
+
103
+ // normalize radius to [0,1] relative to PCF_MAX_RADIUS to scale offsets
104
+ float radiusNorm = radiusSamples / float(PCF_MAX_RADIUS);
105
+
106
+ // --- 3) Final PCF using scaled sampling kernel (fixed loop bounds but scaled offsets)
107
+ // We'll sample a (2*PCF_MAX_RADIUS+1)^2 kernel and scale sample offsets by radiusNorm
108
+ float sum = 0.0;
109
+ float count = 0.0;
110
+
111
+ for (int x = -PCF_MAX_RADIUS; x <= PCF_MAX_RADIUS; ++x) {
112
+ for (int y = -PCF_MAX_RADIUS; y <= PCF_MAX_RADIUS; ++y) {
113
+ // scale offsets by radiusNorm so effective kernel size changes dynamically
114
+ vec2 offset = vec2(float(x) * texelSizeX * radiusNorm,
115
+ float(y) * texelSizeY * radiusNorm);
116
+ sum += texture(shadow_map, vec3(proj_coords.xy + offset, proj_coords.z - bias));
117
+ count += 1.0;
118
+ }
119
+ }
120
+
121
+ shadow = sum / count;
122
+
123
+ // Slightly smooth the final shadow value to avoid hard quantization
124
+ shadow = smoothstep(0.0, 1.0, shadow);
125
+ }
126
+ }
127
+
128
+ // ----- Final Lighting -----
129
+ vec3 lightColor = lights[i].color * lights[i].intensity;
130
+
131
+ vec3 diffuse = diff * lightColor * attenuation;
132
+ vec3 specular = spec * lightColor * attenuation;
133
+
134
+ result += shadow * (diffuse + specular) * color;
135
+ }
136
+
137
+ f_color = vec4(result, 1.0);
138
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamengine3d
3
- Version: 1.17.2
3
+ Version: 1.17.5
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
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "gamengine3d"
8
- version = "1.17.2"
8
+ version = "1.17.5"
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,90 +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
- uniform sampler2DShadow shadow_map;
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
-
31
- // ----- Physically-correct attenuation -----
32
- float dist = length(lights[i].position - frag_pos);
33
- float attenuation = 1.0 / (dist * dist + 0.001);
34
-
35
- // ----- Diffuse (Lambert) -----
36
- float diff = max(dot(normal, light_dir), 0.0);
37
-
38
- // ----- Specular (Blinn-Phong) -----
39
- vec3 view_dir = normalize(-frag_pos); // camera at origin for now
40
- vec3 half_dir = normalize(light_dir + view_dir);
41
-
42
- float shininess = 32.0;
43
- float spec = pow(max(dot(normal, half_dir), 0.0), shininess);
44
-
45
- // ----- Shadow -----
46
- vec3 proj_coords = frag_pos_light_space.xyz / frag_pos_light_space.w;
47
- proj_coords = proj_coords * 0.5 + 0.5;
48
-
49
- float shadow = 1.0;
50
-
51
- if (proj_coords.x >= 0.0 && proj_coords.x <= 1.0 &&
52
- proj_coords.y >= 0.0 && proj_coords.y <= 1.0) {
53
-
54
- float ndotl = dot(normal, light_dir);
55
-
56
- // Better normal-dependent bias
57
- float bias = max(0.005 * (1.0 - ndotl), 0.0005);
58
-
59
- ivec2 texSize = textureSize(shadow_map, 0);
60
- float texelSizeX = 1.0 / float(texSize.x);
61
- float texelSizeY = 1.0 / float(texSize.y);
62
-
63
- // ---- 5x5 PCF kernel ----
64
- shadow = 0.0;
65
- for (int x = -2; x <= 2; ++x) {
66
- for (int y = -2; y <= 2; ++y) {
67
- vec2 offset = vec2(float(x) * texelSizeX,
68
- float(y) * texelSizeY);
69
- shadow += texture(shadow_map,
70
- vec3(proj_coords.xy + offset,
71
- proj_coords.z - bias));
72
- }
73
- }
74
- shadow /= 25.0;
75
-
76
- // smooth the edges
77
- shadow = smoothstep(0.0, 1.0, shadow);
78
- }
79
-
80
- // ----- Final Lighting -----
81
- vec3 lightColor = lights[i].color * lights[i].intensity;
82
-
83
- vec3 diffuse = diff * lightColor * attenuation;
84
- vec3 specular = spec * lightColor * attenuation;
85
-
86
- result += shadow * (diffuse + specular) * color;
87
- }
88
-
89
- f_color = vec4(result, 1.0);
90
- }
File without changes
File without changes
File without changes