How to implement custom shader (specifically into ogre 3.0)?

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
knn217
Halfling
Posts: 70
Joined: Wed Jan 25, 2023 9:04 am
x 5

How to implement custom shader (specifically into ogre 3.0)?

Post by knn217 »

Hello, recently I've been looking into shaders to make my project looks better but I found that shader is quite hard to get into. I picked GLSL to start and 've been watching some videos from "the art of code" where he performs some shader techniques in shadertoy. This feels like the easiest way to learn shader to me, but when I checked the shader files my Ogre project created, I found nothing similar to what I saw. Here's an example:

Code: Select all

#if 0
	***	hlms_uv_count0	2
	***	hlms_pose	0
	***	uv_emissive	0
	***	first_valid_detail_map_nm	4
	***	fresnel_scalar	0
	***	hlms_uv_count	1
	***	uv_detail_nm1	0
	***	uv_detail_nm2	0
	***	areaLightMasks	1
	***	BRDF_Default	1
	***	set0_texture_slot_end	2
	***	uv_specular	0
	***	hlms_lights_area_approx	1
	***	hlms_forwardplus_flipY	1
	***	hlms_lights_directional	0
	***	samplerStateStart	2
	***	alpha_test	0
	***	GGX_height_correlated	1
	***	metallic_workflow	0
	***	hw_gamma_write	1
	***	uv_detail_weight	0
	***	hlms_alpha_to_coverage	0
	***	cubemaps_as_diffuse_gi	1
	***	uv_detail_nm3	0
	***	hlms_pose_normals	0
	***	hlms_pose_half	0
	***	hlms_lights_spot	1
	***	GL_ARB_shading_language_420pack	1
	***	uv_normal	0
	***	hlms_alphablend	0
	***	uv_detail3	0
	***	normal_map	0
	***	hlms_bones_per_vertex	3
	***	uv_detail1	0
	***	fresnel_workflow	0
	***	perceptual_roughness	1
	***	alpha_test_shadow_caster_only	0
	***	materials_per_buffer	240
	***	hw_gamma_read	1
	***	hlms_skeleton	1
	***	hlms_lights_point	1
	***	GL_ARB_base_instance	1
	***	s_lights_directional_non_caster	1
	***	uv_detail0	0
	***	uv_diffuse	0
	***	uv_detail_nm0	0
	***	hlms_render_depth_only	0
	***	num_pass_const_buffers	3
	***	uv_detail2	0
	***	uv_roughness	0
	***	receive_shadows	1
	***	hlms_lights_area_tex_mask	1
	***	clear_coat	0
	***	needs_view_dir	1
	***	set1_texture_slot_end	2
	***	use_planar_reflections	0
	***	hlms_normal	1
	***	normal_weight	0
	***	GL_ARB_texture_buffer_range	1
	DONE DUMPING PROPERTIES
	DONE DUMPING PIECES
#endif

There are vertex and pixel shader files (I'm assuming pixel is the same as fragment?) but there's no main function for them like I was told, so I figure the main function exists in a shader somewhere in Ogre.

I thought I was supposed to modify these shader files but looks like this is not the way so I have 2 questions:

1) How do I implement shaders into my project like mentioned here https://ogrecave.github.io/ogre-next/ap ... Components ? I did look into the postprocessing sample but this seems to be higher level (compositor) than what I'm trying to learn.
2) Any recommendations for shader learning resources? I'm not even sure I'm learning the right stuff to implement into Ogre right now.

(Sorry for this post being related to Ogre, but I thought it's more suited for this channel than the help channel)

rpgplayerrobin
Gnoll
Posts: 605
Joined: Wed Mar 18, 2009 3:03 am
x 341

Re: How to implement custom shader (specifically into ogre 3.0)?

Post by rpgplayerrobin »

I wish I could help, but I am not using OgreNext.

I only write here because you might want to move this question to the Help forum instead, as @dark_sylinc might look there more often instead of this forum.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5277
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1268
Contact:

Re: How to implement custom shader (specifically into ogre 3.0)?

Post by dark_sylinc »

Hi!

OgreNext has two ways of doing shaders:

  • Low Level Materials
  • Hlms

Hlms materials are the preferred ones for getting everything working out of the box (e.g. PBS / PBR materials) with all rendering features like shadows. They get auto generated based on templates, and a lot of stuff is going on.

For tweaking shaders for a lot of objects and obtaining high performance, customizing an Hlms implementation becomes important. We are adding tutorial examples in 4.0.

But since you seem to be starting out, "Low Level Materials" is what you want to start with. They are called like that because you get exactly what a raw shader is supposed to be, with a simple interface to bind your parameters. There's not much happening behind the scenes.

Low Level Materials (LLM) are what were regular Materials in Ogre 1, and most of its documentation still aplies to OgreNext 3.0.

In OgreNext we use LLM mostly for postprocessing stuff, but it can be used for anything (e.g. see Sample_Postprocessing). LLMs are not the best for performance if applied to a large number of objects though. And in OgreNext certain features will be unavailable, like shadow mapped shadows.

If you're starting out with shaders and want to get familiar, I suggest to start with LLMs.

Once you feel more comfortable, you can look at customizing your shaders. For that the tutorials that will be in 4.0 are a great thing to look at (the tutorial works for 3.0 though the listeners need to change its function overload parameters to remove the new tid parameter), and there's a lot of resources you can look at for customizing an Hlms implementation in the 2.1+ FAQ.

knn217
Halfling
Posts: 70
Joined: Wed Jan 25, 2023 9:04 am
x 5

Re: How to implement custom shader (specifically into ogre 3.0)?

Post by knn217 »

Hello, thanks for all the replies!

dark_sylinc wrote: Sat Dec 02, 2023 2:37 am

OgreNext has two ways of doing shaders:

  • Low Level Materials
  • Hlms

Yes, I was aware of these when I read the docs. But since there are quite a few terms in these methods that I didn't know, my impression of it was that this was something high level that people who already know about low level shaders use to save some time when they need an existing technique instead of reinventing the wheels.
This is why I thought I needed to start with shaders 1st to get all the basics down before using these methods above.

As I understand, Low Level Materials is setting shaders through scripting language and Hlms is setting shaders through C++ right?

I'll probably start with Hlms then since it's covered in the Postprocessing Sample. Thanks for all the help!

Post Reply