Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 tobikemp   Members   -  Reputation: 104

Like
0Likes
Like

Posted 14 August 2014 - 10:29 AM

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 ® 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
//

    vs_3_0
    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 ® 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
//

    ps_3_0
    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
    endif
    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
    else
      mad_sat r2.x, v0.w, c0.x, c0.y
      add r1.w, -r2.x, c1.w
    endif
    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;
        ALPHABLENDENABLE = FALSE;
        //CLIPPING = FALSE;

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

 



Sponsor:

#2 MJP   Moderators   -  Reputation: 11774

Like
1Likes
Like

Posted 14 August 2014 - 12:23 PM

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, 14 August 2014 - 12:25 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS