Table of Contents

Class SGMaterial

Namespace
LibGFX.Graphics.Materials
Assembly
LibGFX.dll

Represents a material used in rendering. Uses the Specular-Glossiness workflow.

public class SGMaterial : IMaterial, IGraphicsResource, IIdentifier, ISerialization
Inheritance
SGMaterial
Implements
Inherited Members

Constructors

SGMaterial()

Initializes a new instance of the SGMaterial class.

public SGMaterial()

SGMaterial(string, Vector4)

Initializes a new instance of the SGMaterial class with the specified name and color.

public SGMaterial(string name, Vector4 color)

Parameters

name string
color Vector4

Properties

Color

The color of the material.

public Vector4 Color { get; set; }

Property Value

Vector4

DiffuseTexture

The diffuse texture of the material.

public Texture DiffuseTexture { get; set; }

Property Value

Texture

FlipNormal

Indicates whether the normal map should be flipped.

public bool FlipNormal { get; set; }

Property Value

bool

ID

The unique identifier of the material.

public Guid ID { get; }

Property Value

Guid

IsInitialized

Gets a value indicating whether the object has been initialized.

public bool IsInitialized { get; }

Property Value

bool

IsTransparent

Gets a value indicating whether the object is partially or fully transparent.

public bool IsTransparent { get; }

Property Value

bool

Name

The name of the material.

public string Name { get; set; }

Property Value

string

NormalTexture

The normal texture of the material.

public Texture NormalTexture { get; set; }

Property Value

Texture

Opacity

The opacity of the material.

public float Opacity { get; set; }

Property Value

float

Shininess

The shininess of the material.

public float Shininess { get; set; }

Property Value

float

SpecularTexture

The specular texture of the material.

public Texture SpecularTexture { get; set; }

Property Value

Texture

UVScale

The UV scale of the material.

public Vector2 UVScale { get; set; }

Property Value

Vector2

Methods

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Populates the material's properties by deserializing values from the specified JSON object.

public void Deserialize(JObject obj, SerializationContext context, Func<JObject, bool> callback = null)

Parameters

obj JObject
context SerializationContext
callback Func<JObject, bool>

Remarks

The provided jObject must contain valid keys for all expected material properties and nested texture objects. Existing property values will be overwritten by the deserialized data.

Disable(IRenderDevice)

Disables blending on the specified render device if the current object is transparent.

public void Disable(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

The render device on which to disable blending. Cannot be null.

Dispose(IRenderDevice)

Disposes the material and its resources.

public void Dispose(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

FreeCPUResources()

Releases any CPU-side resources associated with the material and its textures.

public void FreeCPUResources()

Init(IRenderDevice)

Initializes the material.

public void Init(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice

LoadFromFile(string)

Loads a material from a JSON file.

public static SGMaterial LoadFromFile(string file)

Parameters

file string

Returns

SGMaterial

Exceptions

ArgumentException

LoadMaterial(Material, string)

Creates a new material instance from the specified Assimp material, loading associated textures from the given directory.

public void LoadMaterial(Material asmat, string directory)

Parameters

asmat Material

The Assimp material to convert. Must not be null.

directory string

The directory path used to resolve texture file locations. Must not be null or empty.

Remarks

If the Assimp material does not specify a diffuse, normal, or specular texture, a default 1x1 texture is used for the corresponding property. The returned material's properties are initialized based on the values present in the Assimp material.

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the material and its associated textures to a JSON object.

public void Serialize(JsonWriter writer, SerializationContext context, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
context SerializationContext
callback Action<JsonWriter>

Remarks

The returned JSON object includes material properties such as name, ID, color, UV scale, normal flip, opacity, and shininess, as well as nested objects for each associated texture. This method is typically used to export material data for storage or interoperability with other systems.

Use(IRenderDevice)

Prepares the material for rendering.

public void Use(IRenderDevice renderDevice)

Parameters

renderDevice IRenderDevice