Jump to content
  • Advertisement
Sign in to follow this  
danromeo

Why doesn't this simple shader work?

This topic is 2786 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

Hey, thanks for reading this.

I have a simple pixel shader which was intended to take two textures and combine them according to a third mask texture. Doesn't work. So I've simplified the shader to simply draw Texturemap1, but tex2d and output the color from Texturemap2.....but it always outputs the color from Texturemap1. WTH?

I set up a sprite batch and render the first texture to it using the simple pixel shader below. All the pixel shader does is gets the color from the second texture and outputs it. As a basic reality check I am able to set the output color to float4(1,0,0,0) and I get the expected results....all red.....so I know that it's at least hitting the correct technique, etc.

The code is very simple. Can somebody tell me what I'm doing wrong PLEASE?????

CODE:

Texture2D map1;
Texture2D map2;

[font="Consolas"][font="Consolas"]combinedMap = [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]RenderTarget2D[/font][/font][/font][font="Consolas"][font="Consolas"](game.GraphicsDevice, Map1.Width, Map2.Height, [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]false[/font][/font][/font][font="Consolas"][font="Consolas"], [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]SurfaceFormat[/font][/font][/font][font="Consolas"][font="Consolas"].Color, [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]DepthFormat[/font][/font][/font][font="Consolas"][font="Consolas"].None);
[font="Consolas"][font="Consolas"]Map1 = content.Load<[/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]Texture2D[/font][/font][/font][font="Consolas"][font="Consolas"]>([/font][/font][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"]...[/font][/font][/font][font="Consolas"][font="Consolas"] + name);
Map2 = content.Load<[/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]Texture2D[/font][/font][/font][font="Consolas"][font="Consolas"]>([/font][/font][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"]...[/font][/font][/font][font="Consolas"][font="Consolas"] + name);

[/font][/font][/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]SpriteBatch[/font][/font][/font][font="Consolas"][font="Consolas"] sb = [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]SpriteBatch[/font][/font][/font][font="Consolas"][font="Consolas"](game.GraphicsDevice);
game.GraphicsDevice.SetRenderTarget(combinedMap);
CreateMaps.CurrentTechnique = CreateMaps.Techniques[[/font][/font][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"]"Combined"[/font][/font][/font][font="Consolas"][font="Consolas"]];
game.GraphicsDevice.Clear([/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]Color[/font][/font][/font][font="Consolas"][font="Consolas"].Black);
sb.Begin(0, [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]BlendState[/font][/font][/font][font="Consolas"][font="Consolas"].Opaque, [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]null[/font][/font][/font][font="Consolas"][font="Consolas"], [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]null[/font][/font][/font][font="Consolas"][font="Consolas"], [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]null[/font][/font][/font][font="Consolas"][font="Consolas"], CreateMaps);
sb.Draw(Map1, [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]Rectangle[/font][/font][/font][font="Consolas"][font="Consolas"](0, 0, Map1.Width, Map1.Height), [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]Color[/font][/font][/font][font="Consolas"][font="Consolas"].White);
sb.End();
[/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]FileStream[/font][/font][/font][font="Consolas"][font="Consolas"] fs = [/font][/font][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"][font="Consolas"][color="#2b91af"]File[/font][/font][/font][font="Consolas"][font="Consolas"].OpenWrite([/font][/font][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"]"c:\\users\\base\\pictures\\test.jpeg"[/font][/font][/font][font="Consolas"][font="Consolas"]);
game.GraphicsDevice.SetRenderTarget([/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]null[/font][/font][/font][font="Consolas"][font="Consolas"]);
combinedMap.SaveAsJpeg(fs, Map1.Width, Map1.Height);
fs.Close();

HLSL:

[font="Consolas"][font="Consolas"]

uniform const Texture Map1;
uniform const Texture Map2;

uniform const sampler map1Sampler = sampler_state{ Texture = <Map1>; MinFilter = Linear;MagFilter = Linear;MipFilter = Linear;AddressU = CLAMP; AddressV = CLAMP;};
uniform const sampler map2Sampler = sampler_state{ Texture = <bathymetryHeightMap>; MinFilter = Linear;MagFilter = Linear;MipFilter = Linear;AddressU = CLAMP; ...etc

float4 CombinedPS(float2 texcoord : TEXCOORD0) : COLOR0
{
float4 map1color=tex2D(Map1Sampler, texcoord);
return map1color;
}

[/font][/font]?

[/font][/font]

Share this post


Link to post
Share on other sites
Advertisement
What you mean it doesnt work???

Where is your vertex shader?

Use [code.] your code here [/code.] Without the dots, so it looks like this your code here

Share this post


Link to post
Share on other sites
1.
> What you mean it doesn't work?

It outputs the color from the map that's being drawn, not the color from the map that I"m tex2d;'ing

> Where is your vertex shader
No vertex shader. Even with a simple vertex shader that simpy passes the texcoord to the pixel shader, I get the same result

2.
>You defined your sampler as "map1Sampler" but used it as "Map1Sampler". I don't think that's allowed.

This is a typo in the post. It obviously would have died with a runtime error if that was the case. The code compiles and runs. Therefore you can ignore the several typos in the 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!