• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Is it possible to load asm/FX-Shaders in DirectX11

1 post in this topic

Hello everyone,


I´m trying to switch form SharpDx9 to SharpDx11. And now I have no idea how to load my old shaders which are a mix of asm and hlsl shaders.

Here is one of the shaders. the assembler parts are extracted from a game. the hlsl-variables are created by me. 


Best regards




texture Tex1 : register( ps, t[0] );
texture Tex2 : register( ps, t[2] );
texture Tex3 : register( ps, t[4] );
texture Tex1Bump : register( ps, t[1] );
texture Tex2Bump : register( ps, t[3] );
texture Tex3Bump : register( ps, t[5] );

texture TexDither : register( ps, t[6] );
texture TexShadowMap : register( ps, t[7] );

sampler2D DiffuseTex1 : register(ps, s[0]) = sampler_state { Texture = (Tex1); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex1 : register(ps, s[1]) = sampler_state { Texture = (Tex1Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D DiffuseTex2 : register(ps, s[2]) = sampler_state { Texture = (Tex2); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex2 : register(ps, s[3]) = sampler_state { Texture = (Tex2Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D DiffuseTex3 : register(ps, s[4]) = sampler_state { Texture = (Tex3); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};
sampler2D BumpTex3 : register(ps, s[5]) = sampler_state { Texture = (Tex3Bump); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

sampler2D ShadowMap : register(ps, s[7]) = sampler_state { Texture = (TexShadowMap); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

sampler2D DitherTex : register(ps, s[15]) = sampler_state { Texture = (TexDither); ADDRESSU = WRAP; ADDRESSV = WRAP; ADDRESSW = WRAP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR;};

bool DitherFlag: register( ps, b[4] ) = false;
bool ShadowsFlag: register( ps, b[1] ) = true;

float4 AmbNDiff: register( ps, c[23] ) = float4(1.5,0.002,1.25,0.0);
float3 DitherClipParams: register( ps, c[21] ) = float3(-0.001,1.000,5.656);
float4 DitherTexParams: register( ps, c[20] ) = float4(0.016,0.016,0.008,0.008);
float4 Exposure: register( ps, c[24] ) = float4(0.022,0.98,-0.150,0.000);
float3 FogColor: register( ps, c[29] ) = float3(0.405,0.89,0.720);
float3 LightVec: register( ps, c[14] ) = float3(-0.784,0.5588,-0.196);
float4 SelCascade: register( ps, c[35] ) = float4(0.007,-0.013,0.5,1.0);
float4x3 ShadowMats[4]: register( ps, c[36] );
//    float4(0.002,-0.001,-0.000,0.289),
//    float4(-0.001,-0.002,-0.002,0.487),
//    float4(0.000,-0.000,-0.000,0.989)};
float3x3 ShadowNormalMat: register( ps, c[17] );
float4 ShadowNormalOffset: register( ps, c[22] )= float4(0.318,1.260,5.027,27.862);
float3 SunColor: register( ps, c[15] ) = float3(3.61,3.24,2.560);

// VertexShader parameters

float4 AmbLevel : register( vs, c[30] ) = float4(0.2013,0.450,0.450,10.500);
float3 CameraPos : register( vs, c[32] );
float4 RangeFog : register( vs, c[31] ) = float4(2.718,0.0,0.0,0.000015);
float4x4 ShadowMtx : register( vs, c[24] );
float4 TerrainAmbient : register( vs, c[48] ) = float4(1.00,1.00,1.0,0.0);
float3x2 TexMat1 : register( vs, c[34] ) = float3x2(1.0,0,0,0,1,0);
float3x2 TexMat2 : register( vs, c[36] );
float4 TexUVMod1 : register( vs, c[38] ) = float4(0.0,0.0,1.0,1.0);
float4 TexUVMod2 : register( vs, c[39] ) = float4(0.0,0.0,1.0,1.0);
float4 WorldOffset : register( vs, c[33] )= float4(0.0,0,0,0.0);
float4x3 WorldViewMtx : register( vs, c[9] );
float4x4 WorldViewProjMtx : register( vs, c[20] );

// Vertex Shader

//sampler2D Tex0 : register(s0); 

VertexShader VS_Main = asm
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
// Parameters:
//   float4 AmbLevel;
//   float3 CameraPos;
//   float4 RangeFog;
//   float4x4 ShadowMtx;
//   float4 TerrainAmbient;
//   float3x2 TexMat1;
//   float3x2 TexMat2;
//   float4 TexUVMod1;
//   float4 TexUVMod2;
//   float4 WorldOffset;
//   float4x3 WorldViewMtx;
//   float4x4 WorldViewProjMtx;
// Registers:
//   Name             Reg   Size
//   ---------------- ----- ----
//   WorldViewMtx     c9       3
//   WorldViewProjMtx c20      4
//   ShadowMtx        c24      3
//   AmbLevel         c30      1
//   RangeFog         c31      1
//   CameraPos        c32      1
//   WorldOffset      c33      1
//   TexMat1          c34      2
//   TexMat2          c36      2
//   TexUVMod1        c38      1
//   TexUVMod2        c39      1
//   TerrainAmbient   c48      1

    def c0, 2, -1, -1.44269502, -0
    dcl_position v0
    dcl_normal v1
    dcl_texcoord v2
    dcl_texcoord1 v3
    dcl_color v4
    dcl_color1 v5
    dcl_position o0
    dcl_color o1
    dcl_texcoord8 o2
    dcl_texcoord o3.xyz
    dcl_texcoord1 o4
    dcl_texcoord2 o5
    dcl_texcoord4 o6
    dcl_texcoord6 o7
    dcl_texcoord7 o8.xyz
    mad r0.xyz, v1, c0.x, c0.y
    dp3 r0.w, r0, r0
    rsq r0.w, r0.w
    mul o3.xyz, r0.w, r0
    add r0, c33, v0
    dp4 o0.x, r0, c20
    dp4 o0.y, r0, c21
    dp4 o0.z, r0, c22
    dp4 o0.w, r0, c23
    dp4 o7.w, r0, c11
    add r1.xyz, r0, -c32
    mul r1.xyz, r1, c31.w
    dp3 r0.w, r1, r1
    mul r0.w, r0.w, c0.z
    exp o4.w, r0.w
    mul r1.xyz, v5, v5
    mul r1.xyz, r1, c30
    mov r1.w, v5.w
    add o2, r1, c48
    mad r1.xyz, v2.xyxw, -c0.yyww, -c0.wwyw
    dp3 r2.x, r1, c34
    dp3 r2.y, r1, c35
    mad o5.zw, r2.xyxy, c38.z, c38.xyxy
    mov o5.xy, r2
    mad r1.xyz, v3.xyxw, -c0.yyww, -c0.wwyw
    dp3 r2.x, r1, c36
    dp3 r2.y, r1, c37
    mad o6.zw, r2.xyxy, c39.z, c39.xyxy
    mov o6.xy, r2
    add o4.xyz, -r0, c32
    mad r0, r0.xyzx, -c0.yyyw, -c0.wwwy
    dp4 o8.x, r0, c24
    dp4 o8.y, r0, c25
    dp4 o8.z, r0, c26
    mov o7.xyz, r0
    mov o1, v4

// approximately 36 instruction slots used


// Pixel Shader
PixelShader PS_Main = asm
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
// Parameters:
//   sampler2D DiffuseTex1;
//   float3 DitherClipParams;
//   bool DitherFlag;
//   sampler2D DitherTex;
//   float4 DitherTexParams;
//   float4 Exposure;
//   float3 FogColor;
//   float3 LightVec;
//   float4 SelCascade;
//   sampler2D ShadowMap;
//   float4x3 ShadowMats[4];
//   float3x3 ShadowNormalMat;
//   float4 ShadowNormalOffset;
//   bool ShadowsFlag;
//   float3 SunColor;
// Registers:
//   Name               Reg   Size
//   ------------------ ----- ----
//   ShadowsFlag        b1       1
//   DitherFlag         b4       1
//   LightVec           c14      1
//   SunColor           c15      1
//   ShadowNormalMat    c17      3
//   DitherTexParams    c20      1
//   DitherClipParams   c21      1
//   ShadowNormalOffset c22      1
//   Exposure           c23      1
//   FogColor           c29      1
//   SelCascade         c35      1
//   ShadowMats         c36     12
//   DiffuseTex1        s0       1
//   ShadowMap          s7       1
//   DitherTex          s15      1

    def c0, 8, -3.5, 0, 3
    def c1, 0.308600008, 0.609399974, 0.0820000023, 1
    def c2, 1, 2, 3, 4
    def c3, 1, 0, -1, -2
    def c4, 0.5, 0, 0, 0
    dcl_color v0.w
    dcl_texcoord8 v1
    dcl_texcoord v2.xyz
    dcl_texcoord1 v3
    dcl_texcoord2 v4.xy
    dcl_texcoord7 v5.xyz
    dcl vPos.xy
    dcl_2d s0
    dcl_2d s7
    dcl_2d s15
    dp3 r0.x, v3, v3
    rsq r0.x, r0.x
    if b4
      rcp r0.y, r0.x
      mad r0.zw, vPos.xyxy, c20.xyxy, c20
      texld r1, r0.zwzw, s15
      mul r0.z, r1.w, c21.y
      mad r0.y, r0.y, c21.x, r0.z
      add r1, r0.y, c21.z
      texkill r1
    nrm r1.xyz, v2
    dp3_sat r0.y, r1, c14
    add r0.z, -r0.y, c1.w
    mul r0.w, r0.z, r0.z
    mad r0.z, r0.z, -r0.w, c1.w
    mul r0.y, r0.y, r0.z
    mul r0.y, r0.y, c4.x
    mul_pp r0.xzw, r0.x, v3.xyyz
    dp3_pp r1.w, r1, r0.xzww
    add r1.w, r1.w, r1.w
    mad_pp r0.xzw, r1.w, r1.xyyz, -r0
    if b1
      mad r1.w, v5.z, c35.x, c35.y
      log r1.w, r1.w
      mad r1.w, r1.w, c35.z, c35.w
      max r2.x, r1.w, c0.z
      min r1.w, r2.x, c0.w
      frc r2.x, r1.w
      add r2.x, r1.w, -r2.x
      add r3, r1.w, c3
      add r4, -r1.w, c2
      min r5, r3, r4
      max r3, r5, c0.z
      dp4 r1.w, r3, c22
      dp3 r3.x, r1, c17
      dp3 r3.y, r1, c18
      dp3 r3.z, r1, c19
      mad r1.xyz, r3, r1.w, v5
      add r2.y, r2.x, -c2.y
      mov r1.w, c1.w
      mov r3, c38
      cmp r3, -r2_abs.x, r3, c41
      mov r4, c44
      cmp r4, -r2.y, r4, c47
      cmp r3, r2.y, r4, r3
      dp4 r3.z, r1, r3
      mov r4, c36
      cmp r4, -r2_abs.x, r4, c39
      mov r5, c42
      cmp r5, -r2.y, r5, c45
      cmp r4, r2.y, r5, r4
      dp4 r3.x, r1, r4
      mov r4, c37
      cmp r4, -r2_abs.x, r4, c40
      mov r5, c43
      cmp r5, -r2.y, r5, c46
      cmp r2, r2.y, r5, r4
      dp4 r3.y, r1, r2
      mov r3.w, c1.w
      texldp r1, r3, s7
      mov r1.w, r1.x
      mad_sat r2.x, v0.w, c0.x, c0.y
      add r1.w, -r2.x, c1.w
    dp3_sat_pp r0.x, r0.xzww, c14
    mul r0.x, r0.x, r0.x
    mul r0.z, r0.x, r0.x
    dp2add_pp r0.x, r0.x, r0.z, r0.y
    mul_pp r1.xyz, r1.w, c15
    mad_pp r0, r0.x, r1, v1
    texld r1, v4, s0
    dp3 r2.x, r1, c1
    lrp r3.xyz, c23.w, r2.x, r1
    mad r0.xyz, r3, r0, -c29
    mad_pp oC0.xyz, v3.w, r0, c29
    mul_pp r0.x, r0.w, r1.w
    mov_pp oC0.w, r0.x

// approximately 86 instruction slots used (3 texture, 83 arithmetic)


// Technique Section for Effect Workspace.Effect Group 2.Textured
technique Textured
    pass Pass_0
        Texture[0] = <Tex1>;
        Texture[2] = <Tex2>;
        Texture[4] = <Tex3>;
        Texture[1] = <Tex1Bump>;
        Texture[3] = <Tex2Bump>;
        Texture[5] = <Tex3Bump>;
        Texture[6] = <TexDither>;
        Texture[7] = <TexShadowMap>;

        Sampler[0] = <DiffuseTex1>;
        Sampler[1] = <BumpTex1>;
        Sampler[2] = <DiffuseTex2>;
        Sampler[3] = <BumpTex2>;
        Sampler[4] = <DiffuseTex3>;
        Sampler[5] = <BumpTex3>;
        Sampler[7] = <ShadowMap>;

        //PixelShaderBool[1] = <ShadowsFlag>;
        //PixelShaderBool[4] = <DitherFlag>;

        PixelShaderConstant[14] = <LightVec>;
        PixelShaderConstant[15] = <SunColor>;
        PixelShaderConstant[17] = <ShadowNormalMat>;
        PixelShaderConstant[20] = <DitherTexParams>;
        PixelShaderConstant[21] = <DitherClipParams>;
        PixelShaderConstant[22] = <ShadowNormalOffset>;
        PixelShaderConstant[23] = <AmbNDiff>;
        PixelShaderConstant[24] = <Exposure>;
        PixelShaderConstant[29] = <FogColor>;
        PixelShaderConstant[35] = <SelCascade>;
        PixelShaderConstant[36] = <ShadowMats>;

        VertexShaderConstant[9]  = <WorldViewMtx>;
        VertexShaderConstant[20]  = <WorldViewProjMtx>;
        VertexShaderConstant[24]  = <ShadowMtx>;
        VertexShaderConstant[30]  = <AmbLevel>;
        VertexShaderConstant[31]  = <RangeFog>;
        VertexShaderConstant[32]  = <CameraPos>;
        VertexShaderConstant[33]  = <WorldOffset>;
        VertexShaderConstant[34]  = <TexMat1>;
        VertexShaderConstant[36]  = <TexMat2>;
        VertexShaderConstant[38]  = <TexUVMod1>;
        VertexShaderConstant[39]  = <TexUVMod2>;
        VertexShaderConstant[48]  = <TerrainAmbient>;

        //FILLMODE = SOLID;
        //CULLMODE = NONE;
        //CLIPPING = FALSE;

        VertexShader = (VS_Main);
        PixelShader = (PS_Main);



Share this post

Link to post
Share on other sites

DX11 only supports loading bytecode that was compiled by the HLSL compiler. There is no longer an assembler, so your only option is to author in HLSL. HLSL also changed quite a bit since DX9, so even your shader code will likely need to be overhauled to make it compile and work.


Also, this forum supports "code" tags for posting code if you'd like to use that in the future.

Edited by MJP

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
Sign in to follow this  
Followers 0

  • Similar Content

    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
    • By YixunLiu
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
  • Popular Now