Class: Doom::Render::RayTracing::MaterialState
- Inherits:
-
Object
- Object
- Doom::Render::RayTracing::MaterialState
- Defined in:
- lib/doom/render/ray_tracing/material_state.rb
Overview
Resolves animated WAD materials and packs per-surface flags into the float shared with sector light level in the GPU triangle texture.
Constant Summary collapse
- EMISSIVE_FLAG =
1_024.0- MASKED_FLAG =
2_048.0- REFLECTIVE_FLAG =
4_096.0- REFRACTIVE_FLAG =
8_192.0- EMISSIVE_PATTERN =
/\A(?:NUKAGE|SLIME|LAVA)/- LIQUID_PATTERN =
/\A(?:NUKAGE|SLIME|LAVA|FWATER|SWATER|BLOOD)/- REFLECTIVE_PATTERN =
/#{LIQUID_PATTERN.source}|(?:METAL|SILVER|COMP|TEK|SUPPORT)/- REFRACTIVE_PATTERN =
LIQUID_PATTERN
Instance Method Summary collapse
- #animation_names ⇒ Object
- #animation_signature ⇒ Object
- #emissive?(name) ⇒ Boolean
- #encoded_light(triangle) ⇒ Object
-
#initialize(flats, animations) ⇒ MaterialState
constructor
A new instance of MaterialState.
- #reflective?(name) ⇒ Boolean
- #refractive?(name) ⇒ Boolean
- #resolve(name) ⇒ Object
Constructor Details
#initialize(flats, animations) ⇒ MaterialState
Returns a new instance of MaterialState.
18 19 20 21 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 18 def initialize(flats, animations) @flats = flats @animations = animations end |
Instance Method Details
#animation_names ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 29 def animation_names return [] unless @animations return @animations.frame_names if @animations.respond_to?(:frame_names) [@animations.flat_translation, @animations.texture_translation] .flat_map { |translation| translation.keys + translation.values } end |
#animation_signature ⇒ Object
23 24 25 26 27 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 23 def animation_signature return nil unless @animations [@animations.flat_translation.values, @animations.texture_translation.values] end |
#emissive?(name) ⇒ Boolean
43 44 45 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 43 def emissive?(name) name&.match?(EMISSIVE_PATTERN) || false end |
#encoded_light(triangle) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 55 def encoded_light(triangle) value = triangle.light.to_f value += EMISSIVE_FLAG if emissive?(triangle.material) value += MASKED_FLAG if triangle.masked value += REFLECTIVE_FLAG if reflective?(triangle.material) value += REFRACTIVE_FLAG if refractive?(triangle.material) value end |
#reflective?(name) ⇒ Boolean
47 48 49 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 47 def reflective?(name) name&.match?(REFLECTIVE_PATTERN) || false end |
#refractive?(name) ⇒ Boolean
51 52 53 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 51 def refractive?(name) name&.match?(REFRACTIVE_PATTERN) || false end |
#resolve(name) ⇒ Object
37 38 39 40 41 |
# File 'lib/doom/render/ray_tracing/material_state.rb', line 37 def resolve(name) return name unless @animations @flats.key?(name) ? @animations.translate_flat(name) : @animations.translate_texture(name) end |