Class SGMaterial
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
Properties
Color
The color of the material.
public Vector4 Color { get; set; }
Property Value
DiffuseTexture
The diffuse texture of the material.
public Texture DiffuseTexture { get; set; }
Property Value
FlipNormal
Indicates whether the normal map should be flipped.
public bool FlipNormal { get; set; }
Property Value
ID
The unique identifier of the material.
public Guid ID { get; }
Property Value
IsInitialized
Gets a value indicating whether the object has been initialized.
public bool IsInitialized { get; }
Property Value
IsTransparent
Gets a value indicating whether the object is partially or fully transparent.
public bool IsTransparent { get; }
Property Value
Name
The name of the material.
public string Name { get; set; }
Property Value
NormalTexture
The normal texture of the material.
public Texture NormalTexture { get; set; }
Property Value
Opacity
The opacity of the material.
public float Opacity { get; set; }
Property Value
Shininess
The shininess of the material.
public float Shininess { get; set; }
Property Value
SpecularTexture
The specular texture of the material.
public Texture SpecularTexture { get; set; }
Property Value
UVScale
The UV scale of the material.
public Vector2 UVScale { get; set; }
Property Value
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
objJObjectcontextSerializationContextcallbackFunc<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
renderDeviceIRenderDeviceThe render device on which to disable blending. Cannot be null.
Dispose(IRenderDevice)
Disposes the material and its resources.
public void Dispose(IRenderDevice renderDevice)
Parameters
renderDeviceIRenderDevice
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
renderDeviceIRenderDevice
LoadFromFile(string)
Loads a material from a JSON file.
public static SGMaterial LoadFromFile(string file)
Parameters
filestring
Returns
Exceptions
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
asmatMaterialThe Assimp material to convert. Must not be null.
directorystringThe 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
writerJsonWritercontextSerializationContextcallbackAction<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
renderDeviceIRenderDevice