Gamebryo Material System (shader tree)

Source: Internet
Author: User
Tags pixel coloring

I have been in touch with the GB engine for more than half a year. During this time, I have been doing rendering-related content, so I have a little bit of knowledge about the GB material system.

Here, I will describe the structure and principle of it with saliva. Some places may not be detailed or may even have incorrect understandings. I hope you will give me more advice.

In fact, there are manyArticleI have already introduced the GB material system, but I have read most of the content in the GB documents that are directly translated,

I am here to share with you what I mean. I hope you can correct the mistakes. Thank you!

 

First look, this is the GB material system structure built by using a simple UML tool on a temporary basis. The main elements are listed and Their Relationships are marked (the compiler only uses inheritance, dependency, and aggregation)

The following describes the functions of each class from top to bottom:

Nimaterial

This class is the core class. It and nimateriallibrary are also the only class exposed to the external logic (nimaterial: getmaterial). In fact, I have never used other interfaces of this class.

(Except setdefaworkworkingdirectory, it sets the shader file directory generated by shadertree ). This class has an important static member ms_pkmaterials, all

After the material is created, it will be placed in this array.

 

Nimaterialdescriptor

This class is also a very core class in the shader tree, which is responsible for getting user-set attributes (niextradata) at runtime and out-of-the-box data information (niextradata ).

Save the current status information to the members, and then obtain the information during the shader generation logic to determine how the shader tree should be generated and what shader nodes should be used.

These nodes are arranged, and the engine also saves the IDs of the sets in which the state information is stored into an array. When the State of the next object is consistent with that of the current state, the shader does not need to be re-generated,

The corresponding material object is obtained directly from the cache. These rendering statuses can be customized, not the DX hardware rendering status! (When I first heard about this, I thought it was DX's built-in

Rendering status -. -!) The generation and use of this object are in the nifragmentmaterial: generatedescriptor function (this State is determined by the object attribute again ).

 

Nigpuprogramdescriptor

This class is actually similar to nimaterialdescriptor. nimaterialdescriptor is the complete coloring.ProgramAll sets of rendering states, and this class only distinguishes between vertex coloring programs and

Pixel coloring program. For example: nistandardvertexprogramdescriptor and nistandardpixelprogramdescriptor

 

Nimaterialnode

It encapsulates the shader program functions. Each nimaterialnode represents a complete shader function. In this class, Multiple Input and Output Parameters of the function can be defined, and its

The subclass nimaterialfragmentnode can be used to specify the function content and description, while the function content can be specified multiple. The corresponding function content is selected based on different shader versions (this is more flexible)

 

Nimaterialnodelibrary

This class is a set of coloring program fragments. It represents one or more complete shader.CodeIs actually a "toolbox". In the logic of generating the shader, the function name is used.

Filter the required nodes and form a complete shader program.

 

Nimaterialinstance

This class is an intermediate product of niavobject packaging material. Through this class, you can use the same material instance to Package Multiple material objects for objects. This ensures that there is only one material object globally.

 

Nimateriallibrary

From the semantics of the class name, everyone should know what it mainly does. It has two very common methods:

Getmaterial: Obtain the material from the static array of the current nimaterial.

Creatematerial: if the material does not exist, create a material from the material library (maybe a material library encapsulated by DLL ).

 

Nifragment

This class is actually a helper class. It helps the subclasses of nimaterial share part of the work that can be done independently, and copies their own nimaterialnodelibrary to the help material class.

 

Niterrainfragmentlighting

It is an auxiliary class of terrain, mainly responsible for the lighting part of terrain materials, such as dynamic lighting, shadow coloring Program Generation

 

Nifragmentoperations

This class is also an auxiliary class of terrain. It is mainly responsible for type conversion, simple operations, and other work in the color program of terrain materials.

 

Nisingleshadermaterial

This class is a special material object. It loads the shader code from a file and initializes this object. It supports NSF, FX, and fxl files, instead of file names.

Shader is identified by the technology (FX: Technique) and implementation (nsf: Implementation) in the file.

 

Nistandardmaterial

In fact, this class has nothing to do. I have explained this in detail in the GB document and many articles on the Internet. Here I will simply introduce it. It is actually encapsulated using the shader tree.

A standard, complete, and super-large set of function functions can basically identify all standard rendering states in the engine (for example, fog nifogproperty, Alpha mixture, etc)
This class can be extended, meaning that the standard material can be replaced in the project. For details about the solution, please contact the author.

 

Niterrainmaterial, niwatermaterial

Similar to nistandardmaterial, the terrain is actually more complex than nistandardmaterial, because it has two more auxiliary classes.

Regardless of the complexity of the content, the principle of the content is the same. The details are only studied by yourself.

 

Nispotshadowwritematerial

It inherits the standard material, which means that it contains all the content and features of the standard material, and it makes some content on the basis of the standard material.

 

Finally, I believe that the description should be detailed enough (at least more detailed than other articles at present). I hope that the readers can understand the GB material system quickly,

Here we only describe the structure of the GB Material System and the functions of each element. The next article will continue to explain how the GB material works, that is, how the material is generated,

How is it applied and finally how it works!

 

The water in the previous article has not been optimized yet, because the current project has not yet planned to take time to optimize, but it must be optimized and there are also some optimizations. After the optimization is complete, continue to explain the water.

 

I hope you can post comments for your support shortly after the blog is launched. Thank you very much!

 

Okay, it's very late. You have to go to bed. Good night!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.