Sign in to follow this  
alt3

[solved] EffectHandle always null on same globals in fx

Recommended Posts

Hi, i wonder getting null for return on a GetParameter in my program. This happens always for the same global variables. I'm working with managed directx 1.1 / C#. Here is how i load the .fx file:
private static Effect mDOF;
mDOF = Effect.FromFile(dev, @"../../DepthOfField.fx", null, null, ShaderFlags.Debug, null, out lWarningAndErrorsDOF);
How i'm trying to get a handle on a variable:
Vector4 lLightDir = new Vector4(200.0f, 300.0f, 150.0f, 0.0f);
EffectHandle hLightDir = mDOF.GetParameter(null, "lightDir");
mDOF.SetValue(hLightDir , lLightDir);
Here hLightDir always get null value. It disturbs me at the highest point ! (and the render is always black). Here is .fx file, with is valid, according to fx composer:
float4x4 WorldViewProj : WorldViewProjection;
float4x4 WorldViewIT : WorldInverseTranspose;
float4x4 WorldView : ViewInverse;
float4   MinMaxDist;
float4   FocusConst;

float4 lightDir : Direction
<
> = {200.0f, 300.0f, 150.0f, 0.0f};

float4 lightColor : Diffuse
<
> = {1.0f, 1.0f, 1.0f, 1.0f};

float4 lightAmbient : Ambient
<
> = {1.0f, 1.0f, 1.0f, 1.0f};

float4 materialDiffuse : Diffuse
<
> = {1.0f, 1.0f, 1.0f, 1.0f};

float    UvOffsetToUse;
float4   UvBase[8];

//-------------------------------------------------------------------
// Textures (bound to real textures by app)
//-------------------------------------------------------------------

texture Meshes;
texture CircleOfConfusion;
texture WorldTex;
texture BlurTex;
texture FilteredTex0;
texture FilteredTex1;
texture FilteredTex2;

//-------------------------------------------------------------------
// Vertex shader input structures
//-------------------------------------------------------------------

struct vertexInput {
    float3 position                : POSITION;
    float3 normal                : NORMAL;
    float4 texCoordDiffuse        : TEXCOORD0;
};

struct VS_INPUT_PT {
    float4 Position : POSITION;
    float2 TexCoord : TEXCOORD0;
};

//-------------------------------------------------------------------
// Vertex shader output (and pixel shader input) structures
//-------------------------------------------------------------------

struct VS_OUTPUT_PT4 {
    float4 oPosition  : POSITION;
    float2 oTexCoord0 : TEXCOORD0;
    float2 oTexCoord1 : TEXCOORD1;
    float2 oTexCoord2 : TEXCOORD2;
    float2 oTexCoord3 : TEXCOORD3;
};

struct vertexOutput {
    float4 hPosition        : POSITION;
    float4 texCoordDiffuse    : TEXCOORD0;
    float4 diffAmbColor        : COLOR0;
    float3 oTexCoord1 : TEXCOORD1;
};

//-------------------------------------------------------------------
// Texture samplers
//-------------------------------------------------------------------


sampler TextureSampler = sampler_state
{
    texture = <Meshes>;
    AddressU  = CLAMP;        
    AddressV  = CLAMP;
    AddressW  = CLAMP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};


sampler CircleOfConfusionSampler = sampler_state
{
    Texture = <CircleOfConfusion>;
    MinFilter = Linear;  
    MagFilter = Linear;
    MipFilter = None;
    AddressU  = Clamp;
    AddressV  = Clamp;
    AddressW  = Clamp;
};

sampler BlurTexSampler = sampler_state
{
    Texture = <BlurTex>;
    MinFilter = Linear;  
    MagFilter = Linear;
    MipFilter = Linear;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

sampler FilteredTexSampler0 = sampler_state
{
    Texture = <FilteredTex0>;
    MinFilter = Linear;  
    MagFilter = Linear;
    MipFilter = NONE;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

sampler FilteredTexSampler1 = sampler_state
{
    Texture = <FilteredTex1>;
    MinFilter = Linear;  
    MagFilter = Linear;
    MipFilter = NONE;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

sampler FilteredTexSampler2 = sampler_state
{
    Texture = <FilteredTex2>;
    MinFilter = Linear;  
    MagFilter = Linear;
    MipFilter = NONE;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

//-------------------------------------------------------------------
// Vertex Shaders (and subroutines)
//-------------------------------------------------------------------

float ComputeDistance(float4 position)
{
    float dist = dot(position, float4(WorldView[0][2], WorldView[1][2], WorldView[2][2], WorldView[3][2]));
    //dist = dist / dot(position, float4(WorldView[0][3], WorldView[1][3], WorldView[2][3], WorldView[3][3]));
    return dist;
}

vertexOutput VS_TransformAndTexture(vertexInput IN)
{
    vertexOutput OUT;
    OUT.hPosition = mul( float4(IN.position.xyz , 1.0) , WorldViewProj);
    OUT.texCoordDiffuse = IN.texCoordDiffuse;

    float3 worldEyePos = WorldView[3].xyz;
    float3 worldVertPos = (IN.position).xyz;
    
    float4 N = mul(IN.normal, WorldViewIT); //normal vector
    float3 E = normalize(worldEyePos - worldVertPos); //eye vector
    float3 L = normalize( -lightDir.xyz); //light vector
    float3 H = normalize(E + L); //half angle vector

    float  diff = max(0 , dot(N,L));

    float4 ambColor = materialDiffuse * lightAmbient;
    float4 diffColor = materialDiffuse * diff * lightColor;
    OUT.diffAmbColor = diffColor + ambColor;

    float4 lPosition = float4(IN.position, 1.0);
    float dist = ComputeDistance(lPosition);        
    OUT.oTexCoord1.x = dist*MinMaxDist.y - MinMaxDist.x;
    OUT.oTexCoord1.yz = FocusConst.xy;

    return OUT;
}

VS_OUTPUT_PT4 BlurVS(const VS_INPUT_PT IN)
{
    VS_OUTPUT_PT4 OUT;
    
    // Transform vertex position to clip space
    OUT.oPosition = mul(IN.Position, WorldViewProj);    
    
    int a = (int)UvOffsetToUse * 4;    

    OUT.oTexCoord0 = IN.TexCoord + UvBase[a    ].xy;
    OUT.oTexCoord1 = IN.TexCoord + UvBase[a + 1].xy;
    OUT.oTexCoord2 = IN.TexCoord + UvBase[a + 2].xy;
    OUT.oTexCoord3 = IN.TexCoord + UvBase[a + 3].xy;

    return OUT;
}

//-------------------------------------------------------------------
// Pixel Shaders
//-------------------------------------------------------------------

float4 BlurPS(VS_OUTPUT_PT4 IN) : COLOR
{
    // This is a simple blur-shader: we simply average all alpha and color
    // values together.
    
    // get colors and alphas from all 4 texture stages
    float4 color0 = tex2D(BlurTexSampler, IN.oTexCoord0);
    float4 color1 = tex2D(BlurTexSampler, IN.oTexCoord1);
    float4 color2 = tex2D(BlurTexSampler, IN.oTexCoord2);
    float4 color3 = tex2D(BlurTexSampler, IN.oTexCoord3);

    // return the average (keeping within the [-2..2] range)
    return 0.5*( 0.5*(color0 + color1) + 0.5*(color2 + color3) );
}

float4 PS_Textured( vertexOutput IN): COLOR
{
    float4 diffuseTexture = tex2D( TextureSampler, IN.texCoordDiffuse );
    return IN.diffAmbColor * diffuseTexture;
}


//-------------------------------------------------------------------
// TECHNIQUES
//-------------------------------------------------------------------

technique TetraDOF
{
    pass P0
    {
          VertexShader = compile vs_1_1 VS_TransformAndTexture();
        PixelShader  = compile ps_1_1 PS_Textured();
    }
}

technique Blur
{
    pass P0
    {
        VertexShader = compile vs_1_1 BlurVS();
        PixelShader  = compile ps_1_1 BlurPS();
        
        // note that these render-state changes are reverted once the effect is complete.
        AlphaBlendEnable = False;
        ZEnable          = False;
        CullMode         = None;
        FillMode         = Solid;  // (even if wireframe is turned on)
        
        ColorOp[0]   = SelectArg1;
        ColorArg1[0] = Texture;
        ColorArg2[0] = Diffuse;
        ColorOp[1]   = Disable;
        AlphaOp[0]   = Disable;
    }
}

technique ShowDepthOfField
{
    pass P0
    {
        Sampler[0] = <FilteredTexSampler0>;
        Sampler[1] = <FilteredTexSampler1>;
        Sampler[2] = <FilteredTexSampler2>;

        AlphaBlendEnable = False;
        ZEnable          = False;
        CullMode         = None;
        FillMode         = Solid;  // (even if wireframe is turned on)
    
        VertexShader = compile vs_1_1 BlurVS();
        PixelShader  =
        asm
        {
           ; NOTE: This shader exists in HLSL above (see ShowDepthOfFieldPS),
           ; but is commented out; the assembly version is used here because
           ; it's the only way to fit this shader in ps1.1.  The HLSL-compiled
           ; version will work if you compile it using ps_2_0; but since the
           ; assembly version will fit in ps_1_1, it is used here instead.
            
           ; Declare pixel shader version
            ps_1_1
            
            def c0, 0.0f, 0.0f, 0.0f, 0.5f
            def c1, 0.0f, 0.0f, 0.0f, 0.333333f
            
           ; sample all the texture stages
            tex t0
            tex t1
            tex t2
            
           ; first interpolate the interpolator: using t0 straight produces ghosting
           ; since the DoF selection is always hi-res (ie, t0) even for the blurred parts.
           ; playing with various combinations of t0, t1, t2 shows that the following
           ; is reasonable (depth-changing edges never get really unblurred)
           ; and yet only takes a single instruction.
            lrp r0.a, c0, t2.a, t0.a
            
           ; although the following also produces good results (but with a bit of ghosting
           ; and two instructions)
           ; r0.a = 0.666*(.5*t2.a + .5*t1.a) + 0.333 * t0.a)
           ;      = 0.333*(t0.a+t1.a+t2.a)
           ; lrp r0.a, c0, t2.a, t1.a
           ; lrp r0.a, c1, r0.a, t0.a    
            
            mov_x2_sat r1.a,   r0.a                // pretend 0 <= r0.a <= 0.5
            lrp           r1.rgb, r1.a, t1, t0        // correctly interpolate t0, t1 and store
            mov_sat    r1.a,   r0_bx2.a         // pretend 0.5 <= r0.a <= 1
            lrp        r0.rgb, r1.a, t2, t1     // correctly interpolate t1, t2 and store
            
            cnd           r0.rgb, r0.a, r0, r1        // figure out which case is the true one and select it
            
           ; mov r0.rgb, t0.a
        };
    }
}
Can anyone help me ? Regards, alt3. [Edited by - alt3 on May 26, 2007 3:09:43 PM]

Share this post


Link to post
Share on other sites
Erm, in fact it was not a real problem:
https://forums.xna.com/thread/10684.aspx

Shame on me.

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