Jump to content
  • Advertisement
Sign in to follow this  

Postprocess shader not working properly

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

Ok, so what I'm trying to do is do fake lighting in a 2d game by making 2 textures, one with the normal screen information, and the second one a black and white texture where the "lights" are located. I'm having trouble getting the second texture set properly. I'm generating the second texture by rendering the white only sprites to a backbuffer, then saving the result of that to a texture. I know it's being generated properly, because when I use a function to save the texture to a file during the game, the save is what I'm expecting to see. I'm using the flatredball engine, and it handles setting the first texture as the rendered screen for me, I just need to figure out how to set the second texture. When I try to just output the second color in the shader, all I get is a completely blank screen. What am I doing wrong? The texture gets updated every frame. This is getting pretty frustrating sad.gif.

The Shader Code:
// Shader Variable
float colorIntensity;

texture backTexture;

// Texture Sampler
//sampler2D inputSampler : register(s0);

sampler2D inputSampler;

sampler2D backSampler : register(s1) = sampler_state
{
texture = <backTexture>;
};

// Pixel Shader
float4 SaturateShader(float2 texCoord1 : TEXCOORD0) : COLOR
{
// Get the pixel's color
float4 color1 = tex2D(inputSampler, texCoord1);
float4 color2 = tex2D(backSampler, texCoord1);

// Return the saturated color
//color3 = color2 + .1f;
//color3 = color;
return color2;
}

// Technique
technique SetSaturation
{
pass Pass0
{
pixelShader = compile ps_2_0 SaturateShader();
}
}



The code that sets the second texture:
namespace Light.Entities
{
class PostProcessEffect : PostProcessingEffectBase
{
private Texture2D backTexture;
private float intensity;

public PostProcessEffect(String shader, Texture2D newBackTexture)
: base(shader)
{
backTexture = newBackTexture;
}

public override void InitializeEffect()
{
base.InitializeEffect();

mEnabled = true;
}

public void setIntensity(float intensityValue)
{
intensity = intensityValue;
}

public void updateTexture(Texture2D newBackTexture)
{
mEffect.Parameters["backTexture"].SetValue(newBackTexture);
}

protected override void SetEffectParameters(FlatRedBall.Camera camera)
{
mEffect.Parameters["colorIntensity"].SetValue(intensity);
mEffect.Parameters["backTexture"].SetValue(backTexture);
}
}
}


Edit: Never mind, I solved my problem through sheer luck.

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!