class
Eagle::Material
- Eagle::Material
- Reference
- Object
Overview
How a mesh's surface looks: color, texture, shininess, glow, transparency and shadows.
Materials use Blinn-Phong lighting with support for directional, point and spot lights. Share one material between many meshes when they look the same.
brick = Material.new(texture: Texture.load("res://brick.png"))
brick.uv_scale = v2(4, 4) # repeat the texture
gold = Material.new(Color.hex("#e3a537"), shininess: 96, specular: 0.8, metallic: 0.6)
lamp = Material.new(Color::YELLOW, emissive: Color::YELLOW) # glows, ignores darkness
hud = Material.unlit(Color::GREEN) # flat color, no lighting
ghost = Material.new(Color::WHITE.alpha(0.3), transparent: true)
ghost.double_sided = true
For fully custom looks, assign a #shader. The standard uniforms are still provided,
and extra values go through #[]=.
Defined in:
eagle/graphics3d/material.crConstructors
-
.new(albedo : Color = Color::WHITE, texture : Texture | Nil = nil, shininess : Number = 32, specular : Number = 0.3, unlit : Bool = false, emissive : Color = Color::BLACK, metallic : Number = 0, transparent : Bool = false)
Creates a material.
-
.unlit(color : Color = Color::WHITE, texture : Texture | Nil = nil) : Material
A material that ignores lighting.
Class Method Summary
-
.standard_shader : Shader
The built-in lit shader.
Instance Method Summary
-
#[]=(name : String, v : GPU::UniformValue)
Sets an extra uniform for a custom shader.
-
#albedo : Color
Base color, multiplied with the texture and vertex colors.
-
#albedo=(albedo : Color)
Base color, multiplied with the texture and vertex colors.
-
#alpha_cutoff : Float32
Pixels with alpha below this are discarded, for cut-out textures like foliage.
-
#alpha_cutoff=(alpha_cutoff : Float32)
Pixels with alpha below this are discarded, for cut-out textures like foliage.
-
#apply(sh : Shader) : Nil
Uploads this material's uniforms to sh, which must be in use.
-
#blend : GPU::BlendMode
Blend mode for transparent materials.
-
#blend=(blend : GPU::BlendMode)
Blend mode for transparent materials.
-
#cast_shadows=(cast_shadows : Bool)
Whether meshes with this material cast shadows.
-
#cast_shadows? : Bool
Whether meshes with this material cast shadows.
-
#double_sided=(double_sided : Bool)
Draw back faces too, for leaves, flags and thin glass.
-
#double_sided? : Bool
Draw back faces too, for leaves, flags and thin glass.
-
#effective_shader : Shader
The shader this material draws with.
-
#emissive : Color
Light the surface gives off by itself.
-
#emissive=(emissive : Color)
Light the surface gives off by itself.
-
#metallic : Float32
How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.
-
#metallic=(metallic : Float32)
How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.
-
#priority : Int32
Draw order within a pass: higher draws later.
-
#priority=(priority : Int32)
Draw order within a pass: higher draws later.
-
#receive_shadows=(receive_shadows : Bool)
Whether shadows fall on meshes with this material.
-
#receive_shadows? : Bool
Whether shadows fall on meshes with this material.
-
#shader : Shader | Nil
A custom shader, or
nilfor the standard one. -
#shader=(shader : Shader | Nil)
A custom shader, or
nilfor the standard one. -
#shininess : Float32
Tightness of highlights: higher values give smaller, sharper highlights.
-
#shininess=(shininess : Float32)
Tightness of highlights: higher values give smaller, sharper highlights.
-
#specular : Float32
Strength of highlights, from 0 to 1.
-
#specular=(specular : Float32)
Strength of highlights, from 0 to 1.
-
#texture : Texture | Nil
Color texture, or
nil. -
#texture=(texture : Texture | Nil)
Color texture, or
nil. -
#transparent=(transparent : Bool)
Blend with what's behind.
-
#transparent? : Bool
Blend with what's behind.
-
#uniforms : Hash(String, Array(Eagle::Mat4) | Array(Eagle::Vec2) | Array(Eagle::Vec3) | Array(Eagle::Vec4) | Array(Float32) | Array(Int32) | Bool | Eagle::Color | Eagle::Mat3 | Eagle::Mat4 | Eagle::Vec2 | Eagle::Vec3 | Eagle::Vec4 | Float32 | Int32)
Extra uniforms passed to a custom shader.
-
#unlit=(unlit : Bool)
Ignore lights and show the albedo and texture as they are.
-
#unlit? : Bool
Ignore lights and show the albedo and texture as they are.
-
#uv_offset : Vec2
Texture offset.
-
#uv_offset=(uv_offset : Vec2)
Texture offset.
-
#uv_scale : Vec2
Texture repeat factor.
-
#uv_scale=(uv_scale : Vec2)
Texture repeat factor.
-
#wireframe=(wireframe : Bool)
Draw triangle edges only.
-
#wireframe? : Bool
Draw triangle edges only.
Constructor Detail
Creates a material.
A material that ignores lighting.
Class Method Detail
Instance Method Detail
Pixels with alpha below this are discarded, for cut-out textures like foliage.
Pixels with alpha below this are discarded, for cut-out textures like foliage.
Light the surface gives off by itself. It is added after lighting, so it glows in the dark.
Light the surface gives off by itself. It is added after lighting, so it glows in the dark.
How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.
How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.
Tightness of highlights: higher values give smaller, sharper highlights.
Blend with what's behind. Transparent meshes draw after opaque ones, sorted back to front.
Blend with what's behind. Transparent meshes draw after opaque ones, sorted back to front.
Extra uniforms passed to a custom shader.
Texture offset. Animate it for scrolling water or conveyor belts.