Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

directx 9 - Converting pixelshader asm to HLSL

I am trying to convert an inline asm ps_1_3 pixelshader back to HLSL and I am stuck at one instruction that I cannot find any documentation for. The instruction is +mov and such a modifier is not listed in the modifiers. I translated it to a simple assignment, but the rendered scene then looks different. Maybe my other translations are wrong as well.

Full asm code:

Sampler[0] = (DiffuseMapSampler);
pixelShader = asm
{
    ps_1_3
    tex t0
#ifdef _POINTLIGHT_
    add r0.rgb, v0, v0
    +mov r0.a, v0.a
    mul_x4 r0, t0, r0
#else
    mul_x4 r0, t0, v0
#endif
#if defined(OVERGROWTH) && HASALPHA2MASK
    mul_x2 r0.a, r0.a, t0.a
#endif
};

Struct and Sampler

struct VS_OUTPUT
{
    float4 Pos  : POSITION0;
    float2 Tex0 : TEXCOORD0;
#if _HASSHADOW_
    float4 TexShadow    : TEXCOORD1;
#endif
    float4 Color  : COLOR0;
    float Fog   : FOG;
};

texture DiffuseMap;
sampler DiffuseMapSampler = sampler_state
{
    Texture = (DiffuseMap);
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    AddressU  = WRAP;
    AddressV  = WRAP;
    MipMapLodBias = 0;
};

My HLSL translation

float4 basicPixelShaderNoShadow(VS_OUTPUT VsOut) : COLOR
{
    float4 diffuseMap = tex2D(DiffuseMapSampler, VsOut.Tex0);
    float4 outCol;
#ifdef _POINTLIGHT_
    outCol.rgb = VsOut.Color.rgb * 2;
    outCol.a = VsOut.Color.a;
    outCol = diffuseMap * outCol * 4;
#else
    outCol = diffuseMap * VsOut.Color * 4;
#endif

#if defined(OVERGROWTH) && HASALPHA2MASK
    outCol.a *= 2 * diffuseMap.a;
#endif
    return outCol;
}
question from:https://stackoverflow.com/questions/65861587/converting-pixelshader-asm-to-hlsl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The +mov means 'in parallel'. Found an example for it here. The differences in rendering come from a change in ps version. The HLSL was set to ps_2_a and when using ps_1_3 for it as well everything renders the same as with asm.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...