Help compile pixel shader from fragments right !

I wrote fragment:


//
texture Normals;
textureCUBE CubeMap;
sampler NormalSampler : register(s0);
samplerCUBE s_CUBE : register(s3);      // s_CUBE must use sampler register s3 
void someFunc (float2 fNormalTex : TEXCOORD0,float4 fSpecTex[3] : TEXCOORD1, out float4 fColor : COLOR)
{
float4 fNormCol = tex2D(NormalSampler, fNormalTex);
float3 norm;
norm.x = dot ( fSpecTex[0].xyz, fNormCol.xyz * 2 - 1 );
norm.y = dot ( fSpecTex[1].xyz, fNormCol.xyz * 2 - 1 );
norm.z = dot ( fSpecTex[2].xyz, fNormCol.xyz * 2 - 1 );
float3 EyeRay;
EyeRay.x = fSpecTex[0].w;
EyeRay.y = fSpecTex[1].w;
EyeRay.z = fSpecTex[2].w;
float3 NewUVW = 2 * dot(EyeRay.xyz, norm.xyz) * norm.xyz - EyeRay.xyz * dot(norm.xyz, norm.xyz);
fColor = texCUBE(s_CUBE, NewUVW); 
} 
pixelfragment someFrag = compile_fragment ps_2_0 someFunc();

 


Then I compiled this fragment:




// Registers:
//
//   Name         Reg   Size
//   ------------ ----- ----
//   NormalSampler  s0       1
//   s_CUBE       s1       1   // in fact s_Cube use sampler register s1 !!!!
//
    ps_2_0
    dcl t0.xy
    dcl t1
    dcl t2
    dcl t3
    dcl_2d s0
    dcl_cube s1
    def c0, 2, -1, 0, 0
    texld r0, t0, s0
    mov r2.x, t1.w
    mov r2.y, t2.w
    mov r2.z, t3.w
    mad r0.xyz, c0.x, r0, c0.y
    dp3 r1.x, t1, r0
    dp3 r1.y, t2, r0
    dp3 r1.z, t3, r0
    dp3 r3.x, r2, r1
    dp3 r0.x, r1, r1
    add r1.w, r3.x, r3.x
    mul r0.xyz, r2, r0.x
    mad r1.xyz, r1.w, r1, -r0
    texld r1, r1, s1
    mov oC0, r0

 


Question: What must I do that s_CUBE use sampler register s3






Answer this question

Help compile pixel shader from fragments right !

  • Sachindinde

    Found the workaround.  Just use 'c' instead of 's':
    sampler NormalSampler : register(c0);
    samplerCUBE s_CUBE : register(c3);      // s_CUBE must use sampler register s3

    :)

    Ben


  • Moshe Sivan

    Might sound a bit dumb - but why must the cubemap be in sampler 3

    The HLSL compiler does a lot of optimization - and it seems fairly trivial that it's spotted an s0 and s3 but no s1/s2 - hence changed s3.

    Jack



  • Roddles

    Ben Luna,

    Thanks.

  • Bruno Stocker

    Ben,

    thank you very much!!!
    It works good!

  • cravingsushi

    why the cubemap must be in sampler 3


    Materials system of render engine using by me places cubemap in sampler 3. It normally worked with asm pixel shaders ps_1_1.
    Now I need to use pixel shaders ps_2_0 and pixel fragment. 



  • Benoit Nesme

    Thanks for reporting this issue.  This is indeed a bug in the fragment linker.  Sorry, but I don't have a workaround for you.

    If possible, you will find the best results using HSL directly and precompiling all of your shaders off-line.  If you google for precompiled shaders, you will find many informative links regarding this.

    Ben Luna
    DirectX Graphics Team


  • Help compile pixel shader from fragments right !