login

Author Topic: Shader and Graphical effects Discussion  (Read 39195 times)

Offline Ursca

  • Deus Vult Dev
  • *****
  • Posts: 128
    • View Profile
Shader and Graphical effects Discussion
« on: October 23, 2007, 04:43:24 PM »
Mtarini has been doing some very impressive things with TLD, and I know Scion has dabbled in shaders, so I thought the time was right to devote a topic to the uh, topic.

I think a few of us are rather intrigued about how far the new shaders can go. Is it possible to write a dynamic normal map shader for instance? Can shaders be made that affect everything on the screen, for some post-production style effects? I certainly didn't think the banner waving shader was possible, so I don't know what to expect.

So, anyway, to start off, what's the procedure for making normal maps now? I've got a bump map that I need making into a normal map, but I don't know how to got about it.

Offline mtarini

  • Administrator
  • *****
  • Posts: 1495
  • TLD dev team
    • View Profile
    • (home)
Re: Shader and Graphical effects Discussion
« Reply #1 on: October 23, 2007, 05:11:47 PM »
Just a matter of terminology: a bumpmap in M&B is already a normal map. Both terms sometimes are referred to some different things, but I thnk they are the same in this context.

How did you get your "bumpmap"? Knowing that I can give you a more detailed answear as to whether or not that's a ready "normalmap" to be used in current  M&B shaders.



About the "can a shader be used for this or that", I think that a general answer is: being a form of programing, shaders are very versatile tool and is very difficult to bound what is possible to do.
However, there are limits, of at least three different kind:
- limits of the shader very structure -- it's out of the shader paradigma;
- limits due to the fact that you can monkey with the shaders alone (as opposed to the shaders and the M&B code);
- computational expense limits (too complicated things would annihilate any computational power);

The extent of these limits are impossibly hard to describe in general. One could state a few clear cut rules, going technical, but there might be tricks to get the same result is some other ways.

So I suggest a different general strategy:

If someone has something (some effect, some feature)  that would like to see introduced, go ahead and ask. Ask that, precisely the specific thing that you would want "is it possible to have motion blur in arrows?"...  "a rotatin chainsword?" ... "falical expression?".  Often, it will be found impossible by someone for some specific reason. Other times, noone will find a way to do that (which is no proof that it is not possible). Sometime, someone with find a way to do that. Thinking of the right effect to do is half of the work.

Beside, one should try to use the shaders to achieve a desired effect, not the other way rond (use an effect just because a shader can be written to do that).

Yoshiboy

  • Guest
Re: Shader and Graphical effects Discussion
« Reply #2 on: October 24, 2007, 04:13:07 AM »
I read your post in the other thread - that sounds great! If you could do that it would be a great step for M&B really. Taking the visuals up altogether.

I've been making normal maps for ages now.

Because of laziness I was going to use a program called crazybump http://www.crazybump.com/ to generate the normal maps from our existing textures (as it really is a kick ass program) but I can make them in other ways too.

Using the nvidia normal map tools and also using zbrush and rendering from a high poly mesh. I've got plenty of practice using both. The problem with those is I would usually only do that when working from an original creation. But I mean, any NEW meshs and textures which are created, as long as they follow some simple procedures (like, for textures, keeping the layers set up nicely, different layers for different 'bumps' or 'textures') or for meshes keeping it as a nice mainly quads dub-division mesh, we can create even better normal maps for those.

Spec maps I was mainly going to copy over the native iron shader alpha maps. But there are a few other tricks I can do with those in conjunction to normal maps in some places.


Quote
So, anyway, to start off, what's the procedure for making normal maps now? I've got a bump map that I need making into a normal map, but I don't know how to got about it.

If you have the nvidia DDS tools installed for your photoshop you should also have normal map tools (afaik) . Flatten all layers and in filters select normalmap filter from the nvidea options branch. Play with that.


I mean, we could get into normal maps and spec maps and talk about them for a long time, but its not worth doing until we have some kind of test shader to see what it really looks like.

Offline Ursca

  • Deus Vult Dev
  • *****
  • Posts: 128
    • View Profile
Re: Shader and Graphical effects Discussion
« Reply #3 on: October 24, 2007, 04:46:17 AM »
How did you get your "bumpmap"? Knowing that I can give you a more detailed answear as to whether or not that's a ready "normalmap" to be used in current  M&B shaders.
Maybe I should have said height map. A simple black and white one, like this:


I would use the nvidia plugin, but someone said that the native normal maps are green because Armagan's put the red channel in the alpha channel or similar. I'm assuming that the normal maps created with the nvidia plugin won't work because of that.


As for suggestions, you said that Armagan's agreed to allow shaders to be affected by scripts. Can a texture be switched for another one using a script?
I'm mainly thinking of seasons here. If you could switch the grass texture for a snow one, change the tree foliage to appear dead, and make an invisible texture change to make icicles appear, that would go an awful long way to representing seasons in M&B.

And Yoshiboy: Thanks for the link to crazybump. It looks fantastic - downloading now.  :D

Offline Ron Losey

  • Master
  • *****
  • Posts: 4418
    • View Profile
Re: Shader and Graphical effects Discussion
« Reply #4 on: October 24, 2007, 04:56:47 AM »
If some of you guys who know what you're doing have some time....

ONR needs a shader config that will allow alpha channel (for the cutouts in the tsuba) (Tsuba - sword handguards) and iron shaders for the blades (on the same item).  I don't know how to set it up ... but I'm sure somebody does.  Take a look at the swords in ONR to see what I mean. 

Just because I cooked up the cutouts in the handguards using alpha channels, that does not mean I know what I'm doing.


Yoshiboy

  • Guest
Re: Shader and Graphical effects Discussion
« Reply #5 on: October 24, 2007, 05:41:09 AM »
Quote
Maybe I should have said height map. A simple black and white one, like this:

Heightmap and bumpmap are the same thing really - yeah.

Quote
I would use the nvidia plugin, but someone said that the native normal maps are green because Armagan's put the red channel in the alpha channel or similar. I'm assuming that the normal maps created with the nvidia plugin won't work because of that.

Ah yeah, armagan has a funny set up to his normal maps.

If you generate a normal map from the texture above you'll get something blueish (either using crazybump or the nvidea tools), now in photoshop switch to channel's tab (next to layers). You'll get the red green and blue channels shown. You'll notice the blue channel has hardly anything - if nothing on it. Armagan has cut out this layer.

To convert to the type of maps armagan uses, copy the green colour layer onto a new texture, and then copy the red layer onto the alpha channel of this new texture. This should then look like the kind of green normalmap armagan uses. I propose we don't use these though - mainly as it saves us the process of this conversion (which I don't really know why armagan does it)

Shaders can't really switch the texture over time like that, because afaik people were stuggling to even get a local time variable into the shader rendering, not to mention the variable for time on the world map.


Quote
ONR needs a shader config that will allow alpha channel (for the cutouts in the tsuba) (Tsuba - sword handguards) and iron shaders for the blades (on the same item).  I don't know how to set it up ... but I'm sure somebody does.  Take a look at the swords in ONR to see what I mean.

With our proposed normal map and spec map shader this would be possible. The alpha channel on the bumpmap would represent how shiny parts of the object are while the alpha on the diffuse (colour) map would represent the transparency.

Offline Ron Losey

  • Master
  • *****
  • Posts: 4418
    • View Profile
Re: Shader and Graphical effects Discussion
« Reply #6 on: October 24, 2007, 05:59:14 AM »
Quote
ONR needs a shader config that will allow alpha channel (for the cutouts in the tsuba) (Tsuba - sword handguards) and iron shaders for the blades (on the same item).  I don't know how to set it up ... but I'm sure somebody does.  Take a look at the swords in ONR to see what I mean.

With our proposed normal map and spec map shader this would be possible. The alpha channel on the bumpmap would represent how shiny parts of the object are while the alpha on the diffuse (colour) map would represent the transparency.

If and when you get it working, somebody else is going to have to set it up and/or explain to me exactly how to set it up.  Because I sure don't know. 

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Shader and Graphical effects Discussion
« Reply #7 on: October 24, 2007, 06:21:02 AM »
If some of you guys who know what you're doing have some time....

ONR needs a shader config that will allow alpha channel (for the cutouts in the tsuba) (Tsuba - sword handguards) and iron shaders for the blades (on the same item).  I don't know how to set it up ... but I'm sure somebody does.  Take a look at the swords in ONR to see what I mean. 

Just because I cooked up the cutouts in the handguards using alpha channels, that does not mean I know what I'm doing.

For a simple solution that requires no further code work, just multi-mesh the blades in your BRFs and give them different materials with different shaders attached.

Offline Ron Losey

  • Master
  • *****
  • Posts: 4418
    • View Profile
Re: Shader and Graphical effects Discussion
« Reply #8 on: October 24, 2007, 06:41:12 AM »
If some of you guys who know what you're doing have some time....

ONR needs a shader config that will allow alpha channel (for the cutouts in the tsuba) (Tsuba - sword handguards) and iron shaders for the blades (on the same item).  I don't know how to set it up ... but I'm sure somebody does.  Take a look at the swords in ONR to see what I mean. 

Just because I cooked up the cutouts in the handguards using alpha channels, that does not mean I know what I'm doing.

For a simple solution that requires no further code work, just multi-mesh the blades in your BRFs and give them different materials with different shaders attached.

Multi-mesh is extremely uncooperative in .89x ... not sure why, but it's a real pain.

Even if we can get multi-mesh to work, it still slows down the game redrawing everything twice.  It would be better to let these guys figure out what they're doing and set it up right.

Offline mtarini

  • Administrator
  • *****
  • Posts: 1495
  • TLD dev team
    • View Profile
    • (home)
Re: Shader and Graphical effects Discussion
« Reply #9 on: October 24, 2007, 08:13:47 AM »
Maybe I should have said height map. A simple black and white one, like this: [IMG]

I see. I would call that "preshaded map", because, you see, it is already dark where the final color should be dark and bright where the final color should be bright.

With that data, I guess, the best thing you can do is to blend it with colormap (differently from a normal map, there is no way to make it react to dynamical changes in light: what is darker-brighter will remain so, no matter where sunlight comes from). That's not as bad as it sounds, and for approximating global illumination it is even a better solution than normal maps (because a normal map is direct illumination only).

Anyway, there is no need to blend the "preshaded map" and the RGB map  in the shader. You might as well blend it with the RGB texture with photoshop (or whatever) and use the result as a ready RGB texture.

The final result would be the same. So, no need of shaders here.

PS: in photoshop, use the "light" blending mode for that layer.



grailknighthero

  • Guest
Re: Shader and Graphical effects Discussion
« Reply #10 on: October 24, 2007, 02:09:14 PM »
One thing I have been wondering about is if we can get flaming weapons that use shaders instead of particles.  I have no idea how shaders work though so it might not be possible.  The flames wouldnt have light coming from them but it still would be better than nothing.

Offline mtarini

  • Administrator
  • *****
  • Posts: 1495
  • TLD dev team
    • View Profile
    • (home)
Re: Shader and Graphical effects Discussion
« Reply #11 on: October 24, 2007, 11:01:42 PM »
Flaming sword: I think it should be possible, using a few tricks.

Yoshiboy: do you have a model that has it all? That is, a (normal map + shiny) and a (rgb map + transparency)?
So that I can work on the shaders with something to test them on.

Digression: I hope that it is clear that the normal map must be in object space.

Just double checking that it is understood: usually, this means that you cannot tile it.
For example, say that you have an orange, and the normal map is used to place the bumps on its skin: you cannot
use the same normal map both for the front part and the rear part, because in the front part the normals point toward the
front, and are around (0,0,1) and in the rear part they point backward, at (0,0,-1). If the normal map was expressed
in tangent space instead, it would be ok to tile the texture over the skin, because the normal map would then describe
the discrepancies w.r.t the local orientation of the surface. We cannot have that in M&B, shaders would have to work
on something they don't have.

Forgive me if I've been restating the well understood. End of digression.

Also, I would like to have a rigged anything with normal maps (+shininess).
Again, normals of the normalmap must be in object space, and in the "initial" position.

Ideally, give me models that are ready to test, in a single brf file which includes the used material.


Also, we must agree on encoding on normals. Is it fine to use the M&B way? that is, RGB is XYZ of
normals? And the shininess: is it fine that it is the M&B way, that is, a weight used to kill shininess
(instead of phong exponent?). Having a single format for texture maps can be useful.
I got it that there are other standard ways to encode normals, but I don't know what they are exactly.

Offline Merlkir

  • Administrator
  • *****
  • Posts: 5742
    • View Profile
    • My DeviantArt online Gallery
Re: Shader and Graphical effects Discussion
« Reply #12 on: October 25, 2007, 12:47:19 AM »
with the flaming sword mention one old idea came to my mind.
Could we make a Balrog?
the skin would be somewhat similar to the movies. Ash and dust, but when he moves, or in a random pattern there would be fire emitted. I imagine we could add the smokey cloak with particle effects, but a shader for the main body would be nice..
Here's my gallery: http://merlkir.deviantart.com/

I'm now painting and drawing commissions. I'll paint portraits, pets, girlfriends, favourite characters..you name it. Send me a PM if interested ;)

Yoshiboy

  • Guest
Re: Shader and Graphical effects Discussion
« Reply #13 on: October 25, 2007, 02:13:29 AM »
Flaming sword: I think it should be possible, using a few tricks.

Yoshiboy: do you have a model that has it all? That is, a (normal map + shiny) and a (rgb map + transparency)?
So that I can work on the shaders with something to test them on.

Digression: I hope that it is clear that the normal map must be in object space.

Just double checking that it is understood: usually, this means that you cannot tile it.
For example, say that you have an orange, and the normal map is used to place the bumps on its skin: you cannot
use the same normal map both for the front part and the rear part, because in the front part the normals point toward the
front, and are around (0,0,1) and in the rear part they point backward, at (0,0,-1). If the normal map was expressed
in tangent space instead, it would be ok to tile the texture over the skin, because the normal map would then describe
the discrepancies w.r.t the local orientation of the surface. We cannot have that in M&B, shaders would have to work
on something they don't have.

Forgive me if I've been restating the well understood. End of digression.

Also, I would like to have a rigged anything with normal maps (+shininess).
Again, normals of the normalmap must be in object space, and in the "initial" position.

Ideally, give me models that are ready to test, in a single brf file which includes the used material.


Also, we must agree on encoding on normals. Is it fine to use the M&B way? that is, RGB is XYZ of
normals? And the shininess: is it fine that it is the M&B way, that is, a weight used to kill shininess
(instead of phong exponent?). Having a single format for texture maps can be useful.
I got it that there are other standard ways to encode normals, but I don't know what they are exactly.

Yeah, I've got a few models. I'll send you a PM in a second.

We can't do tangent normal maps? :( sorry I don't know the terms that well but those are the blue looking ones?



However we can have the multi-colored ones or world space ones (whatever they are called)? Like this -



But armagan practically has the tangent ones working as his weird type of green variation on them...I can't really tell the point of the world space ones as they don't adapt to light source changes or face normal changes. They are only really good for static rendering - but then you may as well shade the diffuse texture yourself with a bit of light and dark areas.

Eitherhow I can probably get you both types of normalmap for the mesh I have in mind. As shown above ;)

That way of encoding the normal maps sounds fine to me.

As for shine, for now we may as well go with the M&B way, it seems to work well enough and it sounds easier.

Offline mtarini

  • Administrator
  • *****
  • Posts: 1495
  • TLD dev team
    • View Profile
    • (home)
Re: Shader and Graphical effects Discussion
« Reply #14 on: October 25, 2007, 07:51:00 AM »
Merlkir:

Balrog? Exciting! Of course, all kind of gameplay issues come to mind... like, the player should be death as soon as he gets within 2 meters of the thing, and it won't die no matter what you throw at him, neither will it stop. It should be making multiple victims per blow (something we can't really do, I think). What can take a Balrog down? (short of an insanely hi-level "Moria the roguelike game" character, Gandalf - any color, or a blue screen crash of the game?)

Technically, it would be fun to try to render it. However, both for it and the flaming sword, I would feel more confident about the result if we had a "time" variable accessible from the shaders. We will in the future, or so it seems, but we sure don't now.


Yoshi:

I will check again when I'll find the time, but I think the "blue" one (tangent space normal maps) cannot be used. They would require the game to send to the shaders some description of tangent space, and it seems it doesn't. If that's correct, there's nothing I can do. Are you saying that they work in some form already? Then my assumption must be wrong. It must have slipped me when I looked for that in the code. I will look again.

The other multicolored kind ("model space normal maps") are surely usable, I don't need the core-game collaboration for this one.
And yes, they would react perfectly to changes or light direction and to rotation of the object. So it would not be like a preshaded diffuse texture at all. It will really be good normal maps. For a static object, they work just as well as the other kind, and are lighter to render.

Working on it, they will react (almost) correctly to the deformation of the model introduced by the rigging and skeletal animation too (said differently, it will be possible to write a normal maps shader for rigged meshes). This will be an approximation, but under most conditions a good one. The shader will be quite a bit more complex, but can be done.
Let me repeat one last time that the normals in the map must be referred for the "neutral" pose. Notice that this last point makes sense only for model space normal map: tangent space normal map are independent of that.

The problem with "model space normal maps" is a problem of rendering ("my job") but of modelling ("Yoshi's job"). It is that they are a lot less flexible: for example, that shark cannot be correct: you are using the same normal map for both sides, but if that's correct for the left side then it cannot be correct for the right side. (how much will this show, is another matter; but could be very much - will result in inchoerent lighting w.r.t. the rest of the scene).

In "model space normal maps" you cannot use the same texture for two differently oriented polygons. With the tangent space one, you can. That's why they are better (but they are also more complex and less fast).

Summary:
+ I need to double check that tangent space ("blue") normalmaps cannot really be used.
+ model space ("multicolored") normalmaps can surely be used, and will be dynamically lighted according to orientation of the object
+ but, with model space ("multicolored") normalmaps you cannot use the same texture for differently oriented polygons.

+ And, rigged normal maps object can be done too

PS: will see the data you sent me in a sec.