Deferred shading material ID

Started by
5 comments, last by Tasaq 11 years, 9 months ago
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 smile.png
Thank you in advance smile.png
(note: I don't want to use texture atlas)
Advertisement
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 );
Perception is when one imagination clashes with another

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 );

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 smile.png
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.

So you'll fill up the first 2D slice, then the second, then the third, and so on.

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):

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);

I used constants just in this example.
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)

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).

I think I wrote there that I unerstand the concept of material IDs :)

Also you should realize that amount of textures that can be bound to a single pass should never exceed 32. (common gpu ability)

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 :)

This topic is closed to new replies.

Advertisement