• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By cozzie
      Hi all,
      As a part of the debug drawing system in my engine,  I want to add support for rendering simple text on screen  (aka HUD/ HUD style). From what I've read there are a few options, in short:
      1. Write your own font sprite renderer
      2. Using Direct2D/Directwrite, combine with DX11 rendertarget/ backbuffer
      3. Use an external library, like the directx toolkit etc.
      I want to go for number 2, but articles/ documentation confused me a bit. Some say you need to create a DX10 device, to be able to do this, because it doesn't directly work with the DX11 device.  But other articles tell that this was 'patched' later on and should work now.
      Can someone shed some light on this and ideally provide me an example or article on  how to set this up?
      All input is appreciated.
    • By stale
      I've just started learning about tessellation from Frank Luna's DX11 book. I'm getting some very weird behavior when I try to render a tessellated quad patch if I also render a mesh in the same frame. The tessellated quad patch renders just fine if it's the only thing I'm rendering. This is pictured below:
      However, when I attempt to render the same tessellated quad patch along with the other entities in the scene (which are simple triangle-lists), I get the following error:

      I have no idea why this is happening, and google searches have given me no leads at all. I use the following code to render the tessellated quad patch:
      ID3D11DeviceContext* dc = GetGFXDeviceContext(); dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); dc->IASetInputLayout(ShaderManager::GetInstance()->m_JQuadTess->m_InputLayout); float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f }; // only used with D3D11_BLEND_BLEND_FACTOR dc->RSSetState(m_rasterizerStates[RSWIREFRAME]); dc->OMSetBlendState(m_blendStates[BSNOBLEND], blendFactors, 0xffffffff); dc->OMSetDepthStencilState(m_depthStencilStates[DSDEFAULT], 0); ID3DX11EffectTechnique* activeTech = ShaderManager::GetInstance()->m_JQuadTess->Tech; D3DX11_TECHNIQUE_DESC techDesc; activeTech->GetDesc(&techDesc); for (unsigned int p = 0; p < techDesc.Passes; p++) { TerrainVisual* terrainVisual = (TerrainVisual*)entity->m_VisualComponent; UINT stride = sizeof(TerrainVertex); UINT offset = 0; GetGFXDeviceContext()->IASetVertexBuffers(0, 1, &terrainVisual->m_VB, &stride, &offset); Vector3 eyePos = Vector3(cam->m_position); Matrix rotation = Matrix::CreateFromYawPitchRoll(entity->m_rotationEuler.x, entity->m_rotationEuler.y, entity->m_rotationEuler.z); Matrix model = rotation * Matrix::CreateTranslation(entity->m_position); Matrix view = cam->GetLookAtMatrix(); Matrix MVP = model * view * m_ProjectionMatrix; ShaderManager::GetInstance()->m_JQuadTess->SetEyePosW(eyePos); ShaderManager::GetInstance()->m_JQuadTess->SetWorld(model); ShaderManager::GetInstance()->m_JQuadTess->SetWorldViewProj(MVP); activeTech->GetPassByIndex(p)->Apply(0, GetGFXDeviceContext()); GetGFXDeviceContext()->Draw(4, 0); } dc->RSSetState(0); dc->OMSetBlendState(0, blendFactors, 0xffffffff); dc->OMSetDepthStencilState(0, 0); I draw my scene by looping through the list of entities and calling the associated draw method depending on the entity's "visual type":
      for (unsigned int i = 0; i < scene->GetEntityList()->size(); i++) { Entity* entity = scene->GetEntityList()->at(i); if (entity->m_VisualComponent->m_visualType == VisualType::MESH) DrawMeshEntity(entity, cam, sun, point); else if (entity->m_VisualComponent->m_visualType == VisualType::BILLBOARD) DrawBillboardEntity(entity, cam, sun, point); else if (entity->m_VisualComponent->m_visualType == VisualType::TERRAIN) DrawTerrainEntity(entity, cam); } HR(m_swapChain->Present(0, 0)); Any help/advice would be much appreciated!
    • By KaiserJohan
      Am trying a basebones tessellation shader and getting unexpected result when increasing the tessellation factor. Am rendering a group of quads and trying to apply tessellation to them.
      OutsideTess = (1,1,1,1), InsideTess= (1,1)

      OutsideTess = (1,1,1,1), InsideTess= (2,1)

      I expected 4 triangles in the quad, not two. Any idea of whats wrong?
      struct PatchTess { float mEdgeTess[4] : SV_TessFactor; float mInsideTess[2] : SV_InsideTessFactor; }; struct VertexOut { float4 mWorldPosition : POSITION; float mTessFactor : TESS; }; struct DomainOut { float4 mWorldPosition : SV_POSITION; }; struct HullOut { float4 mWorldPosition : POSITION; }; Hull shader:
      PatchTess PatchHS(InputPatch<VertexOut, 3> inputVertices) { PatchTess patch; patch.mEdgeTess[ 0 ] = 1; patch.mEdgeTess[ 1 ] = 1; patch.mEdgeTess[ 2 ] = 1; patch.mEdgeTess[ 3 ] = 1; patch.mInsideTess[ 0 ] = 2; patch.mInsideTess[ 1 ] = 1; return patch; } [domain("quad")] [partitioning("fractional_odd")] [outputtopology("triangle_ccw")] [outputcontrolpoints(4)] [patchconstantfunc("PatchHS")] [maxtessfactor( 64.0 )] HullOut hull_main(InputPatch<VertexOut, 3> verticeData, uint index : SV_OutputControlPointID) { HullOut ret; ret.mWorldPosition = verticeData[index].mWorldPosition; return ret; }  
      Domain shader:
      [domain("quad")] DomainOut domain_main(PatchTess patchTess, float2 uv : SV_DomainLocation, const OutputPatch<HullOut, 4> quad) { DomainOut ret; const float MipInterval = 20.0f; ret.mWorldPosition.xz = quad[ 0 ].mWorldPosition.xz * ( 1.0f - uv.x ) * ( 1.0f - uv.y ) + quad[ 1 ].mWorldPosition.xz * uv.x * ( 1.0f - uv.y ) + quad[ 2 ].mWorldPosition.xz * ( 1.0f - uv.x ) * uv.y + quad[ 3 ].mWorldPosition.xz * uv.x * uv.y ; ret.mWorldPosition.y = quad[ 0 ].mWorldPosition.y; ret.mWorldPosition.w = 1; ret.mWorldPosition = mul( gFrameViewProj, ret.mWorldPosition ); return ret; }  
      Any ideas what could be wrong with these shaders?
    • By simco50
      I've stumbled upon Urho3D engine and found that it has a really nice and easy to read code structure.
      I think the graphics abstraction looks really interesting and I like the idea of how it defers pipeline state changes until just before the draw call to resolve redundant state changes.
      This is done by saving the state changes (blendEnabled/SRV changes/RTV changes) in member variables and just before the draw, apply the actual state changes using the graphics context.
      It looks something like this (pseudo):
      void PrepareDraw() { if(renderTargetsDirty) { pD3D11DeviceContext->OMSetRenderTarget(mCurrentRenderTargets); renderTargetsDirty = false } if(texturesDirty) { pD3D11DeviceContext->PSSetShaderResourceView(..., mCurrentSRVs); texturesDirty = false } .... //Some more state changes } This all looked like a great design at first but I've found that there is one big issue with this which I don't really understand how it is solved in their case and how I would tackle it.
      I'll explain it by example, imagine I have two rendertargets: my backbuffer RT and an offscreen RT.
      Say I want to render my backbuffer to the offscreen RT and then back to the backbuffer (Just for the sake of the example).
      You would do something like this:
      //Render to the offscreen RT pGraphics->SetRenderTarget(pOffscreenRT->GetRTV()); pGraphics->SetTexture(diffuseSlot, pDefaultRT->GetSRV()) pGraphics->DrawQuad() pGraphics->SetTexture(diffuseSlot, nullptr); //Remove the default RT from input //Render to the default (screen) RT pGraphics->SetRenderTarget(nullptr); //Default RT pGraphics->SetTexture(diffuseSlot, pOffscreenRT->GetSRV()) pGraphics->DrawQuad(); The problem here is that the second time the application loop comes around, the offscreen rendertarget is still bound as input ShaderResourceView when it gets set as a RenderTargetView because in Urho3D, the state of the RenderTargetView will always be changed before the ShaderResourceViews (see top code snippet) even when I set the SRV to nullptr before using it as a RTV like above causing errors because a resource can't be bound to both input and rendertarget.
      What is usually the solution to this?
    • By MehdiUBP
      I wrote a MatCap shader following this idea:
      Given the image representing the texture, we compute the sample point by taking the dot product of the vertex normal and the camera position and remapping this to [0,1].
      This seems to work well when I look straight at an object with this shader. However, in cases where the camera points slightly on the side, I can see the texture stretch a lot.
      Could anyone give me a hint as how to get a nice matcap shader ?
      Here's what I wrote:
      Shader "Unlit/Matcap"
              _MainTex ("Texture", 2D) = "white" {}
              Tags { "RenderType"="Opaque" }
              LOD 100
                  #pragma vertex vert
                  #pragma fragment frag
                  // make fog work
                  #include "UnityCG.cginc"
                  struct appdata
                      float4 vertex : POSITION;
                      float3 normal : NORMAL;
                  struct v2f
                      float2 worldNormal : TEXCOORD0;
                      float4 vertex : SV_POSITION;
                  sampler2D _MainTex;            
                  v2f vert (appdata v)
                      v2f o;
                      o.vertex = UnityObjectToClipPos(v.vertex);
                      o.worldNormal = mul((float3x3)UNITY_MATRIX_V, UnityObjectToWorldNormal(v.normal)).xy*0.3 + 0.5;  //UnityObjectToClipPos(v.normal)*0.5 + 0.5;
                      return o;
                  fixed4 frag (v2f i) : SV_Target
                      // sample the texture
                      fixed4 col = tex2D(_MainTex, i.worldNormal);
                      // apply fog
                      return col;
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 porting dx9 to dx10 or later - how hard?

This topic is 423 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

porting dx9 to dx10 or later - how hard?


dx10 will get me real instancing for grass - and texture arrays. dx11 will get me things like NVIDIA turf effects.


everything i'm finding online about rendering grass is dx10 or newer.


FVF gets replaced by....   i've already done some, but i forget the name!


and i'd have to supply my own basic shaders? right?


anything else really major?  minor variations in the matrix declarations as i recall.


i may have to bite the bullet and step up to a newer version of DX. i hate to have to do so, so late in the project, but you have to break a few eggs to make a real mayonnaise.

Edited by Norman Barrows

Share this post

Link to post
Share on other sites

dx9 to 11 is not really that hard, and forget dx10, you can use dx11 with feature level from 9 to 11. The most tricky thing will be the constant buffer management and update that replace the old constant register array. Everything is shader on dx11, no more fixed pipeline, but it is usually quite simple to patch that with a few handy shaders. 


For your question about matrices, with shaders, everything is up to you, left, right, direct, indirect, row major or column major, it is all about what flavor you prefer :)

Edited by galop1n

Share this post

Link to post
Share on other sites

If you are still using the fixed function-pipeline, then maybe before upgrading to DX10+, you should probably start by using shaders. Removing the FFP might prove to be a huge project in and off itself, and if you combine it with changing the entire API surrounding it... I'd just break it off, if you first port your DX9-game to use shaders everywhere, upgrading to DX11 is a lot easier. There are some things that are still different that have been mentioned, but nothing quite as huge as FFP => Shaders.

Share this post

Link to post
Share on other sites
I'm currently going from 9 to 11 and it's doable. My advice is to learn dx11 separately, small projects, iterate, iterate more and then update (or start from scratch, which I did) your codebase.

Share this post

Link to post
Share on other sites
I would actually recommend porting your game to "modern D3D9c" first, and then porting that to D3D11.


by that you mean vertex declarations instead of fvf, and shaders. right?  and no d3dx dependencies? i think all i use out of d3dx are the texture and mesh loading code.  - and the skinned mesh api. but i have the skinned mesh api as stand alone source code - extracted from tiny.cpp, multi_anim.cpp and dxut.cpp. but wait- that doesn't include the controller api code in d3dx9.lib!  : (


i guess turn off d3dx9.lib and see what fails to link? that will instantly tell me exactly which d3dx routines i use - and must replace.


what about basic shaders? example code is readily available? aniso mip map w/ gourard, phong, alpha test or blend, and some two stage tex blending? i've had to do much of  that stuff in software in the past, i'd hate to have to look it all up again.


there's one more thing i can try...  


there is some sort of pseudo instancing possible in dx9 using indexed buffers in a special way. i suppose i ought to give it a shot before going in the dx10-11 direction just for instancing grass.  


or maybe lookup both that and what would have to change in dx9, and figure out whats the best option.


my biggest fear is that i'd end up spending weeks or months writing shaders. although i've done similar coding in the past, and am pretty comfortable with it.  


that's also another concern, i may come to like shader coding too much, causing delays on work on the game. its been a long time since i could just get a long pointer to vidram and "party on the bitmap". going to shaders would give me that kind of power again - intoxicating at the very least. my problem is i'm trying to build games, but i also enjoy low level graphics programming. but i only need low level graphics code as required by the game. anything more is technically a waste of time. shader coding may be distractingly fun for me.

Edited by Norman Barrows

Share this post

Link to post
Share on other sites

I have just made this transition. One thing to note is that in D3D11 there is no longer any functionality provided for the loading of mesh .x files as there is in D3D9. So if you are using such files then you will probably have to write your own mesh exporter/importer.


There is also no longer any built in support for loading .tga files or .dds files. And .bmp files won't load the alpha.


It was worth it to move to D3D11 because overall it runs a lot faster, at least for me. A good thing with D3D11 is that you can sample the depth buffer directly, so when doing deferred rendering there is no need to store a separate buffer for that.


I started out with following the tutorials on this site:


Edited by CarlML

Share this post

Link to post
Share on other sites

A good thing with D3D11 is that you can sample the depth buffer directly, so when doing deferred rendering there is no need to store a separate buffer for that.
 It's a bit late for you now, but you can do that in D3D9 as long as the user has a D3D10 capable GPU.

See INTZ here: http://aras-p.info/texts/D3D9GPUHacks.html


RAWZ/DF16/DF24 also worked on a handful of particular D3D9-era GPU's (e.g. RAWZ was GeForce 7 only, maybe?), but INTZ works on all D3D10 GPUs.

Share this post

Link to post
Share on other sites

well i read the dx9 docs about shaders and effects and HLSL yesterday.


set stream, set constants, set shaders (pre-compileld, already loaded), DIP.  that seems to be what it boils down to.


i use d3dx meshes for loading, but copy them into a vb and ib, then release the d3dxmesh. so i have buffers ready to go already.  


i think the skinned mesh code in Caveman 3.0 already does this, via simple shaders and a fx file.


i'm not really doing a lot of fancy special effects, animated vegetation, alpha blended flames and smoke.


depth of field seems to be the only post processing effect that's appropriate for a scene as seen by the human eye as opposed to a camera lens.  IE the human eye doesn't have lens flare, etc. corona effects, but that's a little different. the problem with DOF is - how do you let the player control the focus distance? in real life its automatic, whatever you "look at", your brain automatically adjusts the eye muscles to focus the lens at that range. rolling the middle mouse wheel is all i can think of.


Snow and three days of lows of 15F ( -9C ) have come to the Washington DC area. In-between dealing with that - getting into the sample code is the next thing on the todo list for today / tomorrow.


It also looks like i can keep the game mostly fixed function, and just use shaders where and as needed, the way i do now for skinned meshes. in fact i've already figured out what you have to save and restore when switching from fixed function to shaders and back again.  I did that when I got skinned meshes working.





' draws a caveperson using the specified textures and animation
fn v draw_skinmesh_caveman_nohair i sex i bodT i eyeT i clothT i ani i ctrl double dt D3DXMATRIX *mWorld i topT i cloakT i braT
' sex: 0=male 1=female
' bodT is body mesh texture ID
' eyeT is eye texture ID
' clothT is clothing texture ID
' ani is which ani should be playing
' ctrl is the index of the character`s controller
i a
' a is the skinned_mesh_pool index of the body mesh
= a controller_pool[ctrl].mesh_index
' 1. set textures in the skinned mesh pool
= skinned_mesh_pool[a].body->texID bodT
= skinned_mesh_pool[a].loincloth->texID clothT
== sex 1
    = skinned_mesh_pool[a].bra->texID braT
= skinned_mesh_pool[a].top->texID topT
= skinned_mesh_pool[a].cloak->texID cloakT
' 2. set animation
c controller_pool_setani ctrl ani
' 3. draw instance ( controllerID, dt, mWorld )
c draw_skinned_mesh_instance ctrl dt mWorld
' set z3d state manager current mesh to none...
= Zcurrentmesh -1
' reset FVF back to z3d FVF...
c Zd3d_device_ptr->SetFVF ZFVF
' 4. draw eyes
c draw_eyeballs2 a eyeT



As you can see, the FVF is all you really need to restore.  I set the "current mesh" to NONE just to be safe.


apparently set_FVF and set_shader are the two calls that actually do the switch from fixed function to porgramnmable pipeline and back. 


so it could be as simple as:

set stream

set shaders

set constants

DIP     // draw animated grass

set FVF     // back to normal operating mode for the game's "graphics engine".


And that means i can use d3dx9 AND shaders!    have my cake AND eat it too!  Something which is definitely not against my religion!   <g>.


I should know in a day or two.


time to hit the books! <g>.


never stop learning.


 and you gotta break a few eggs to make a real mayonnaise

Edited by Norman Barrows

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement