Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shader_components.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import bge
  2. from mathutils import Vector
  3. from collections import OrderedDict
  4. try:
  5. from custom_shaders import wind as w
  6. logic = bge.logic
  7. except (ImportError, AttributeError):
  8. pass
  9. class Wind(bge.types.KX_PythonComponent):
  10. """
  11. Assign a wind shader to a material.
  12. Args:
  13. Material: The object material to which the shader should be assigned.
  14. Fast Lighting: Activate per vertex lighting instead of per pixel lighting.
  15. Wind Strength: The strength of the wind.
  16. Wind Speed: The speed of the wind movement.
  17. Object Deforming: The deforming value that set how much the geometry will be deformed.
  18. Object Bending: The bending of higher gemometry in comparison to lower level geometry.
  19. Ground Level: The height (distance from the object origin) where the geometry begins to move.
  20. Material Type: Sets the type of the material.
  21. Texture Slot: The texture slot for the diffuse texture.
  22. Normalmap Slot: The texture slot for the normalmap texture.
  23. Normal Factor: Amount normalmap affects normal values. (Similar to the setting in the texture tab)
  24. Texture Scale: The size of the texture.
  25. """
  26. args = OrderedDict([
  27. ("Material", "Material"),
  28. ("Material Type", {"Diffuse Texture", "Material Color", "Diffuse Texture (Fast Lighting)", "Material Color (Fast Lighting)", "Diffuse Texture + Normalmap", "Material Color + Normalmap"}),
  29. ("Texture Slot", 0),
  30. ("Normalmap Slot", 1),
  31. ("Normal Factor", 0.0),
  32. ("Texture Scale", Vector((1.0, 1.0))),
  33. ("Wind Strength", 0.1),
  34. ("Wind Speed", 1.0),
  35. ("Object Deforming", 0.0),
  36. ("Object Bending", 0.0),
  37. ("Ground Level", 0.0),
  38. ])
  39. def start(self, args):
  40. material = args['Material']
  41. scale = None
  42. lighting = False
  43. texture = None
  44. normalmap = None
  45. normal_factor = 0.0
  46. if args['Material Type'] in ["Diffuse Texture (Fast Lighting)", "Material Color (Fast Lighting)"]:
  47. lighting = True
  48. if args['Material Type'] in ["Diffuse Texture", "Diffuse Texture (Fast Lighting)", "Diffuse Texture + Normalmap"]:
  49. texture = args['Texture Slot']
  50. scale = args['Texture Scale']
  51. if args['Material Type'] in ["Diffuse Texture + Normalmap", "Material Color + Normalmap"]:
  52. normalmap = args['Normalmap Slot']
  53. normal_factor = args['Normal Factor']
  54. scale = args['Texture Scale']
  55. m = w.shader_utils.get_material(self.object, material)
  56. self.shader = w.WindShader(m, texture=texture, scale=scale, vertex_lighting=lighting, normalmap=normalmap, normal_factor=normal_factor)
  57. self.shader.strength = args['Wind Strength']
  58. self.shader.speed = args['Wind Speed']
  59. self.shader.deforming = args['Object Deforming']
  60. self.shader.bending = args['Object Bending']
  61. self.shader.ground = args['Ground Level']
  62. def update(self):
  63. #pass
  64. self.shader.update()