Help!How to draw all the objects in only one DrawPrimitive() call?

Started by
19 comments, last by AlanWu 11 years, 4 months ago

how to put the texture into one buffer?How to make the textures connect to the vertices?

That depends on what API you're using. Is this DirectX11? XNA? Something else?
In most cases, (assuming the vertices also have texture coordinates associated with them) you pass the texture and the texture coordinates to the pixel shader drawing the mesh.


And what kind of optimizations you think i still can do?


Optimizations could include:
View-frustum culling (don't even bother drawing something the camera can't see)
Storing geometry in a partitioning tree to cull entire branches that aren't visible (makes the culling process more efficient than checking per-mesh)
Instancing (if you have a lot of identical/similar meshes)
Batching by material/effect to reduce changes to the rendering pipeline
...the list goes on. There are a lot of articles and blogs about how different studios grabbed those last extra frames-per-second by some code trickery, but like I said before, pre-optimization is a trap you can fall into, making your task overly-complex without confirming you even NEED to based on your use cases.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

Advertisement

[quote name='AlanWu' timestamp='1354606053' post='5006992']
how to put the texture into one buffer?How to make the textures connect to the vertices?

That depends on what API you're using. Is this DirectX11? XNA? Something else?
In most cases, (assuming the vertices also have texture coordinates associated with them) you pass the texture and the texture coordinates to the pixel shader drawing the mesh.


And what kind of optimizations you think i still can do?


Optimizations could include:
View-frustum culling (don't even bother drawing something the camera can't see)
Storing geometry in a partitioning tree to cull entire branches that aren't visible (makes the culling process more efficient than checking per-mesh)
Instancing (if you have a lot of identical/similar meshes)
Batching by material/effect to reduce changes to the rendering pipeline
...the list goes on. There are a lot of articles and blogs about how different studios grabbed those last extra frames-per-second by some code trickery, but like I said before, pre-optimization is a trap you can fall into, making your task overly-complex without confirming you even NEED to based on your use cases.
[/quote]

ok,thank you!
I will try it.

[quote name='AlanWu' timestamp='1354606053' post='5006992']
how to put the texture into one buffer?How to make the textures connect to the vertices?

That depends on what API you're using. Is this DirectX11? XNA? Something else?
In most cases, (assuming the vertices also have texture coordinates associated with them) you pass the texture and the texture coordinates to the pixel shader drawing the mesh.


And what kind of optimizations you think i still can do?


Optimizations could include:
View-frustum culling (don't even bother drawing something the camera can't see)
Storing geometry in a partitioning tree to cull entire branches that aren't visible (makes the culling process more efficient than checking per-mesh)
Instancing (if you have a lot of identical/similar meshes)
Batching by material/effect to reduce changes to the rendering pipeline
...the list goes on. There are a lot of articles and blogs about how different studios grabbed those last extra frames-per-second by some code trickery, but like I said before, pre-optimization is a trap you can fall into, making your task overly-complex without confirming you even NEED to based on your use cases.
[/quote]

well,i don't know how to do it,do you have some tutorial about using pixel shader to draw the mesh?
could you give me some tutorial or some example?
i just learnt how to use pixel shader yesterday.
thank you!
Loading and sampling a texture is very standard stuff as far as pixel shaders, wherever you learned how to use the shader should also cover texturing. You'll greatly benefit from learning how to search for references on google.

A few minutes of poking around dug up this, which incidentally I found by searching this very site and running across this thread.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)


Loading and sampling a texture is very standard stuff as far as pixel shaders, wherever you learned how to use the shader should also cover texturing. You'll greatly benefit from learning how to search for references on google.

A few minutes of poking around dug up this, which incidentally I found by searching this very site and running across this thread.


thank you!

Loading and sampling a texture is very standard stuff as far as pixel shaders, wherever you learned how to use the shader should also cover texturing. You'll greatly benefit from learning how to search for references on google.

A few minutes of poking around dug up this, which incidentally I found by searching this very site and running across this thread.


i still don't understand.i learnt how to use Pixel Shaders.
But,how to use Pixel Shaders to change the texture?
You don't use a pixel shader to change the texture, you change the texture a pixel shader is referencing (nuances of english syntax, so this might just be confusing at the moment).

In other words, a pixel shader will sample from a texture and draw that to the polygons' surface. For the shader to know which texture to use, you have to pass it the texture in your application code. If you want a different texture to be used, you pass in a new texture to that shader before drawing more polygons.

If you "learned how to use Pixel Shaders" then you should know how to do this. Otherwise you haven't learned how to use pixel shaders yet.

Read through the tutorial I linked before, as well as this tutorial on the same site. If you're just looking for code, the last line in that second tutorial shows how to change the texture.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

well,i want to use 100 different textures in one DrawPrimitive() call.
I used PixelShader,but how to pass 100 textures into the PixelShader?
I know use tex2D(sampler,tex coord); to get texture pixel then return it.but,how could i get the texture in PixelShader?
I think i can use SetTexture(xx, Tex) and multiple sampler,but PixelShader 2.0 only support 16 samplers.
And ,do you have a facebook?
I want to add you,facebook chat is easier.

This topic is closed to new replies.

Advertisement