Sign in to follow this  
Kaelan

[HLSL] Outputting multiple texture coordinates

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this