Fluxtah

Welcome to another one of my newb questions!

Can somebody explain the difference between a material and a shader

My own ideas would probably be:

- A Material defines the texture and lighting properties of a surface, and maybe even the sound properties of a surface. Visual qualities of a material can be described with  shader(s) !

Anyway, if someone could give me some ideas here as I find the two terms quite conflicting, but its probably because of my limited understanding!

cheers :)

The reason I ask is I was thinking about making a Material class that maybe describes texture, lighting properties and sound of certain geometry.

edit: by the way I have checked out the definition of a material in the directx documentation but it only describes a material as something that has lighting properties, surely a material can go beyond this definition

Maybe material is something that was preshader :) confused...

 



Re: XNA Game Studio Express Material vs Shader

Arek Bal

To fully understand this topic...u got to get into HLSL a li'l and VertexShader>>PixelShader.

I'll try to explain it as easily as I can. This topic is really sophisticated ...so I am gonna just show you the direction for answers:

- Shaders are recalculating your information on Object into screen. Vertex shader/s mainly calculates geometry...then Pixel shader/s calculates this into ("texels to pixels for example") screen.

This is done by effects...i hope you already seen BasicEffect class. (Effect class for your own effects).

So as you can see, relation between these two words - Material and Shaders is clean.

Material is the collection(not that collection class) of graphical features connected to an 3d object. It's not a professional description but I do hope it will help on your way.

Only light is somewhat out of definition. You will usually recalculate your objects reaction to light.

Sorry for noobie to noobie answer. Never ever again.

EDIT: Creating Material class...isn't "good way". Sometimes you will call to the same texture/effect from many objects.




Re: XNA Game Studio Express Material vs Shader

Fluxtah

I should have mentioned I have no problems understanding HLSL, that was not my question.

Maybe the original usage of Material is out of place with current technologies used to describe properties of a surface (shaders do this), this is my idea of material:

Glass
Wood
Concrete
Rock
Stone
Clay
Carpet
Paper
Plastic
Plant
Metal
Cloth
Fluid

This is the dictionary definition of material:

the substance or substances of which a thing is made or composed: Stone is a durable material.

The original D3D Material, in my mind is out of place with shaders, maybe LightingProperties would have been more suitable, because a material is so much more than how a surface deals with light, surely





Re: XNA Game Studio Express Material vs Shader

Arek Bal

Hmm... u mean all, not only the graphics...

I was thinking one more time on this material class...you can(you should) make a way of "Material" class to operate on this kind of database. You will have a list of 3d objects, and a list of properties (from physics to sounds).

But in meaning of 3d graphics...material is what I already said...It's a list of textures(maps also) and effects attached to 3d object.
EDIT: Surface is about geometry mainly (bump, parallax and so on) .
http://en.wikipedia.org/wiki/Surface






Re: XNA Game Studio Express Material vs Shader

Fluxtah


But in meaning of 3d graphics...material is what I already said...It's a list of textures(maps also) and effects attached to 3d object.

This makes sense, although I think the definition has been outdated (at least the d3d definition is pre-shader).

In the context of XNA, there is no material anymore, why is this





Re: XNA Game Studio Express Material vs Shader

Arek Bal

EDIT2: I was thinking some time, where is difference between surface and material...
I found: Example - glass...it have a surface and some translucent calculations.




Re: XNA Game Studio Express Material vs Shader

Fluxtah

Do you think sound has a place in materials (in the non computer graphics sense)

A material can emit sound when knocked, brushed, walked on etc, but materials are not the only thing that emit sound.







Re: XNA Game Studio Express Material vs Shader

ClydeCoulter

Fluxtah, it sounds like you are struggling with the Object Oriented sense of your organization of properties for objects.  This is good :) good thinking :)  What is the name of the object class that deals with this kind of information for these kinds of things.

Material properties can be attached to objects, but objects may be made of more than one material.  You might add mass, melting point, etc....to a material, but.....is that what you want to think of as object properties

(edit) I see material (effect properties ) as the description of light(s), color(s) and texture but the shader applies these attributes to the object (although the shader might also contain hard-coded or calculated properties also, like shadows, etc..)






Re: XNA Game Studio Express Material vs Shader

Fluxtah

Yes, in some ways I am thinking of how better to organise things so they are more intuitive and obvious to what they do.





Re: XNA Game Studio Express Material vs Shader

ClydeCoulter

Okay, I think I have a way to think of material vs shader.............

Material (in xna/dx) are the properties that shaders work with to apply visual effects to 3d/2d objects. That is, if we look at shader/material/effect as an object class, then material (effects) are the instance data and shaders are the implentation. (in a manner of speaking, although not exclusively).






Re: XNA Game Studio Express Material vs Shader

Fluxtah

hmm that makes sense but does that mean a Material can have multiple effects

Ive been googling on surface properties, partly from how hl2 does things and also unreal.

HL2 define materials that are associated to some shader, defining what textures make up that material as well as surface properties.

On a basic level if I was to define a material in xml it could look like this:

<material name="Grass" shader="BumpMapped">
 <texture>grass.dds</texture>
 <normalmap>grassnormalmap.dds</normalmap>
 <properties>
         <sound>grass.wav</sound>
 </properties>
</material>

To be honest I dont think I want to jump right ahead and make a complex material system but just something I can start with and build on otherwise I will get bogged down in design decisions when I can always refactor as I need more.

I think at the most basic I want an easy way to define, what texture, what shader, what sound and wrap them up all in a nice abstracted way, like an xml file that I can deserialize in a pre-processing stage.

edit: by the way clyde do you want me to send you that terrain shader as a rendermonkey file It would probably be better that way then you can see it working before exporting it as an fx file, it supports a base texture and 6 detail textures + lightmap, only problem is its a 3 pass shader when I really only wanted 2 pass but I couldnt figure out how to apply the lightmap other than in a 3rd pass :(
 





Re: XNA Game Studio Express Material vs Shader

ClydeCoulter

Fluxtah, I have not tried rendermonkey, but I just went and found it on ATI's site, so I can download it......I actually, wanted to discuss possible collaboration efforts if we can come together on some foundational points so that we don't duplcate but rather compliment one anothers work. I would be glad to check out the shader (I'm new to hlsl) but more so, I would like to maybe come up with some plan that would allow our "things" to work together for the benifit of both of us. But we can discuss this offline of this forum, if you don't mind email or even phone to start out. I would like to find out what your ultimate goal for your engine is (and you mine) and see if we have a really similar goal, since so far from forum messages, it sounds like we do (as far as cababilities, not necessarily game).

Back on the forum topic, do you think that 3d objects can share shaders in your engine (like shadow map would be a pair techinques that are shared for objects that cast a shadow and then there are receivers). Perhaps texture, some lights and a few material like elements are per object, but some are global (sunlight ). Refactoring can be expensive sometimes, depends on the extent and how the object model is organized (which I'm sure you already know).






Re: XNA Game Studio Express Material vs Shader

Fluxtah

Hi I sent you an email about the collaboration idea.

The only thing that concerns me about having multiple shaders per object is how to effectively organise shader code, I am also very new to HLSL but I have a few books and I understand the general principle of vertex / pixel shaders, and HLSL is a breeze to write, its just the physics and maths side of things that are not instantly in my grasp.

The only way I can think of is to dynamically build shaders in a preprocessing step to essentially optimise them for a certain usage. Its either one great uber shader that does everything, or lots of small shaders fragments that are linked together to form a final output, or even shaders that contain duplicate code.. not a good prospect. again I am very new to shaders and game programming in general, so I am not sure how to persue this until I learn more.

I think maybe distilling useful shaders into a library and not thinking to 'big' might be the way forward and live with the fact of duplicated code for now, I have the time (probably the rest of my life) to refactor, as I am not a game developer by trade and I am in no rush to be one either, I am probably to old for that :)

I quite like the way Valves VMT files work, this seems an ok way to associate textures, shaders and physical properties, I will probably start with my limited XML example above and build/refactor from there on.





Re: XNA Game Studio Express Material vs Shader

zxdgsadf

Fluxtah,

I'm still learning this too but here's the way I understand it so far (not to say that I'm right, this is simply my understanding *so far*):

Materials are a combo of color, diffuse color, spec color, mirror color, alpha percentage, reflectivity and textures applied to color, mirror, spec, normal and alpha channels and they can be applied unevenly, keyed to a greyscale or color key image that tells the renderer where to apply the channel and how much by the key images levels (did I miss anything ).

Shaders are, instead, information about what color should be mapped to each vertex. Then there is the matter of exactly how the color values of pixels on the faces and edges that are in between vericies should be calculated and rendered. This is also done within the shader code.

Is there more Dunno, I haven't finished the tutes. You can follow along here:

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Starting_point.php

By the way, my idea of a "material" comes from 3D modeling... and I described most of the things that Blender uses to calculate what a given material should look like when rendered.

Good luck,

Scott





Re: XNA Game Studio Express Material vs Shader

Arek Bal

You are still going around my definition. Also, when you create some definition like this for yourself. Remember that mapping is for help...and task performed by maps...teoretically can be maintained by formulas...and sometimes these could be easier. Look on maps as 0 to FF per pixel.