Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

SlimDX and Shaders

This topic is 3744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!