DX11 Direct2D but generate background from 3D Model

Recommended Posts

timjohnarm    1

So the application itself is 2D and layered but I want to build the background bitmap from a Blender 3D model.

When I make an appeal to Saint Google there seem to be an awful lot of ways of getting to the desired result.

The process I have in mind is to do the following. Please comment on the practicality or otherwise of this approach.

Use a background thread to:

  • Load the model
  • Create a 3D buffer for rendering into
  • Render into the buffer
  • Copy the 3D buffer to a 2D buffer somewhere

The main loop will

  • Blit? copy the 2D background to the backbuffer of the swap chain
  • Overlay the background with various sprites
  • Swap buffers

Which leads to the following questions.

What is the best option for exporting a Blender model for use by DirectX.

Which API should I use to create a 3D buffer for rendering the model into? As it only gets rendered on scene changes, every 10-20 seconds, am I correct in assuming it shouldn't be part of the swap chain? In managing the background buffer is it best to, or must I, use a "dummy" device of some kind?

How do I turn a 3D buffer into a 2D bitmap for load into the 2D swap chain?

What is the best way to set up the 2D buffer  so asto minimise the cost of the copy for every frame by the main loop?

Edited by timjohnarm

Share this post

Link to post
Share on other sites
Endemoniada    430


Does the background move ? I'm not familiar with Direct2D. You can always just go full D3D and render quads for the 2D stuff, it will certainly be very fast.

As for loading models from Blender (or any other program) you'll need a loader. It's not that hard to code an .obj loader yourself, otherwise you can probably find some code. It depends on the format your game engines uses so I would just make it myself if I were you, it basically comes down to parsing a text file (for .obj).

Share this post

Link to post
Share on other sites

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

  • Similar Content

    • By isu diss
       I'm trying to code Rayleigh part of Nishita's model (Display Method of the Sky Color Taking into Account Multiple Scattering). I get black screen no colors. Can anyone find the issue for me?
      #define InnerRadius 6320000 #define OutterRadius 6420000 #define PI 3.141592653 #define Isteps 20 #define Ksteps 10 static float3 RayleighCoeffs = float3(6.55e-6, 1.73e-5, 2.30e-5); RWTexture2D<float4> SkyColors : register (u0); cbuffer CSCONSTANTBUF : register( b0 ) { float fHeight; float3 vSunDir; } float Density(float Height) { return exp(-Height/8340); } float RaySphereIntersection(float3 RayOrigin, float3 RayDirection, float3 SphereOrigin, float Radius) { float t1, t0; float3 L = SphereOrigin - RayOrigin; float tCA = dot(L, RayDirection); if (tCA < 0) return -1; float lenL = length(L); float D2 = (lenL*lenL) - (tCA*tCA); float Radius2 = (Radius*Radius); if (D2<=Radius2) { float tHC = sqrt(Radius2 - D2); t0 = tCA-tHC; t1 = tCA+tHC; } else return -1; return t1; } float RayleighPhaseFunction(float cosTheta) { return ((3/(16*PI))*(1+cosTheta*cosTheta)); } float OpticalDepth(float3 StartPosition, float3 EndPosition) { float3 Direction = normalize(EndPosition - StartPosition); float RayLength = RaySphereIntersection(StartPosition, Direction, float3(0, 0, 0), OutterRadius); float SampleLength = RayLength / Isteps; float3 tmpPos = StartPosition + 0.5 * SampleLength * Direction; float tmp; for (int i=0; i<Isteps; i++) { tmp += Density(length(tmpPos)-InnerRadius); tmpPos += SampleLength * Direction; } return tmp*SampleLength; } static float fExposure = -2; float3 HDR( float3 LDR) { return 1.0f - exp( fExposure * LDR ); } [numthreads(32, 32, 1)] //disptach 8, 8, 1 it's 256 by 256 image void ComputeSky(uint3 DTID : SV_DispatchThreadID) { float X = ((2 * DTID.x) / 255) - 1; float Y = 1 - ((2 * DTID.y) / 255); float r = sqrt(((X*X)+(Y*Y))); float Theta = r * (PI); float Phi = atan2(Y, X); static float3 Eye = float3(0, 10, 0); float ViewOD = 0, SunOD = 0, tmpDensity = 0; float3 Attenuation = 0, tmp = 0, Irgb = 0; //if (r<=1) { float3 ViewDir = normalize(float3(sin(Theta)*cos(Phi), cos(Theta),sin(Theta)*sin(Phi) )); float ViewRayLength = RaySphereIntersection(Eye, ViewDir, float3(0, 0, 0), OutterRadius); float SampleLength = ViewRayLength / Ksteps; //vSunDir = normalize(vSunDir); float cosTheta = dot(normalize(vSunDir), ViewDir); float3 tmpPos = Eye + 0.5 * SampleLength * ViewDir; for(int k=0; k<Ksteps; k++) { float SunRayLength = RaySphereIntersection(tmpPos, vSunDir, float3(0, 0, 0), OutterRadius); float3 TopAtmosphere = tmpPos + SunRayLength*vSunDir; ViewOD = OpticalDepth(Eye, tmpPos); SunOD = OpticalDepth(tmpPos, TopAtmosphere); tmpDensity = Density(length(tmpPos)-InnerRadius); Attenuation = exp(-RayleighCoeffs*(ViewOD+SunOD)); tmp += tmpDensity*Attenuation; tmpPos += SampleLength * ViewDir; } Irgb = RayleighCoeffs*RayleighPhaseFunction(cosTheta)*tmp*SampleLength; SkyColors[DTID.xy] = float4(Irgb, 1); } }  
    • By ben berizovsky
      Hello there, I am new to the forum and in game development in general!
      I am currently building a simulator for some game, and I am having a few problems already, and I am using the libgdx framework.
      I have an isometric map drawn, where each tile is a spot that only one entity can be at. 
      An entity can either move left, right or just forward in a straight line.
      Now this is what it looks at the moment:

      As you can see, my ship entity is located at 1,1.
      I want to start with adding a function that moves the ship in a straight line, so I need to move this ship to 1,2.
      So I have a Vector2 that represents the ship's position, I made a dummy one in the local class where it paints entities, and the map and it's set to isometric coordinates of 1,1:
      r = new TextureRegion(texture, location.getX(), location.getY(), location.getWidth(), location.getHeight()); local = new Vector2(getIsometricX(1,1, r), getIsometricY(1,1, r));  
      "r" is my texture region, which is my sprite image off the spritesheet.
      Now I have set a target position to 1,2:
      target = new Vector2(getIsometricX(1,2, r), getIsometricY(1,2, r));  
      So now my question is, how can I make that ship move to the target position? If i add 1 to x and y every tick, it will just move too much to the right.
      This is how I paint everything:
      @Override public void render() { batch.setProjectionMatrix(camera.combined); batch.begin(); // Render the map renderSeaBattle(); // Render ships renderEntities(); batch.end(); }  
      And the map painting:
      private void renderSeaBattle() { // The map tiles GameTile[][] tiles = map.getTiles(); for (int i = 0; i < tiles.length; i++) { for(int j = 0; j < tiles[i].length; j++) { GameTile tile = tiles[i][j]; Texture texture = tile.getTexture(); int x = (i * GameTile.TILE_WIDTH / 2) - (j * GameTile.TILE_WIDTH / 2) -texture.getWidth() / 2; int y = (i * GameTile.TILE_HEIGHT / 2) + (j * GameTile.TILE_HEIGHT / 2) -texture.getHeight() / 2; batch.draw(texture, x, y); } } }  
      And the entities:
      private void renderEntities() { batch.draw(r, local.x + location.getOffsetx(), local.y + location.getOffsety()); } location is an instance that contains the offset position for that specific sprite, because not all sprites are the same size, so to center it on the tile, each one has set offsetX and Y.
      And this is my coordinate conversion methods:
      public int getIsometricX(int x, int y, TextureRegion region) { return (x * GameTile.TILE_WIDTH / 2) - (y * GameTile.TILE_WIDTH / 2) - (region.getRegionWidth() / 2); } public int getIsometricY(int x, int y, TextureRegion region) { return (x * GameTile.TILE_HEIGHT / 2) + (y * GameTile.TILE_HEIGHT / 2) - (region.getRegionHeight() / 2); }  
      After I do the straight line, how can I create left/right movements in curves?
    • By mark_braga
      What is the value of the vertex_id attribute in a metal shader when using drawPrimitives with indirectBuffer?
      I know it is relative to baseVertex when using normal draw but how does it work with indirect draw arguments?
      It doesn't say anything in the spec so any info on this would really help.
      Thank you.
    • By Kamil Sawejko
      Hi there,

      I am looking for team members. Anything from programmers to concept artists.

      I would like to make a game similar to "Tactics Ogre". It would have an open world where you navigate your character like in any other rpg, and upon encountering a monster a battlefield would be created. Battle would be tactical and turn based.

      The game would be a part of a franchise. My dream is creating an MMORPG, so I thought I will start with a little rpg game which will take place in the same world. If the game is successful, we can expand from there, and hopefully at some point create an MMORPG.

      If you are interested, drop me a message at k.sawejko@gmail.com

    • By ilovegames
      Wind Of Fear is a game where we have to kill different kinds of waves of monsters packing weapons. The main goal is to survive the waves and pump up your own weapons. There is a store where you will buy new weapons, scattered crystals that restore your life are also on the map!

      WASD - Walking
      Shift - Running
      Mouse1 - Attack
      Space - Jump
      ScrolDown - weapon change
      T - Deceleration of time
      G - Bleed your weapon
      Esc - Exit, pause
      Download http://falcoware.com/WindOfFear.php

  • Popular Now