SlimDX and Shaders

Started by
10 comments, last by Stormtrooper 15 years, 9 months ago
I've been poking this all day and can't figure out for the life of me why this won't work. I have this shader:

texture myTexture;

sampler2D texSampler0 = sampler_state
{
	Texture	  = <myTexture>;
};

float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color;
    
    Color = tex2D( texSampler0, Tex.xy)*10;
    return Color;
}


technique TestShader
{
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 MyShader();
    }

}

That is simply suppose to make everything a bit brighter. But the effect isn't doing squat. Here is my code. First I call begin scene, then begin effect, then draw the sprite, then end effect, then end scene. There are no errors when compiling or running. I'm setting the texture to the Texture of the sprite I'm rendering

        public Renderer(Form renderForm)
        {
            ...
            _spriteEffect = Effect.FromFile(_device, "shader.fx", ShaderFlags.Debug);
            _spriteEffect.Technique = "TestShader";
         
        }

      /// <summary>
        /// Clears the buffers and begins the scene.
        /// </summary>
        public void BeginScene()
        {
            _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            _device.BeginScene();            
            _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);
        }


        public void beginEffect()
        {
            _spriteEffect.Begin(FX.None);
            _spriteEffect.BeginPass(0);
        }

        public void endEffect()
        {
            _spriteEffect.EndPass();
            _spriteEffect.End();
        }

        public void SetEffectTexture(Texture texture)
        {
            _spriteEffect.SetValue("myTexture", texture);
        }

        /// <summary>
        /// Ends the scene then flips the buffers.
        /// </summary>
        public void EndScene()
        {
            _sprite.End();

            _device.EndScene();
            _device.Present();
        }

Any and all help would be greatly appreciated.
Advertisement
I suspect you have a problem calling sprite.End() after you call effect.End().

The sprite queue isn't submitted to the device until sprite.End() is called.

EDIT: You might try swapping the order of begin's and end's

effect.Begin
sprite.Begin
sprite.Draw
sprite.End
effect.End

or call sprite.Flush before you call effect.End

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thanks for the tips...but unfortunately it didn't help. I've looked at the SlimDX examples and they are pretty much exactly how I have it. I'm wondering if something isn't wrong with the shader itself. Do I need to have a vertex shader in there as well?
Why cant i see the first post, only the answer post ?

Is my IE messed up ? or is some nerds actually deleting there initial post(s)

Seem to see this in several posts, pissing me off to be honest.

[Edited by - NightMarez on July 18, 2008 3:01:21 AM]
Quote:Original post by NightMarez
Why cant i see the first post, only the answer post ?

Is my IE messed up ? or is some nerds actually deleting there initial post(s)

Seem to see this in several posts, pissing me off to be honest.


Theres a fix for that....it's called FireFox :)
Quote:
Why cant i see the first post, only the answer post ? ... is some nerds actually deleting there initial post(s)

There are no deleted posts in this thread.

Quote:
Thanks for the tips...but unfortunately it didn't help. I've looked at the SlimDX examples and they are pretty much exactly how I have it. I'm wondering if something isn't wrong with the shader itself. Do I need to have a vertex shader in there as well?

That depends on the nature of the geometry; if a no-op vertex shader is sufficient to render the geometry, then no vertex shader is equivalent to the no-op shader.

Scaling by 10 in your pixel shader like that is, by the way, going to saturate most colors to white. You background isn't white, is it?
Quote:
That depends on the nature of the geometry; if a no-op vertex shader is sufficient to render the geometry, then no vertex shader is equivalent to the no-op shader.

Scaling by 10 in your pixel shader like that is, by the way, going to saturate most colors to white. You background isn't white, is it?


Everything appears as if there is no shader at all. If I take out all the _spriteEffect code it would look exactly the same as if I had it in there. And my background is white. The tiles are green.
It's possible the geometry -- the positions you're using for the sprite -- are in the wrong space or otherwise outside the range of values that would provide sane on-screen values. What to the numbers look like?
The x,y values go from 0,0 to the width/height of the screen(drawing a tilemap of 32x32 sprites). The z value of the sprites is 0.
Quote:Original post by jpetrie
Quote:
Why cant i see the first post, only the answer post ? ... is some nerds actually deleting there initial post(s)

There are no deleted posts in this thread.


Then my forum is bugged up like hell, total wierdness (sorry for hijacking the post like this, its just very confusing).

I only see 1 post above my other one, i suspect there should be 2 atleast since the post above my first one in this topic looks like a answer post.

This topic is closed to new replies.

Advertisement