LotusExigeS1

Could someone who is more intelligent than me please convert the below asm code to HLSL. You will have a place in heaven if you do this ..... :O)

Thanks,

Dave

PixelShader =

asm

{

ps_1_1

tex t0

tex t1

// Specular

dp3_sat r1, t1_bx2, v1_bx2 // r1 = (2.0 * (NormalMap - 0.5)) * (2.0 * (vSpecular - 0.5))

dp3_sat r0, t1_bx2, v0_bx2

mul_sat r1, r1, r0

mul_sat r1, r1, r1

mul_sat r1, r1, c2

// Diffuse + Ambient

dp3_sat r0, t1, v0_bx2

mad_sat r0, r0, c1, c0

mad_sat r0, r0, t0, r1

};

PixelShaderConstant1[0] = (cAmbient);

PixelShaderConstant1[1] = (cDiffuse);

PixelShaderConstant1[2] = (cSpecular);



Re: XNA Framework Port asm to HLSL help please

Malmer

What exactly is it that you want to achive Might be easier just to write what you need instead of decipher shader asm.



Re: XNA Framework Port asm to HLSL help please

LotusExigeS1

the asm shader above works perfectly for me. But I want it in HLSL so that I can understand it and add a couple of things ...

Thanks.





Re: XNA Framework Port asm to HLSL help please

Malmer

Yes, but it is usually easier to write a shader given what is desired rather than machine code.



Re: XNA Framework Port asm to HLSL help please

LotusExigeS1

I have managed to get a vertex buffer working for animating a skinned mesh. the pixel shader above simply adds a diffuse to the skinned mesh. It sounds easy to replicate (and it should be), be its really tricky to get it working right (due to the complex bones and weighting that transform the vertices in the vs)... th ps above works for me and I cant replicate its results through HLSL ...

Thanks.





Re: XNA Framework Port asm to HLSL help please

neogir

Your asm ps shader represents a very common lightning model, nothing more.
Here it is:

extern float3 cAmbient : AMBIENT;
extern float3 cDiffuse : DIFFUSE;
extern float3 cSpecular: SPECULAR;

struct PSIn
{
      float4 color : COLOR;         // Color after vertex shader has executed
      float3 normal : TEXCOORD0;    // Vertex normal after vertex shader
      float3 lightVec : TEXCOORD1;  // The vector from the vertex
                                      // in world space to the light source
     float3 halfwayVec : TEXCOORD2;// The vector halfway between the "lightVec"
                                      // and the vector from the vertex in world  space to the eye
 };

struct PSOut
{
     float4 color : COLOR;
};


SuperPixelShader (PSin psIn)
{
       float3 diffuse, specular;
       PSOut psOut = (PSOut)0;

      psIn.normal = normalize(psIn.normal);
      psIn.lightVec = normalize(psIn.lightVec);
      psIn.halfwayVec = normalize(psIn.halfwayVec);

       specular = pow(max(dot(psIn.normal, psIn.halfwayVec), 0), 2) * cSpecular;
      diffuse = max(dot(psIn.normal, psIn.lightVec), 0) * cDiffuse;
      psOut.color.rgb = (diffuse * psIn.color.rgb) + (specular * psIn.color.rgb)  + (cAmbient * psIn.color.rgb);
      return psOut;
}

technique SuperlLighting
{
 
      pass P0
      {
           // Set render states and declare vertex shader here
          PixelShader = compile ps_2_0 SuperPixelShader; // Use pixel shader 2.0 -> v1.1 does not support max op
      }
}


IMHO no one is writing vertex and pixel shaders in different languages (am I wrong here ) to avoid  some nasty conjugation problem.  I wonder what does the vertex shader look like





Re: XNA Framework Port asm to HLSL help please

LotusExigeS1

I have been trying to use the code found here -

http://www.flipcode.com/articles/article_dx9skinmeshmod.shtml

if you go to the updated link at the bottom, the sample includes a normal mapped version.

Thanks for your port of the code, I have unfortunately tried something similiar and it isnt working for me.

The end result I require is to be able to position a light with x,y,z and position a model with x,y,z have the model diffused correctly.  This is a walk in the park with hlsl and a standard mesh.  I am currently trying to do this with a skinned mesh and its proving to be a bitch.  Lastly, the sample above uses a light direction only, and I am TOO THICK TO WORK OUT HOW TO CHANGE IT TO A OMNI DIRECTIONAL POINT LIGHT with an x,y,z location ... any ideas would be very much appreciated.

Thanks.

FYI - this is one of the last things I need to complete to get my game done (ish), you can see my progress here -

retro dungeon master style game - www.entombed.co.uk

There is a little movie link at the top of the page, so you can get a feel for it.  This is not an XNA game, but I love XNA and MDX and people seem really helpful on this forum.  I am going to port this to XNA as soon as XNA has all the bits I need.





Re: XNA Framework Port asm to HLSL help please

Jon Watte

I believe you can do the Phong lighting model in 1.1, if you use saturate() instead of max().
You might, however, want to use a normalization cube map.





Re: XNA Framework Port asm to HLSL help please

Malmer

The real tricky thing is that you run out of instructions really fast. A GeForce 3 doesn't have that many to play with. For a phong ps 1.1 I think you have to do it in asm to make sure you get it done in as few instructions as possible.



Re: XNA Framework Port asm to HLSL help please

Jon Watte

You can write HLSL code that compiles to the same number of instructions. I've done it. However, as of the December 2006 DirectX SDK, they no longer target ps_1_1 targets -- you HAVE to use assembly for those shaders. Progress, I guess.