Search code examples
3dxnadirectxdirect3d3d-modelling

Direct3D or XNA Rendering custom billiard balls


I'm working on a math game where the numbers (0-99) are used for the questions and the answers (like standard billiard balls, but they only go to 15 normally).

So, I'm thinking it'd be a lot smarter to generate at -least- the numbers programmatically rather than modelling 99 different balls in 3DSMax or similar.

I'm working in C#/XNA but can handle an explanation in DX11/C++ as well.

I'm not looking for code, but rather an approach: sort of a bullet list that would look like this (if this were anything close to correct):

  • Build a shpere in 3DS that is white and has a stripe on it.
    • Or, should the strip be part of the texture I later add?
  • During DrawModel change the color of the ball (if solid) or stipe (if striped)
  • Somehow add the number to the ball in a way that it looks like the same quality as the rest of the ball

Perhaps there's a magic way to take a texture and wrap it around a sphere without any distortion, and then I could just generate textures and stick 'em on the spheres. But as you can guess, I don't know which way to go here.

Thanks for any direction!


Solution

  • If you're looking to tackle it with XNA / MonoGame / ANX, the approach really depends on whether you're using the Reach profile or HighDef profile.

    With the reach profile, I'd suggest:

    1. Creating a RenderTarget
    2. Clear the render target to the colour of the ball
    3. Draw the white stripe(s) on to the render target
    4. Draw the number onto the render target
    5. Create dynamically a (or use an existing) Sphere mesh
    6. Render the sphere mesh using the Basic effect and the rendertarget texture

    With the high profile, it's a case writing a pixel shader that:

    1. takes a "white" texture, a "colour" texture, a colour and a "number" texture
    2. renders the white texture white
    3. renders the colour texture the supplied colour
    4. renders the numbers texture

    (I'd suggest rendering the number texture using a similar technique to the Reach profile example. Rendering text is a pain so may as well take advantage of the inbuilt stuff where possible). There is an re-colouring example provided by the (former) XNA team at http://create.msdn.com