Sign in to follow this  

Deferred shading material ID

This topic is 1959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I encountered some problems with this technique with implementation using xna 4.0. I understand the basic idea of material IDs, my main problem is passing material list into shader.
While searching on the net for answer to my question i found two ways of doing that:
1. Use texture arrays
2. Use texture3D to store materials
As far as i know XNA does not support texture arrays, so first one is out. With second one I got one problem, I have no idea how to use setData with texture3D
(say, i got 4 textures 256x256, but i don't know how to "push" them into texture3D).
My question is how to do that? (I know how to handle it inside hlsl, I only got problems with xna side)
Also, if someone know another way I'll be grateful [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Thank you in advance [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
(note: I don't want to use texture atlas) Edited by Tasaq

Share this post


Link to post
Share on other sites
You should be able to bind each shader to their own individual sampler by finding the parameter in your effect and setting the value,and then read from them using tex2D( sampler, texCoord );

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1343709246' post='4964710']
You should be able to bind each shader to their own individual sampler by finding the parameter in your effect and setting the value,and then read from them using tex2D( sampler, texCoord );
[/quote]
I hope i understood You corectly:) I don't want to create ubershaders for materials neither hardcode limited number of texture lookup. I want to use flexible method so when graphician wants to have 10, 20 or 30 materials there won't be any problems with that.
By the way i took the texture3D idea from Catalin Zima [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Tasaq

Share this post


Link to post
Share on other sites
Basically you can conceptualize the 3D texture as a bunch of 2D textures one right after the other, with the number of 2D textures being equal to the depth of the texture. So you'll fill up the first 2D slice, then the second, then the third, and so on. Then when you access the texture in your shader a texture coordinate Z component of 0 will correspond to the first slice, and 1.0 will correspond to the last slice. Edited by MJP

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1343770198' post='4964998']
So you'll fill up the first 2D slice, then the second, then the third, and so on.
[/quote]
Texture2D is nullable so i have no clue how i can create texture3D. With texture2D I create an array of Color type with size equal to number of pixels and then use setData(for instance, I use it to create noise). But with 3D texture I am confused :(
Coul you tell me if it's good idea to do it this way (personaly, it doesn't look to clean for me):
[CODE]
tex2d[0] = Content.Load<Texture2D>("material1");
tex2d[1] = Content.Load<Texture2D>("material2");
Color[] tempColor = new Color[256 * 256 * 2];
int iterator = 0;
foreach (var texture in tex2d)
{
Color[] color = new Color[256*256];
texture.GetData(color);
foreach (var vector3 in color)
{
tempColor[iterator] = vector3;
}
}
tex3d = new Texture3D(GraphicsDevice, 256, 256, 2, false, SurfaceFormat.Color);
tex3d.GetData(tempColor);
[/CODE]
I used constants just in this example.

Share this post


Link to post
Share on other sites
a material ID is a per vertex information. A texture is bind to a slot before you render and ID is readable in shader. Then, in shader you decide which slot to sample. I see no complication. (textures are not uniform data, it is texture2D slots that has been bound before you call draw of the mesh, so make sure that the IDs corespond to textures you have bound). Also you should realize that amount of textures that can be bound to a single pass should never exceed 32. (common gpu ability)

Share this post


Link to post
Share on other sites
[quote name='JohnnyCode' timestamp='1343872038' post='4965373']
a material ID is a per vertex information. A texture is bind to a slot before you render and ID is readable in shader. Then, in shader you decide which slot to sample. I see no complication. (textures are not uniform data, it is texture2D slots that has been bound before you call draw of the mesh, so make sure that the IDs corespond to textures you have bound).
[/quote]
I think I wrote there that I unerstand the concept of material IDs :)
[quote name='JohnnyCode' timestamp='1343872038' post='4965373']
Also you should realize that amount of textures that can be bound to a single pass should never exceed 32. (common gpu ability)
[/quote]
True, but we shouldn't say "32 is max and I can't do more, I won't even try". In XNA, with texture3D you can create a voxel cube with size of 256x256x256 - that makes a set of 256 texture lookups. 256x256 texture is fine for per-pixel anistropic lighting (at least for personal purposes).
MJP said everything I needed :)

Share this post


Link to post
Share on other sites

This topic is 1959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this