Ocular Engine
Ocular::Graphics::MaterialResourceLoader Class Reference

Creates Material objects from Ocular Material files (.omat) More...

#include <MaterialResourceLoader.hpp>

Inheritance diagram for Ocular::Graphics::MaterialResourceLoader:
Ocular::Core::AResourceLoader

Public Member Functions

virtual bool loadResource (Core::Resource *&resource, Core::File const &file, std::string const &mappingName) override
 
- Public Member Functions inherited from Ocular::Core::AResourceLoader
 AResourceLoader (std::string const &extension, ResourceType type)
 
virtual std::string getSupportedFileType () const
 
virtual bool loadSubResource (Resource *&resource, File const &file, std::string const &mappingName)
 
virtual bool exploreResource (File const &file)
 
ResourceType getResourceType () const
 

Additional Inherited Members

- Protected Member Functions inherited from Ocular::Core::AResourceLoader
bool isFileValid (Core::File const &file) const
 
- Protected Attributes inherited from Ocular::Core::AResourceLoader
std::string m_SupportedExtension
 
ResourceType m_Type
 

Detailed Description

Creates Material objects from Ocular Material files (.omat)

Overview

This loader is responsible for creating Material objects from the XML-based Ocular Material files (.omat). For a full description of the Ocular Material file format, see the Materials section of the manual.

But as the manual does not yet exist, here is an example of the XML:

<OcularMaterial>
    <ShaderProgram>
        <Vertex>
            <Path>Shaders/OcularFlat</Path>
        </Vertex>
        <Fragment>
            <Path>Shaders/OcularFlat</Path>
        </Fragment>
    </ShaderProgram>
    <Textures>
        <Texture>
            <Path>Textures/Grass</Path>
            <Name>Grass</Name>
            <Register>0</Register>
        </Texture>
        <Texture>
            <Path>Textures/GrassBump</Path>
            <Name>Grass Bump Map</Name>
            <Register>1</Register>
        </Texture>
        <Texture>
            <Path>Texture/GrassSpecular</Path>
            <Name>Grass Specular Map</Name>
            <Register>2</Register>
        </Texture>
    </Textures>
    <Uniforms>
        <Uniform>
            <Type>Vector4</Type>
            <Name>Offset</Name>
            <Register>0</Register>
            <Value>1.0 0.5 3.0 0.0</Value>
        </Uniform>
        <Uniform>
            <Type>Float</Type>
            <Name>Fade</Name>
            <Register>1</Register>
            <Value>0.5</Value>
        </Uniform>
        <Uniform>
            <Type>Matrix3x3</Type>
            <Name>Identity3x3</Name>
            <Register>2</Register>
            <Value>1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0</Value>
        </Uniform>
        <Uniform>
            <Type>Matrix3x3</Type>
            <Name>Rot3x3</Name>
            <Register>3</Register>
            <Value>
                0.38 1.0 0.0
                1.97 3.0 0.5
                0.01 0.9 1.0
            </Value>
        </Uniform>
    </Uniforms>
    <RenderState>
        <PrimitiveStyle>0</PrimitiveStyle>
    </RenderState>
</OcularMaterial>

The above XML can be broken into three major sections: ShaderProgram, Textures, and Uniforms.

ShaderProgram

The ShaderProgram is split into individual 'Shader' sections that simply specify which Shader resource file defines them. Note that these resource files may be uncompiled files (.hlsl, .glsl, etc.), pre-compiled binaries, or a mix of the two.

Internally, a request is done for the ShaderProgram that matches the specified file and then the specific shader is retrieved. For example, for the above Vertex shader we would:

ShaderProgram* program = OcularResources->getResource<ShaderProgram>("Shaders/OcularFlat");

if(program)
{
    material->setVertexShader(program->getVertexShader());
}

The following are valid shader stage tags:

<Vertex>
<Geometry>
<Fragment> or <Pixel>
<PreTessellation> or <Hull>
<PostTessellation> or <Domain>

Textures

This defines all textures to be bound to in the Material.

The three required bits of information (path, name, and register) directly map to what the Material::setTexture method requires as input parameters.

Note that 'Name' is independent of the actual Resource's name. This is used for certain graphics APIs that bind based on name instead of register. So, we could have the following:

Resource Source: Texture/Grass Resource Name: "Grass" Material Binding Name: "GrassDiffuse"

In the Material file we are specifying the 'Material Binding Name' and not the 'Resource Name.' Of course, it is perfectly acceptable that these names match, but it is not required.

Uniforms

Here the individual Uniforms for the material are specified. Each Uniform is composed of three parts: Type, Name, and Value.

Valid types are:

Float
Vector4
Matrix3x3
Matrix4x4

Their values are specified in the following way:

    Float: <Value>#</Value>

  Vector4: <Value># # # #</Value>

Matrix3x3: <Value># # #  # # #  # # #</Value>

           or

           <Value>
               # # #
               # # #
               # # #
           </Value>

Matrix4x4: <Value># # # #  # # # #  # # # #  # # # #</Value>

           or

           <Value>
               # # # #
               # # # #
               # # # #
               # # # #
           </Value>

All numbers are converted to 32-bit floats.

Render State

Select parts of the Render State may be changed via Materials. Currently, the following fields may be specified:

PrimitiveStyle: unsigned integer corresponding to the PrimitiveStyle enum definitions

Member Function Documentation

bool Ocular::Graphics::MaterialResourceLoader::loadResource ( Core::Resource *&  resource,
Core::File const &  file,
std::string const &  mappingName 
)
overridevirtual
Parameters
[out]resource
[in]file
[in]mappingName

Reimplemented from Ocular::Core::AResourceLoader.


The documentation for this class was generated from the following files: