RTSS Improvements

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


al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

RTSS Improvements

Post by al2950 »

Firstly I would like to comment on the following post by dark_sylinc:
dark_sylinc wrote:I agree on the tools. This is why I added a few slides about RTSS to be more node-like. If we make a customizable node system, creating a graphical interactive tool for setting up material would be very easy.....
I proposed an idea similar to this back in 2011, (see here), however i did not get enough feedback to warrant me spending a lot of time on it. However the comments I did get back made some valid points. Mainly the RTSS is slightly lower level then a node based system that an artist may use, however there some simple extensions that could be added to RTSS to allow a node based system to be built on top of it if someone wishes.

Myself and Mattan Furst have posted before about a number of issues, please see here & here. I dont want to go through those posts here as they are quite lengthy, but I thought I might outline some general areas in RTSS that I believe need updating, and hopefully get the community and Ogre team thinking/posting about it:
  • Flexibility of SRS needs to be improved. This really comes down to how SRS parameters are initialised, used & shared, however its an area that needs a lot of discussion. Previous posts I linked to earlier cover this but I suggest we have a separate topic to discuss this particular issue.
  • Error reporting needs to be improved and handled better.
  • RenderState should be an interface - At the moment there is a single render state, and it forces FFP. However there are times when a dev may not want FFP to be automatically applied to a material. (eg g-buffer)
  • Materials should be able to "opt-out" of certain SRS's. This is useful when you apply a SRS template to an entire scheme, however you may want some materials to ignore it
  • Documentation - need I say more!
  • Performance - I dont believe RTSS has any real performance issues. Its more or a lack of understanding (ie documentation) that causes these issues.
My mind seems to have drawn a blank at the moment, but there are some other minor points that I wanted to make. However the first point has a lot to it and if someone wants to start a discussion about it, then please create a new topic titled "RTSS SRS Parameters" or something similar!
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RTSS Improvements

Post by al2950 »

I understand that the RTSS is not very well known yet, however I was expecting at least a few comments!

I would very much appreciate some direction from the Ogre team, as I am more than likely going to start work on the RTSS anyway. However I would be completely gutted if I did a load of work and then have the Ogre team to turn round and say "no we dont want that"!
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin
x 108

Re: RTSS Improvements

Post by PhilipLB »

I agree deeply with the error reporting, this was the most painful part when I developed a SRS.
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: RTSS Improvements

Post by masterfalcon »

Those sound like some great ideas. Making a node based interface for the RTSS would allow much more flexible and robust tools for designers.

As for performance. I noticed an issue a couple years ago. Functions being used for basic operations, like add, subtract, assign, etc. can be exceptionally slow depending on the drivers. That's what led me to integrate the glsl-optimizer.

But on the whole, I like your ideas.
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99

Re: RTSS Improvements

Post by Wolfmanfx »

Sad thing is that RTSS is not great on Android it led to crashes / device freezes or just black screens - to many poor driver impl.
I also agree that basic ops like +,-,*,/ could be done without functions - it could be explicitly generated inside the program writer because there i know how to multiply a matrix with a vector.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RTSS Improvements

Post by al2950 »

Thank you all for your replies, thought I would wait a bit longer to see if anyone else replied!
PhilipLB wrote: I agree deeply with the error reporting, this was the most painful part when I developed a SRS.
Could you please mention some of the areas that caused you trouble?
Wolfmanfx wrote: Sad thing is that RTSS is not great on Android it led to crashes / device freezes or just black screens - to many poor driver impl.
I did not realise this :? . This is something that should really be looked at. I have no idea about development on mobile platforms, but ill add it to the list. If you have any more info that would be helpful it would be good!
masterfalcon & Wolfmanfx wrote: I also agree that basic ops like +,-,*,/ could be done without functions - it could be explicitly generated inside the program writer because there i know how to multiply a matrix with a vector.
This is a good point. Just to check I understand you correctly; you mean leave the function definitions in code, but within the 'program writer' treat them as 'special' functions so they are written inline of the current function instead of calling another function? I might add an option to allow certain or all functions to be written inline, instead of separate function calls. It would make the shaders difficult to read but might fix a number of mobile platform issues.
I have to admit I did not think it would cause any performance issues as I would expect the compiler to deal with it better, oh well!!

I am constructing a task list, so I might put a wiki article up for it at some point.
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin
x 108

Re: RTSS Improvements

Post by PhilipLB »

If, for example, there is a syntax error in the actual shader file, you get no good error message, just an exception not even saying it's a syntax error.
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: RTSS Improvements

Post by drwbns »

I'd just like to see a better guide on using it :)
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RTSS Improvements

Post by al2950 »

drwbns wrote:I'd just like to see a better guide on using it :)
I am working on it :D
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99

Re: RTSS Improvements

Post by Wolfmanfx »

To make it usefull we have to get rid of all functions inside the shaders except the main function. Also i am not sure if the shader compiler can deal with the complicate un-optimized shader.
enigma6
Gnoblar
Posts: 1
Joined: Thu Jun 20, 2013 6:19 pm

Re: RTSS Improvements

Post by enigma6 »

not so good on android
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: RTSS Improvements

Post by dark_sylinc »

Ok I'm going to drop a bomb here. It may sound like a rant, [s]because it is[/s] but I'm just trying to go straight to the point and take it constructive:

A lot of people isn't using the RTSS. And the poll shows an alarming number. Why? because the documentation SUCKS. Where are the material syntax extensions by the way? They're nowhere to be mentioned. Aaaand...
Image
Seriously?

The system is too complex, large, intimidating. What's worse is that in the little time I've been digging into RTSS, extending with my own shaders looks like a nightmare.

There doesn't seem to be a clear example of how to extend it with your own. Not to mention that we should be able to extend it without writing much C++ code, which doesn't seem to be the case.

I opened up ShaderSystem.cpp from the Sample_ShaderSystem. Wait... what? It's 1800 lines! And there are three more files? And they're also large?!? What about the other projects... nevermind.
It seems like a lot of C++ effort needs to be done just to get RTSS up and running.

So much for a "plug'n play" package.

But then I see the changes that were done to add RTSS to Ogre Meshy, it hints it wasn't that hard after all. In fact it's just a couple of lines.
Of course, that only works if you don't want custom shaders (which can actually be a lot of users). GLES2 users are probably the biggest users.
I am guessing now that extending RTSS with my own shaders could still be a nightmare; but getting RTSS up and running on my own projects wasn't as intimidating as it initially looked. That's a documentation and sample fail.
Which brings me to the big problem: Having a robust material system. RTSS is one attempt to solve it.

A robust material system
Scrawl has a good summary of reasons why the current material system is limited in usefulness. But frankly, I think Shiny is going too far to the other extreme.

To summarize Scrawl's complains, if my model is not animated; I need a vertex shader. If my model is animated, I need a different VS. If my model has more bone weights per vertex, I need a different VS. If I'm using Instancing, I need another VS. And if I want shadows, I also need ANOTHER VS. And better be sure the math in the caster's VS matches the receiver's VS. And if I want normal mapping, I need a permutation of all the previous variations with normal mapping on and off. It's a O(2^N) problem. Not cool.
Of course, I can use #ifdef macros (and that actually works, very well shall I add); but I have to write a vertex_program entry for each one of them. And a different material to bind these shaders. And better be sure I bound the right shadow caster program to that material.

This could be solved with a shader generator similar to RTSS, hey but then we got to deal with GLSL too (assuming you started first w/ HLSL or Cg)
We're not the only ones with problems on this area. Unity too.

While writing the Ogre 2.0 manual (and having some ideas for future Ogre 2.x) I came to the conclusion the problem with the current material system is that it is too flexible.
Think about it: the material system is just a low level interface where a VS and a PS are bounds. The only addition is that a shadow caster can also be bound.

But I don't want this kind of flexibility to go away. It's really useful for some tricky stuff. But most of the time I need a higher level system that deals with the usual permutation problem.
Wolfmanfx wrote:To make it usefull we have to get rid of all functions inside the shaders except the main function. Also i am not sure if the shader compiler can deal with the complicate un-optimized shader.
This is another issue. If we read Low Level Thinking in High Level Shading Languages (in ppt) we realize shader compiler suck at optimizing our code.

If we take a look at CryENGINE 3; their materials are actually quite rigid. They have a series of presets: Cloth, Eye, Glass, Hair, HumanSkin, Ilum, etc which can have diffuse/normal/specular/environment maps, few parameters that can be tweaked and that's it.
Artists only have to spend time tweaking the few parameters being given and the quality of their textures. And they've got the "Ilum" shader for most generic stuff.

Imagine if a material could just be:

Code: Select all

material MySweater
{
    shader cloth
    roughness 7
    fresnel 0.25
    receive_shadows off
    diffuse_map mytexture.dds
    normal_map mytextureNM.dds
    specular_map mytextureSPEC.dds
}
Or we can look at UDK's flexibility which relies on live node editing to get the job done. There's mixed feelings on this community regarding nodes, but I can tell you every artist I've known loves them (though they're prone to creating very slow materials because they don't have a programmer's mentality).

RTSS focusing on emulating FFP
Well, this is something I would love to review. RTSS should be focusing on providing materials that look good. We're trying to emulate the look games had in 2001 for God sake! Providing PBS (physically based shading) is a very good start.
The good thing about PBS is that we start caring more about just choosing one or two BDRF for the whole game, and then just tweak a few parameters for every surface. No need to write so many shaders.

Main issues when dealing with shaders
When I'm writing shaders, my first problem begins like this:

Code: Select all

#ifdef NORMA_MAP
  float4 outTangent : TEXCOORD1;
  float4 otherData : TEXCOORD2;
#else
   float4 otherData : TEXCOORD1;
#endif
As the number of interpolators keep growing, I keep having to change their numbers. Same happens when I use VTF in a vertex shader (diffuse texture is now on texture unit 1, not 0; normal maps in TU 2, etc)

Unless we resort to generating the code entirely through C++ (like Sinbad's Terrain, something I like to avoid very much) this can easily solved with a shader preprocessor in Ogre: Include a set of keywords that will be recognized by Ogre.

For example:

Code: Select all

#ifdef NORMAL_MAP
  float4 outTangent : @TEXCOORDN;
#endif
  float4 otherData : @TEXCOORDN;
Each @TEXCOORDN will be replaced by the next valid unused texcoord. Same can be done with texture samplers (to solve the VTF issue). This approach is very much like Shiny, but Shiny took it to an extreme where the whole shader looks like a mess of keywords so that it cross compiles into HLSL/GLSL to the point it looks like an entire different language. No thanks. That's a bit too much.

My second issue is already been mentioned, and it is not being able to easily match the VS versions of both receiver and caster (let Ogre strip all unnecessary defined macros, and add "-DDEPTH_CASTER" to the compile arguments)
And when a model is loaded, check whether it's using instancing and whether it's animated; and pick the right VS. That's not hard in code if you drive Ogre on how to do it with a couple text files.

A material system that generates material
Like I said, I don't want to remove the flexibility of the current material system. But we do can have a higher level material system that can generate the lower level material. Whether it is RTSS or another a new one, I don't know.
Owen
Google Summer of Code Student
Google Summer of Code Student
Posts: 91
Joined: Mon May 01, 2006 11:36 am
x 21

Re: RTSS Improvements

Post by Owen »

I've thought similar, with regards to RTSS being too complex yet too inflexible.

I think choosing to work with existing shading languages to start with was a bad idea. You can't do intelligent compilation without understanding the code you're working with.

What I think we need is a shader generator which
  • Parses the shader code it is working with and understands it, so it can build a single output function that crappy shader compilers (I'm looking at you, most GLES implementations) can deal with
  • Builds techniques based upon material properties
As an example, here is a hypothetical normal mapping shader fragment:

Code: Select all

type fragment;
property "normal_map" texture; 
in property("normal_map", texture) sampler2D normalMap;
in property("normal_map", uv) vec2 normalMapUV;
inout vec3 rt_normal;

// Expand a 0.0-1.0 vector into a -1.0-1.0 vector
vec3 scale(vec3 in) {
    return 2 * (in - 0.5);
}

main {
    rt_normal *= scale(texture(normalMap, normalMapUV));
}
And a hypothetical per-pixel diffuse lighting shader fragment:

Code: Select all

type fragment;
property "diffuse" colour;
in vec3 rt_normal;
in property("diffuse") vec3 diffuse;
in perlight vec3 lightVector;
in perlight vec3 rt_lightColour;
in vec3 fragTexture;
inout rt_fragColour;

main {
    rt_fragColour += fragTexture * diffuse * rt_lightColour * dot(rt_normal, lightVector);
}
(n.b. fragTexture being the sampled texel from a fragment I haven't bothered to write here :). Also, variables starting with "rt_" are 'fixed function' variables; think GLSL's gl_ variables or HLSL's sv_ vars (I think; not familiar with HLSL))

A material might then be defined as

Code: Select all

material Rocks {
    texture rocks.dds
    normal_map rocks_nm.dds
    diffuse 0.5 0.3 0.0
}
and the shader system would, upon noting the "normal_map" invocation, realize it needs to use the normal mapping shader. Likewise, the "diffuse" property would trigger the use of the diffuse lighting shader. There could also be adaptor shaders, that can derive one property from another.

Also, note I don't mention "varying" or "uniform" or similar at all there: the assumption is that the shader system can work it out (it knows what variables are referenced in the various stages anyway - any names in common become implicitly varying, effectively; inputs to the first used stage are implicitly uniform, etc, etc)

Obviously, there are more considerations, e.g. I haven't really considered how per-light matters would be handled, or how even the ligthing method would be selected (i.e. some games would want to iterate through a light information texture or similar, as opposed to a bunch of constants in a finite number of registers); but I think that, by breaking things down in this way, we would end up with something which looks like RTSS should, rather than what it currently does.

I don't think that writing a shading language parser/re-emitter would be too difficult. I think people have been scared of it because programming language work is a somewhat specialist field... but implementing a parser (which goes code -> syntax tree) isn't difficult, and writing a code-re-emitter isn't too difficult either.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: RTSS Improvements

Post by masterfalcon »

Sounds like what you have in mind is in some respects a rebranding and refocussing of the RTSS. Right now we use it to emulate FFP for GL ES 2, GL3+ and DX11 and present it as such to users. To help make it easy for someone to get started quickly without having to write a shader for every material.

However, your idea of making the user define a BDRF first, then everything would get generated does sound like a good replacement for that mentality and one that we should have our users thinking about anyway in this day and age.

Owen, are you proposing that we have a meta-shader language that we write out then translate into the correct native language? Somewhat like LLVM's IR? I know that idea has been kicked around before but not really thought about seriously.
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Re: RTSS Improvements

Post by Xavyiy »

Woah, @dark_sylinc post is huge! Here is what I think:

I think there are two main questions behind this discussion:
  • 1. Who are the material system target users? coders or artists?
  • 2. What would be really useful for Ogre users?
1. Who are the material system target users? coders or artists?
It's clear that the target are Ogre users, so corders!. We are not UDK or Cryengine which are game engines targetted on a team of artists and a few coders doing the logical stuff, but always quite far from graphical stuff. We are not Unity either, but hey, I think their approach would be better for us. Still not perfect.

So, since the Ogre3D target users are coders (at least the people who would really make something with Ogre, a game, scientific app, or whatever), I really think we should keep the current low-level system, with no restrictions/modifications. Any other adition like the RTSS or any other shader generator, unified language to glsl/hlsl translator (true or macro based, like Shiny), etc, should just be optional components. Why? Because Ogre is a rendering engine aimed at experts people, and we usually like to do things "our way".

Conclusion: whatever we do with the RTSS or any other shader system, ALWAYS keep the current "low-level" interface (i.e. the current material C++ API / script file format).

1. 2. What would be really useful for Ogre users?
RTSS: too cryptic, no script-based shader definitions, poor documentation, ... Conclusion: almost never used, just for emulating FFP (which btw must be completely removed from the Ogre core, we're not in 2001 anymore).

Shiny: at the end it gets quite cryptic, but it's great to have a "macro-based unified" language. Personally, if I wouldn't be that masochist (I write all shaders x2: glsl / hlsl, mainly to keep my knowledge up to date) I would be using something like it.

Node-based system: IMHO forget about that, it needs a robust UI system (who is going to write/maintain it? And really doing it, not mantain it for the first 6 months and then stop working on it, like what happen with almost all non-core parts of Ogre). Also, the performance of the generated code wouldn't be quite good.

State of the art MATERIAL LIBRARY? YES! YES! YES!
But TRUE state of the art, not the fucking (sorry, but it's true) materials included with the ogre samples. PBR materials, etc. All with proper shadow support (only one technique, the best one (PSSM), not a mix of #ifdef that at the end nobody understand). Also completely remove all CG based materials from the samples (HLSL/GLSL implementations please!). And always use the same naming convention for all built-in ".material" files (uniform var names, file names, tabs/spacing inside scripts, etc!), the current library included with the Ogre samples scares me!

Then, the user would just have to inherit from one of these built-in materials, redefine some params/textures and voilá, the magic happens. No need to extend/understand the RTSS, no need to write shaders, ... all quickly done!

And if the user wants more advanced materials, like water or volume fire shaders, he is always able to use the "low-level" .material scripts for it, like we all are doing right now.

Xavier
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: RTSS Improvements

Post by syedhs »

Yes I have similar thought with Xavyiy's -

1) Current material script implementation is okay - but
:arrow: can be made optional ie user can have also other ways like lua script.. flexibility.
:arrow: can be made easier like dark_sylinc's comment on texcoord. A lot of time, if we think it through, 20% effort can easily result in 80% better result.. ie a lot easier shader script etc.

2) Proposing entirely different approach (like node-based) need someone or group of people that vouch that they will see it through the end - which may take more than a year so I have doubt on it.. It is acceptable only if things can be worked on stage by stage, and each stage is usable - at least if it takes more time that it should be, people can still use and improve it.

3) Shader library.. YES big YES. A lot of posts on this forum, comment on not working shadow, normal maps, asking shader - so why not just give them something that simply work out-of-box? Something which is certified by Ogre teams.. :mrgreen: Currently shader libraries are in wild and even in the sample, it is not really great (and there are so many variants). And to those experts (I am not), they can always author their own shader.

4) I like RTSS idea.. probably what can be done is
:arrow: To document everything about RTSS..
:arrow: People say to extend it is difficult, probably it can be overcome by documentation. Probably another layer is needed so that if people choose to extend it, it needs less than 200 lines or so (including shader).
:arrow: Showstopper so far is probably cryptic bugs like what I experienced 3 years back. RTSS cause my FPS to dip below 5 FPS for a few second, and then resume to normal FPS, I have no idea why. Removing RTSS cure my problem. Another show stopper is like what people say about Android port - is it something that cannot be solved?
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1894
Joined: Sun Mar 08, 2009 5:25 am
x 116

Re: RTSS Improvements

Post by mkultra333 »

I'm one of the people who never use the RTSS, don't understand it, and don't really know what it does. I use a tonne of hand written shaders though, probably 50+ basic shader template types, and then on top of that different versions depending on the textures used, and then on top of that cloned variations on those generated at run time. My setup is pretty bizarre and convoluted, but needs to be like that for various effects and special requirements.

I definitely DON'T want to lose the low level access of writing real HLSL shaders. I never use Ogre compositors or inbuilt shadows, because I tend to customize everything (not the least because I target being compatible with nvidia 3DVision stereoscopic rendering, which often requires some special shader tweaks.)
All with proper shadow support (only one technique, the best one (PSSM)
I think PSSM is probably for all the terrain people. I'm a dungeon person, so I prefer Variance Shadow Mapped spotlights. And I have them in a special deferred shading setup (again, with tweaks that make it work with 3DVision). So PSSM isn't for everyone.

Basically I'm just putting in a vote to make sure low level access to shaders is always there for those who need it.
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Re: RTSS Improvements

Post by Xavyiy »

@mkultra
Well, I just proposed PSSM because of I'm a terrain/open-door guy, but ideally we should have different zipped packs, each one for each supported shadow technique. And also another one without shadows support at all (which will also serve as a template, that way one is able to easily create its own pack for a custom shadow technique).

PLEASE: don't handle all shadow techniques in the same shader programs with tons of #ifdef. Don't make the same mistakes of the past. Let's do it in different zipped packages.
Basically I'm just putting in a vote to make sure low level access to shaders is always there for those who need it.
+1000 (In the case it wasn't clear enough from my previous post)
Owen
Google Summer of Code Student
Google Summer of Code Student
Posts: 91
Joined: Mon May 01, 2006 11:36 am
x 21

Re: RTSS Improvements

Post by Owen »

masterfalcon wrote:Owen, are you proposing that we have a meta-shader language that we write out then translate into the correct native language? Somewhat like LLVM's IR? I know that idea has been kicked around before but not really thought about seriously.
Precisely, except LLVM IR is much lower level.

When you have the full syntax tree for a shader fragment.. gluing them together precisely and reliably becomes a lot easier. Errors all get caught in the meta-language compiler, rather than after 30 shaders have been gooped together into the output shader. (Hopefully. At least, this should be the case after the shader compiler has been debugged)
Xavyiy wrote:It's clear that the target are Ogre users, so corders!. We are not UDK or Cryengine which are game engines targetted on a team of artists and a few coders doing the logical stuff, but always quite far from graphical stuff. We are not Unity either, but hey, I think their approach would be better for us. Still not perfect.

So, since the Ogre3D target users are coders (at least the people who would really make something with Ogre, a game, scientific app, or whatever), I really think we should keep the current low-level system, with no restrictions/modifications. Any other adition like the RTSS or any other shader generator, unified language to glsl/hlsl translator (true or macro based, like Shiny), etc, should just be optional components. Why? Because Ogre is a rendering engine aimed at experts people, and we usually like to do things "our way".

Conclusion: whatever we do with the RTSS or any other shader system, ALWAYS keep the current "low-level" interface (i.e. the current material C++ API / script file format).
One aspect I think RTSS gets right is that it just "glues onto" the material system, building a technique when the needed one isn't present.

Any replacement/improvement should keep doing that.
Xavyiy wrote:... Conclusion: almost never used, just for emulating FFP (which btw must be completely removed from the Ogre core, we're not in 2001 anymore).
I think that the FFP properties can stay; they're still generally useful (and do little harm by existing; the majority of games still use the same "ambient" "diffuse" "specular" properties);
Xavyiy wrote:State of the art MATERIAL LIBRARY? YES! YES! YES!
But TRUE state of the art, not the fucking (sorry, but it's true) materials included with the ogre samples. PBR materials, etc. All with proper shadow support (only one technique, the best one (PSSM), not a mix of #ifdef that at the end nobody understand). Also completely remove all CG based materials from the samples (HLSL/GLSL implementations please!). And always use the same naming convention for all built-in ".material" files (uniform var names, file names, tabs/spacing inside scripts, etc!), the current library included with the Ogre samples scares me!
This is where the RTSS should come in. The fixed materials we have... are useless as soon as you need something even slightly different.

And everybody needs something slightly different...
syedhs wrote:Yes I have similar thought with Xavyiy's -

1) Current material script implementation is okay - but
:arrow: can be made optional ie user can have also other ways like lua script.. flexibility.
Already done. See my GSoC!
syedhs wrote:2) Proposing entirely different approach (like node-based) need someone or group of people that vouch that they will see it through the end - which may take more than a year so I have doubt on it.. It is acceptable only if things can be worked on stage by stage, and each stage is usable - at least if it takes more time that it should be, people can still use and improve it.
My hunch is that artists love node-based systems, but... they'd be nearly as happy with a "property based" system, we don't then need to write a node editor... and we don't need to deal with the fact that node based shaders as an artist would create them are in a "data flow" format which... is tricky to optimize.
syedhs wrote:4) I like RTSS idea.. probably what can be done is
:arrow: To document everything about RTSS..
:arrow: People say to extend it is difficult, probably it can be overcome by documentation. Probably another layer is needed so that if people choose to extend it, it needs less than 200 lines or so (including shader).
:arrow: Showstopper so far is probably cryptic bugs like what I experienced 3 years back. RTSS cause my FPS to dip below 5 FPS for a few second, and then resume to normal FPS, I have no idea why. Removing RTSS cure my problem. Another show stopper is like what people say about Android port - is it something that cannot be solved?
I think solving the Android ports' problems with the RTSS as-is will be difficult. It fundamentally works by gooping together fragments of shaders... but doesn't have any understanding of the kernel of the shaders themselves.

I think RTSS has some good ideas... but perhaps should be considered a "prototype".

My proposal with regards to the "shader fragments" and properties was that it function along similar lines to RTSS: You define properties which get passed to shaders in your material scripts, and the "new RTSS" then builds techniques where they're missing.
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 217

Re: RTSS Improvements

Post by scrawl »

Some good ideas in this topic. And thanks for bringing up Shiny.
FYI, the meta-language is optional. It's mainly just a proof of concept that I found pretty neat for personal uses. But I agree it shouldn't be included in the engine.
There's also another couple of things that just aren't done nicely, but I didn't see any other way of doing it. You have to remember that it's an extension and basically hacked on top of Ogre's existing facilities.
BUT, the good news: I have thought about this for a couple of days and I think I can fix it - If we add the main features directly into the Ogre core, properly integrated with the rest of the material system, things are going to look much nicer.
I think this is a good project for a GSOC, since we'll also need to convert lots of the sample materials (especially the .cpp shaders: Terrain, Deferred Shading), write decent documentation, etc.
If you like the idea, I can write up a GSOC proposal with a feature overview and roadmap, and I'd be honored to do it next year! :)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: RTSS Improvements

Post by dark_sylinc »

I really, really agree with xavyiy.

I like the idea of zip packages and removing Cg. Unfortunately Cg is dying and has a lot of shortcomings it didn't have when we were all developing on SM 3.0 hardware.

Just one thing:
Xavyiy wrote:Then, the user would just have to inherit from one of these built-in materials, redefine some params/textures and voilá, the magic happens. No need to extend/understand the RTSS, no need to write shaders, ... all quickly done!
This is what I'm complaining. It does not happen magically. Perhaps the most clear example is instancing HW VTF: The vertex shader has to exactly match the number of weights per vertex for the mesh.

While I was at Sandswept working on The Dead Linger, more than once we had the issue that the zombie's torso had 3 weights per vertex; the artist made a few changes; and now it had 2. But when testing in game, the torso wouldn't show up. Because the material was inheriting from the wrong template.
So I went in and fixed it.

Then a month later the artist changed the zombie again; and the now the head needed to inherit from a different material. It was a stressing endless loop.
Unfortunately, this wasn't just for zombies. But almost every asset in the game. I tried to instruct the artists on which material to pick, but it was pointless. It's too coder oriented like xavy said.
In the end I ended up auditing the materials every now and then to ensure they were correct.

This was a very displeasing job that Ogre should be handling automatically. We should be picking "Sweater_Red" instead of "Sweater_Red_2_weights_instanced" or "Sweater_Red_3_weights_skinned_shadowed"
And when we add lod materials (one with normal map + specular map + parallax mapping; another without parallax, another without anything fancy for the distance), maintaining so many material is cumbersome.
What you're saying xavy only works out of the box when Ogre is using regular Entities and software skinning.
Owen
Google Summer of Code Student
Google Summer of Code Student
Posts: 91
Joined: Mon May 01, 2006 11:36 am
x 21

Re: RTSS Improvements

Post by Owen »

..demonstrating, I think, the current flaw in the material system: Its' not designed to parametrize materials on mesh properties, when it really should be able to

(Additionally, we should be able to attach e.g. normal maps to a mesh - IMO, there are two types of normal map to consider: those which are related to the mesh (e.g. those derived from a higher-poly version) and those related to the texture (e.g. picking out the details in a piece of gravel); it should be possible for the mesh to specify the former and the material script the later (potentially resulting in both being combined on one entity)

I think the material system needs a rework, then we need an "RTSS v2.0"
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: RTSS Improvements

Post by Assaf Raman »

As the father of the RTSS I guess I should also reply to this thread. Well – a few facts:

The RTSS is the second generation of a shader generator in OGRE, the first version was part of my D3D10 render system effort – since in D3D10 the fixed pipeline was canceled and I wanted to support all current OGRE functionality – I needed to emulate the fixed pipeline. You can see my code in the OGRE history. My approach was a shader generation process completely in C++ code that adds lines to the shader based on the current required state. The result was very hard to maintain, but at least some of the OGRE samples sort of worked. At least all the ones without shaders and that were simple.

The RTSS itself wasn't created for the D3D10, it was created for me by Nir Hasson that worked for me in an unnamed company, the company had existing fixed pipeline engine, I created the next generation engine for the company based on OGRE. When Nir started to work for me we got to a stage where the engine has given the company all the old engine capabilities and I wanted to add new capabilities like per-pixel lighting, normal maps and self shadows for object.

As all the models in the company's resources (a big number of models) didn't use shaders, and I didn't have the resources to go over them all and modify them – I couldn’t start using shaders without building the RTSS – that basically give me the same functionality as the fixed pipeline – so all existing models can be rendered – but can also be extended. So Nir emulated the fixed pipeline, then added the per pixel lighting – and suddenly the product had per pixel lighting without any change to any model or material. Then he added bump map support – and new models could use it. So we added more and more features to it, new shadows techniques, photo shop blending modes, hardware animations groups for instancing, the "hundreds of dynamic lights" support and so on (some of the work was done by also by Mattan that joined and left my team after Nir).
The nice thing was that the RTSS also solved the issue of exiting models and such for other render systems – D3D10 that later was renamed to D3D11 and for the OpenGL ES 2.0 that was released after the RTSS was created and part of OGRE (I am almost sure of that).

So the RTSS is my child, for better or worse. Even if other people wrote the code for me – I am the hand that pulls the ropes behind the curtain. See this month commits and see the changes Lior just made for me.

So, here is my response (I am numbering the points so you can reference them by number for further discussion):

1. The RTSS is used by me and I am satisfied. More then that I have a product that couldn't do what it does without it.

2. The RTSS isn't that hard to learn – Lior learned it in a few days on his own and even made some fixes and extensions to it.

3. The RTSS does optimizations that you will never be able to do with the "#ifdef" mega shaders – as it pack shader parameters automatically between the vertex to pixel shader.

4. Cg and D3D shader compiler optimize the RTSS results very well and for OpenGL ES 2 – there is a solution the unity guys wrote that can be used: http://aras-p.info/blog/2010/09/29/glsl-optimizer/

5. Cg is not dead and actually the best way I know not to write shaders code twice, it is supported even on iOS – see here: http://aras-p.info/blog/2010/05/21/comp ... l-in-2010/

6. Some people wrote that the RTSS is not documented, well, that may be true – but it never held me back (I wander why). I am not going to document it, so I guess it can be one of our future Google summer of code projects.

7. Some people wrote that supporting the fixed pipeline makes the end result look like old games. Well I strongly disagree, what makes games look old are the artists that creates the model, the RTSS gives you all the functionality of the fixed pipeline – but allow you to replace any part you want and extend it. You can decide what part of it to use and what not, how are options a bad thing?

8. Some people wrote that the RTSS\OGRE wasn't built for artists – well, it was built for them, more then that – many extensions were developed because of requests from my artists for more flexibility.

9. The RTSS does have sample how to extend it, look it up – so many extensions, anything that isn't a part of the fixed pipeline is and extension. There is more then one sample in the sample browser that is dedicated for it.

10. The RTSS makes OGRE truly cross platform – as it makes the same code, with the same models – run on different platforms that support totally different shader languages.

11. I welcome any new ideas, but I don't see why one should replace the other. The RTSS is an OGRE component. OGRE can be compiled without it, it is not a part of the core, anyone has a better idea, or an idea for RTSS generation 3 – develop it in parallel – like we have different render systems, scene managers and other plugins.

Also a long post I guess. But I think I wrote all I had to say.
Watch out for my OGRE related tweets here.
f00bar
Halfling
Posts: 57
Joined: Sun Feb 15, 2009 4:00 am
x 1

Re: RTSS Improvements

Post by f00bar »

@Assaf Raman:

Thanks a lot for RTSS.

I think one could boost RTSS adoption with 2 measures (and with that making sure it will be an important part of ogre for a long time): It should be easily usable by the people that don't want to extend it and that just want some basic shaders to use in a platform independent manner.

1) If RTSS would include the most used shaders I'm sure many more people would use it. Some "übershader", a replacement for the monster or monster2 shaders from the wiki. For me, diffuse, specular and normal maps would solve the needs of most of my toy projects (even nicer with support for additional detail maps for any of the maps, with LOD without detail maps; and maybe a simple method to hide tiling).

2) Simple wiki page how to use it (not extend it). Not a long documentation, just "How do I get diffuse, specular and normal maps to work with my app and which parameters can I tune how". "And what if I want to have animations and shadows and LOD". Not all the details, just some starting pointers.


Sorry if this points have been solved in the meantime. It's been a while since I used RTSS for one of my toy projects. At that time normal mapping worked out of the box, but not with a specular map. And I initially had a hard time understanding what to do to use RTSS.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RTSS Improvements

Post by al2950 »

Wow, Ive been trying to coax a reaction out of you guys about this topic for while, clearly I need to be a bit more opinionated! :)

Firstly a rant... Sorry!
I think it is ludicrous that the only graphics we support, out of the box, is FFP. Its 2013 for christ sake! It bugs me that I can recognise a game/simulation made from Ogre a mile away, simply because it looks a bit dated and quite frankly only looks good because of work done by Xavyiy and a few others. Admittedly we attract a lot of devs who are new to the gaming/simulation/programming world which does not help, although I think its great we do attract these people. The point is Ogre is one of, if not the best open source rendering engine on the planet and we should have a material system that can allow things like, physically based lighting, out of the box.
I appreciate there have been many games made with Ogre that do look stunning, the point is a lot of work has gone in to them, and their results can not be reproduced out of the box.
Rant over, :)

Anyway, as we move away from Dx9, we obviously loose FFP, and this is were RTSS works very nicely. Many comments made above about the limitations of RTSS are not necessarily true and come from a lack of understanding of it. This is again down to a lack of documentation, which I hold my self partially responsible. So I will try and clear some stuff up,

Documentation/Use
I have been working on some documentation, unfortunately my life has been a bit complex in the last 2 years, and my company will not pay me to write docs for Ogre! I will try and push some out though so we can get the ball rolling. There are 2 sides to this;
  • Firstly using RTSS, this is very simple, adding new abilities to your material, eg, normal maps, specular maps is very easy, if they exists!
  • Secondly creating new sub render states. Ok this is a bit more complex, and quite frankly can be a little confusing, this obviously needs some work. However its not as bad as everyone thinks!
You need to write C++ to extend RTSS
To be honest this is one of the best parts of it, it means that each sub render state can be incredibly powerful and flexible. There are already a number of examples of this in RTSS which simply could not be done without it.

Unified/Meta shader language
This is an issue, but I believe a separate one to this discussion. Yes we should look at this but it could just plug into the RTSS, or the next reincarnation of it.

Performance
Ok the GLES thing is annoying and is an issue. I have looked at making sure all basic operators are written inline, it would not be to difficult to do, but I think there must be a better solution.

There is another performance issue/bug which I have run into and I believe its the same as syedhs has a while back. I did solve it in my own pipeline, and was something to do with shadow casting renders changing the number of lights that were used on the material, meaning as soon as you used more than 1 light the RTSS would compile new shaders twice every frame because the number of lights changed. Now the RTSS does use a hash system to see if a shader config has already been compiled to prevent stalls like this, but to be honest its not working correctly. Actually it is but its in the wrong place IMHO.

Node based system
RTSS is a coders tool, not an artists tool. Also as a few have pointed out Ogre is used by coders not artists, and we dont tend to be too good at creating GUI tools for very good reasons. However the RTSS effectively just plugs shader snippets together, the inputs and outputs are resolved in the C++ side, some of which can be done completely automatically(ish!) based on 'Content type' eg WVP, Colour diffuse, Binormal world space. I was going to add a couple of things to allow some of these input/outputs to be customised, thus giving the option to use RTSS as the backend to a node based material tool.

Loosing low level shader access
I dont think anyone in this community would ever suggest that is a good idea :wink:, I think RTSS fits in nicely where it is, as component, at the moment

Disclaimer
I am not trying to blindly defend RTSS, and there is list of issues with it, but I do think it is a step in the right direction. I also have to admit I have not looked at Scrawl's Shiny yet, so I can not comment on how it compares to RTSS. Sorry Scrawl! Although it does not have a C++ side and I really do see the C++ side as a +ve not a -ve , I am C++ dev after all!

I dont want to start listing the benefits of RTSS, although there are a few large ones that have been missed, but I really would encourage the more advanced devs to give it a good look and try and understand it. Then we can try and see what needs to be done so we can end up with a large material library out of the box which everyone desperately wants!

Sorry for the long post, but trust me it was a lot longer!

Gus