[2.2] HLMS basics

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
universal_state
Gnoblar
Posts: 3
Joined: Tue Dec 15, 2020 9:14 pm
x 2

[2.2] HLMS basics

Post by universal_state »

Hi there,

I'm currently trying to port my voxel terrain https://www.youtube.com/watch?v=PfyQ_DYArwA from UE4 (originally this was even based on my own DX9 Engine) to Ogre-Next. I've already copied the "Empty Project" and I'm now able to render a plane using a manual mesh. Now I'm trying to apply a PBS material via item->setDatablock("Rocks"), though it seems like it can't find the relevant files/HLMS. The documentation does not make clear which files are needed, though I think "PbsMaterials.material" and "PbsMaterials.compositor" must be relevant, so I've copied them to the directory of the executable, but the plane still appears to have no texture. I'm even unsure where and when in the "Sample_PbsMaterials" project the HLMS files are loaded, since neither the .material nor the .compositor file can be found there in the source code.

As you see, I'm quite lost. Maybe someone can point me to some basic introduction to HLMS. I've found the documentation for HLMS https://ogrecave.github.io/ogre-next/api/2.1/hlms.html, but thats already too advanced. I've also found a bunch of other threads like this one viewtopic.php?p=519340#p519340, but this is also already three steps too far.
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 156

Re: [2.2] HLMS basics

Post by sercero »

Hello,

Here are some articles about HLMS in the wiki, I am using OGRE v1 so I don't know how helpful they are.
http://wiki.ogre3d.org/Ogre+V2+for+dummies
http://wiki.ogre3d.org/-HLMS
http://wiki.ogre3d.org/HLMS+Materials
http://wiki.ogre3d.org/Ogre+2.1+FAQ

But it is a place to start.
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.2] HLMS basics

Post by Lax »

Nice! I hope it will work!! I would be also very interested!

Are you familiar with Ogre 2.x compositor system?
For hlms:
* The usual way is to use .json files. Example:

Code: Select all

{
	"samplers" :
	{
		"Sampler_Platformer" :
		{
			"min" : "anisotropic",
			"mag" : "anisotropic",
			"mip" : "anisotropic",
			"u" : "wrap",
			"v" : "wrap",
			"w" : "wrap",
			"miplodbias" : 0,
			"max_anisotropic" : 1,
			"compare_function" : "disabled",
			"border" :[1, 1, 1, 1],
			"min_lod" : -3.40282e+38,
			"max_lod" : 3.40282e+38
		}
	},

	"macroblocks" :
	{
		"Macroblock_Platformer" :
		{
			"scissor_test" : false,
			"depth_check" : true,
			"depth_write" : true,
			"depth_function" : "less_equal",
			"depth_bias_constant" : 0,
			"depth_bias_slope_scale" : 0,
			"cull_mode" : "clockwise",
			"polygon_mode" : "solid"
		}
	},

	"blendblocks" :
	{
		"Blendblock_Platformer" :
		{
			"alpha_to_coverage" : false,
			"blendmask" : "rgba",
			"separate_blend" : false,
			"src_blend_factor" : "one",
			"dst_blend_factor" : "one_minus_src_alpha",
			"blend_operation" : "add"
		}
	},

	"pbs" : 
	{
		"TreasureChest_D" :
		{
			"macroblock" : "Macroblock_Platformer",
			"blendblock" : "Blendblock_Platformer",
			"shadow_const_bias" : 0.001,
			"workflow" : "SpecularWorkflow",
			"brdf" : "blinn_phong",
			"diffuse" :
			{
				"value" : [1, 1, 1],
				"background" : [1, 1, 1, 1],
				"texture" : "TreasureChestD.tga",
				"sampler" : "Sampler_Platformer"
			},
			"specular" :
			{
				"value" : [1, 1, 1],
				"texture" : "TreasureChestS.tga",
				"sampler" : "Sampler_Platformer"
			},
			"fresnel" :
			{
				"value" : 0.1,
				"mode" : "coeff"
			},
			"normal" :
			{
				"value" : 1,
				"texture" : "TreasureChestN.tga",
				"sampler" : "Sampler_Platformer"
			},
			"roughness" :
			{
				"value" : 1.7,
				"texture" : "TreasureChestR.tga",
				"sampler" : "Sampler_Platformer"
			}
		}
	}
There you can specify different pictures for different purposes: Diffuse, Specular, NormalMap, Roughness, Metallness, Emmissive etc. You also specify some parameters for each texture type and the workspace, brdf

It takes some time, til you get warm with all this new stuff, but its great!
If I were you, I would first build a simple Ogre project, which e.g. shows a mesh and a plane using different pbs (physically based shaders).

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

universal_state
Gnoblar
Posts: 3
Joined: Tue Dec 15, 2020 9:14 pm
x 2

Re: [2.2] HLMS basics

Post by universal_state »

Thanks sercero for the links, especially the first one I didn't know yet. But those links are still too advanced. What interests me is the C++ code that is needed to load a HLMS and which files are needed for a HLMS. Which endings should these files have so that Ogre can recognize them as a HLMS? I found the .material and .compositor files. Are these all that are needed? I also found in the "Sample_PbsMaterials" Project the following line

Code: Select all

dataFolder += "2.0/scripts/materials/PbsMaterials";
which could load the relevant HLMS files. I found this path under "build/sdk/Media". Should I copy this path to my project? Is this path relative to the working directory of the executable? This seems to not be the case with "Sample_PbsMaterials" as the executables are somewhere else.
Are you familiar with Ogre 2.x compositor system?
Unfortunately no. But it seems like a kind of mixed shader language and a D3D11_..._DESC container. I think if I get a basic HLMS working I will find my way. Though, if you write

Code: Select all

"texture" : "TreasureChestD.tga"
, where should the file be stored so that the engine can find and load TreasureChestD.tga? Or should you somehow manually load this file?
If I were you, I would first build a simple Ogre project, which e.g. shows a mesh and a plane using different pbs (physically based shaders).
Yes this is actually my plan. Right now, I can already show a plane but the second step with pbs does not work. Still, thanks Lax for your example of a HLMS.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.2] HLMS basics

Post by dark_sylinc »

Hi!

To clear your confusion:

1. You need to load the template files required by Hlms. They can be found in Samples/Media/Hlms and need to be with your application.
This is done at the beginning of your app, during initialization.
registerHlms() shows how to do this.

These files should not be edited by users unless you're really advanced and want to do something custom

2. You'll need a .compositor script to load a compositor. This is not related to the Hlms though. However you can skip this part if you create a basic one from code:

Code: Select all

// Setup a basic compositor with a blue clear colour
CompositorManager2 *compositorManager = root->getCompositorManager2();
const String workspaceName( "Demo Workspace" );
const ColourValue backgroundColour( 0.2f, 0.4f, 0.6f );
compositorManager->createBasicWorkspaceDef( workspaceName, backgroundColour, IdString() );
compositorManager->addWorkspace( sceneManager, window->getTexture(), camera, workspaceName, true );
Compositor files can be edited by users; it can be used to make some postprocessing FXs or achieve certain rendering results (like having a character being drawn always on top of everything).

3. You'll need .material files which is where your (Hlms) materials are defined. They end in either .material or .material.json
These files are meant to be edited by users (e.g. artists)

And yes, when our code does:

Code: Select all

dataFolder += "2.0/scripts/materials/PbsMaterials";
it is to tell Ogre to load all the .material files present in that folder; because we will be using them.

You can register all the folders you need in resources.cfg though (sometimes named resources2.cfg). The samples just try to avoid loading everything, and instead try to just load the folders they need.
where should the file be stored so that the engine can find and load TreasureChestD.tga? Or should you somehow manually load this file?
It should be in a folder included in resources.cfg, or in a folder which was added via Ogre::ResourceGroupManager::getSingleton().addResourceLocation()

To be clear, we call ResourceGroupManager::getSingleton().addResourceLocation() on all the locations specified in resources.cfg; so that it can be edited by users with ease.

Regarding samples, since you seem very lost, I suggest you start with the one in Samples/2.0/Tutorials/Tutorial00_Basic which is really basic and straight to the point.

Afterwards you can move on to setting up your own project using EmptyProject as a base (see overall doc on EmptyProject) which will set you up and running with lots convenience functions.

Cheers
Matias
universal_state
Gnoblar
Posts: 3
Joined: Tue Dec 15, 2020 9:14 pm
x 2

Re: [2.2] HLMS basics

Post by universal_state »

Thanks a lot dark_sylinc! This was exactly what I needed to understand how HLMS are loaded into Ogre. The textures now show on the objects and using the Pbs Compositor I even got shadows to work.
Image

Maybe one could link to this thread in the wiki, since this information could be helpful for people like me that are just starting out.
Post Reply