Class: Bestguigui::GouraudShading

Inherits:
Object
  • Object
show all
Defined in:
lib/bestguigui_lab/gouraud_shading.rb

Overview

Calcule une couleur par sommet à partir de sa normale et d'une lumière fixe, quantifiée en peu de nuances par canal — utilisé par ObjModel en mode shading: :gouraud pour simuler, en plus de la texture (elle la module, ne la remplace pas), un rendu façon modèles de perso PSX (FF7 & co) : pas de lumière OpenGL temps réel, un effet "en bandes" plutôt qu'un dégradé lisse.

Constant Summary collapse

LIGHT_DIRECTION =

direction fixe

[0.4, 0.8, 0.4].freeze
AMBIENT =

part de lumière reçue même côté ombre

0.35
COLOR_LEVELS =

teintes par canal : peu de nuances, façon banding PSX

16

Instance Method Summary collapse

Constructor Details

#initialize(light_direction: LIGHT_DIRECTION, ambient: AMBIENT, color_levels: COLOR_LEVELS) ⇒ GouraudShading

Returns a new instance of GouraudShading.



15
16
17
18
19
# File 'lib/bestguigui_lab/gouraud_shading.rb', line 15

def initialize(light_direction: LIGHT_DIRECTION, ambient: AMBIENT, color_levels: COLOR_LEVELS)
    @light_direction = normalize(light_direction)
    @ambient = ambient
    @color_levels = color_levels
end

Instance Method Details

#vertex_color(normal, material_color) ⇒ Object



21
22
23
24
# File 'lib/bestguigui_lab/gouraud_shading.rb', line 21

def vertex_color(normal, material_color)
    intensity = @ambient + ((1.0 - @ambient) * [dot(normal, @light_direction), 0.0].max)
    material_color.map { |channel| quantize(channel * intensity) }
end