Jump to content
  • Advertisement
Sign in to follow this  
Kaelan

[HLSL] Outputting multiple texture coordinates

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

So I'm trying to write a glow shader at the moment and one part of this involves creating a blurred version of a source image. For some odd reason, whenever I try to output more than one texture coordinate, however, every coordinate but the first comes out wrong. As an example, a simple version of the shader code I'm using right now:
texture glowTexture;

sampler GlowSampler = sampler_state
{
    Texture   = (glowTexture);
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

//Passed to the vertex shader from the pipeline
struct GLOW_INPUT
{
    float4 pos : POSITION;
    float2 texCoord : TEXCOORD;
};

//VS output / PS input:
struct GLOW_OUTPUT
{
    float4 pos : POSITION;
    float2 texCoord0 : TEXCOORD0;
    float2 texCoord1 : TEXCOORD1;
    float2 texCoord2 : TEXCOORD2;
    float2 texCoord3 : TEXCOORD3;
};

//PS output:
struct pixel
{
    float4 color : COLOR;
};

//////////////////////////
//  Vertex Shaders:
//////////////////////////
GLOW_OUTPUT glowVSHorizontal1(GLOW_INPUT IN)
{
    GLOW_OUTPUT OUT;
	
    OUT.pos = IN.pos;
	
    OUT.texCoord0 = IN.texCoord;
    OUT.texCoord1 = IN.texCoord;
    OUT.texCoord2 = IN.texCoord;
    OUT.texCoord3 = IN.texCoord;
	
    return OUT;
}
//////////////////////////
//  Pixel Shaders:
//////////////////////////
pixel glowPS(GLOW_OUTPUT IN)
{
    pixel OUT;
	
    float4 color  = tex2D( GlowSampler, IN.texCoord0 ) *
		  tex2D( GlowSampler, IN.texCoord1 ) *
		  tex2D( GlowSampler, IN.texCoord2 ) *
		  tex2D( GlowSampler, IN.texCoord3 );

    OUT.color = color;
    OUT.color.a = 1.0f;
	
    return OUT;
}

//////////////////////////
//  Techniques:
//////////////////////////
technique T0
{
	pass P0
	{
	    vertexshader = compile vs_2_0 glowVSHorizontal1();
	    pixelshader  = compile ps_2_0 glowPS();
	}
}


This should be sampling the same color four times and making a dimmer version of the original image. It's not: instead all I get is black. If I change the pixel shader to:
pixel glowPS(GLOW_OUTPUT IN)
{
	pixel OUT;
	
	float4 color  = tex2D( GlowSampler, IN.texCoord0 ) *
			tex2D( GlowSampler, IN.texCoord0 ) *
			tex2D( GlowSampler, IN.texCoord0 ) *
			tex2D( GlowSampler, IN.texCoord0 );

	OUT.color = color;
	OUT.color.a = 1.0f;
	
	return OUT;
}


Then, it works fine and I get the expected output. What's going on here? I'm clearly missing something to make this work correctly, but I have no idea what...it's like I'm writing 4 variables with the same value, but only one of them actually gets written to correctly. Any ideas on what I'm doing wrong here?

Share this post


Link to post
Share on other sites
Advertisement
I'm getting the impression that it's just not applying any kind of transformations or interpolations to any of the texture coordinates beyond the first one. But I have no idea why it would do that. :/

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!