Class: Mittsu::ShaderMaterial

Inherits:
Material
  • Object
show all
Defined in:
lib/mittsu/materials/shader_material.rb,
lib/mittsu/renderers/opengl/materials/shader_material.rb

Instance Attribute Summary collapse

Attributes inherited from Material

#alpha_map, #alpha_test, #blend_dst, #blend_dst_alpha, #blend_equation, #blend_equation_alpha, #blend_src, #blend_src_alpha, #blending, #bump_map, #color, #color_write, #combine, #default_attribute_values, #depth_test, #depth_write, #env_map, #id, #light_map, #map, #metal, #name, #normal_map, #opacity, #overdraw, #polygon_offset, #polygon_offset_factor, #polygon_offset_units, #program, #reflectivity, #refraction_ratio, #shader, #shadow_pass, #side, #size_attenuation, #specular_map, #transparent, #type, #uniforms, #uniforms_list, #uuid, #visible, #wrap_around

Instance Method Summary collapse

Methods inherited from Material

#clear_custom_attributes, #custom_attributes_dirty?, #dispose, #init, #needs_face_normals?, #needs_lights?, #needs_update=, #needs_update?, #refresh_uniforms, #set, #set_values, #to_json, #update

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(parameters = {}) ⇒ ShaderMaterial

Returns a new instance of ShaderMaterial.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mittsu/materials/shader_material.rb', line 33

def initialize(parameters = {})
  super()

  @type = 'ShaderMaterial'
  @defines = {}
  @uniforms = {}
  @attributes = nil

  @vertex_shader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}'
  @fragment_shader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}'

  @shading = SmoothShading

  @line_width = 1

  @wireframe = false
  @wireframe_linewidth = 1

  @fog = false # set to use scene fog

  @lights = false # set to use scene lights

  @vertex_colors = NoColors # set to use "color" attribute stream

  @skinning = false # set to use skinning attribute streams

  @morph_targets = false # set to use morph targets
  @morph_normals = false # set to use morph normals

 # When rendered geometry doesn't include these attributes but the material does,
 # use these default values in WebGL. This avoids errors when buffer data is missing.
  @default_attributes_values = {
    'color' => [1.0, 1.0, 1.0],
    'uv' => [0, 0],
    'uv2' => [0, 0]
  }

  # TODO: necessary?
	# this.index0AttributeName = undefined;

  self.set_values(parameters)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def attributes
  @attributes
end

#definesObject

Returns the value of attribute defines.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def defines
  @defines
end

#fogObject

Returns the value of attribute fog.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def fog
  @fog
end

#fragment_shaderObject

Returns the value of attribute fragment_shader.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def fragment_shader
  @fragment_shader
end

#lightsObject

Returns the value of attribute lights.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def lights
  @lights
end

#morph_normalsObject

Returns the value of attribute morph_normals.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def morph_normals
  @morph_normals
end

#morph_targetsObject

Returns the value of attribute morph_targets.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def morph_targets
  @morph_targets
end

#shadingObject

Returns the value of attribute shading.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def shading
  @shading
end

#skinningObject

Returns the value of attribute skinning.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def skinning
  @skinning
end

#vertex_colorsObject

Returns the value of attribute vertex_colors.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def vertex_colors
  @vertex_colors
end

#vertex_shaderObject

Returns the value of attribute vertex_shader.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def vertex_shader
  @vertex_shader
end

#wireframeObject

Returns the value of attribute wireframe.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def wireframe
  @wireframe
end

#wireframe_linewidthObject

Returns the value of attribute wireframe_linewidth.



31
32
33
# File 'lib/mittsu/materials/shader_material.rb', line 31

def wireframe_linewidth
  @wireframe_linewidth
end

Instance Method Details

#cloneObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mittsu/materials/shader_material.rb', line 76

def clone
  material = ShaderMaterial.new

  super.clone(material)

	material.fragment_shader = @fragment_shader
	material.vertex_shader = @vertex_shader

	material.uniforms = UniformsUtils.clone(@uniforms)

	material.attributes = @attributes
	material.defines = @defines

	material.shading = @shading

	material.wireframe = @wireframe
	material.wireframe_linewidth = @wireframe_linewidth

	material.fog = @fog

	material.lights = @lights

	material.vertex_colors = @vertex_colors

	material.skinning = @skinning

	material.morph_targets = @morph_targets
	material.morph_normals = @morph_normals

 material
end

#needs_camera_position_uniform?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/mittsu/renderers/opengl/materials/shader_material.rb', line 3

def needs_camera_position_uniform?
  true
end

#needs_view_matrix_uniform?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/mittsu/renderers/opengl/materials/shader_material.rb', line 7

def needs_view_matrix_uniform?
  true
end