class Eagle::Material

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.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.


def self.unlit(color : Color = Color::WHITE, texture : Texture | Nil = nil) : Material #

A material that ignores lighting.


Class Method Detail

def self.standard_shader : Shader #

The built-in lit shader.


Instance Method Detail

def []=(name : String, v : GPU::UniformValue) #

Sets an extra uniform for a custom shader.


def albedo : Color #

Base color, multiplied with the texture and vertex colors.


def albedo=(albedo : Color) #

Base color, multiplied with the texture and vertex colors.


def alpha_cutoff : Float32 #

Pixels with alpha below this are discarded, for cut-out textures like foliage.


def alpha_cutoff=(alpha_cutoff : Float32) #

Pixels with alpha below this are discarded, for cut-out textures like foliage.


def apply(sh : Shader) : Nil #

Uploads this material's uniforms to sh, which must be in use.


def blend : GPU::BlendMode #

Blend mode for transparent materials.


def blend=(blend : GPU::BlendMode) #

Blend mode for transparent materials.


def cast_shadows=(cast_shadows : Bool) #

Whether meshes with this material cast shadows.


def cast_shadows? : Bool #

Whether meshes with this material cast shadows.


def double_sided=(double_sided : Bool) #

Draw back faces too, for leaves, flags and thin glass.


def double_sided? : Bool #

Draw back faces too, for leaves, flags and thin glass.


def effective_shader : Shader #

The shader this material draws with.


def emissive : Color #

Light the surface gives off by itself. It is added after lighting, so it glows in the dark.


def emissive=(emissive : Color) #

Light the surface gives off by itself. It is added after lighting, so it glows in the dark.


def metallic : Float32 #

How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.


def metallic=(metallic : Float32) #

How metal-like the surface is, from 0 to 1: diffuse color fades out and highlights take on the albedo color.


def priority : Int32 #

Draw order within a pass: higher draws later.


def priority=(priority : Int32) #

Draw order within a pass: higher draws later.


def receive_shadows=(receive_shadows : Bool) #

Whether shadows fall on meshes with this material.


def receive_shadows? : Bool #

Whether shadows fall on meshes with this material.


def shader : Shader | Nil #

A custom shader, or nil for the standard one.


def shader=(shader : Shader | Nil) #

A custom shader, or nil for the standard one.


def shininess : Float32 #

Tightness of highlights: higher values give smaller, sharper highlights.


def shininess=(shininess : Float32) #

Tightness of highlights: higher values give smaller, sharper highlights.


def specular : Float32 #

Strength of highlights, from 0 to 1.


def specular=(specular : Float32) #

Strength of highlights, from 0 to 1.


def texture : Texture | Nil #

Color texture, or nil.


def texture=(texture : Texture | Nil) #

Color texture, or nil.


def transparent=(transparent : Bool) #

Blend with what's behind. Transparent meshes draw after opaque ones, sorted back to front.


def transparent? : Bool #

Blend with what's behind. Transparent meshes draw after opaque ones, sorted back to front.


def 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.


def unlit=(unlit : Bool) #

Ignore lights and show the albedo and texture as they are.


def unlit? : Bool #

Ignore lights and show the albedo and texture as they are.


def uv_offset : Vec2 #

Texture offset. Animate it for scrolling water or conveyor belts.


def uv_offset=(uv_offset : Vec2) #

Texture offset. Animate it for scrolling water or conveyor belts.


def uv_scale : Vec2 #

Texture repeat factor.


def uv_scale=(uv_scale : Vec2) #

Texture repeat factor.


def wireframe=(wireframe : Bool) #

Draw triangle edges only.


def wireframe? : Bool #

Draw triangle edges only.