• Advertisement
Sign in to follow this  

HLSL Projective Textures

This topic is 4349 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 have written a shader in HLSL which performs projective texturing fine, but around the edges of the view the texture is being rendered from, it seems to not take into account the texture it should be rendering, and just renders white. Here is a screenshot of what I am talking about: http://equalmeans.net/~chriss/HLight.jpg The texture is being rendered downward from the light, and those white lines on the walls are where the edge of the projected textures view is. I am using tex2Dproj to get the texture coordiante, so I am not quite sure how to alter these to get rid of the white lines. Thank you in advance, -Chris

Share this post


Link to post
Share on other sites
Advertisement
No, it's not fixed unfortunately. On the two walls, there is a horizontal line right in the middle of them where the projected texture is registering white for some reason. My screen is pretty bright, so you may not be able to see it all that well if your screen is darker.

-Chris

Share this post


Link to post
Share on other sites
I had to up the brightness on my monitor to the point where I thought it might burn my eyes [grin]

Anyway, from what I can see, that horizontal line is running at the same height as your light source. Correct?

Have you got any clamping, wrapping or filtering modes set? Might be worth checking those out - just a guess though, but it could be that those lines are as a result of it sampling outside of the texture area.

hth
Jack

Share this post


Link to post
Share on other sites
The filtering mode for the projected texture is set to Clamp, so I thought that would have taken care of it, but I guess not. The shader works fine when projecting it onto something entirely in it's view, and even mostly well for objects not entirely in it's view, just a very small line at the edge of the view. So I am fairly certainly the shader code is ok, but here it is anyway:


float4x4 WorldViewProj; //World * View * Projection
float4x4 World; //World
float4x4 TexTransform; //Texture transformation matrix
float3 LightPos; //World position of the light
float LightFalloff; //Range of the light

texture LightTex;
texture ColorTex;

//Must be clamped so the light texture shows up only once
sampler LightTexSampler = sampler_state
{
Texture = <LightTex>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};

sampler ColorTexSampler = sampler_state
{
Texture = <ColorTex>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

////////////////////////////////////////////////////////////
// Structures
////////////////////////////////////////////////////////////
struct MainA2V{
float4 Position : POSITION;
float3 Normal : Normal;
float2 TexCoord0 : TEXCOORD0;
};

struct MainV2P{
float4 Position : POSITION;
float2 TexCoord0 : TEXCOORD0;
float4 TexCoord1 : TEXCOORD1;
float3 LightVec : TEXCOORD2;
};

////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////
void MainVS(in MainA2V IN, out MainV2P OUT)
{
//Copy color texture coordinates through
OUT.TexCoord0 = IN.TexCoord0;

//First two are the projected texture coordinates
OUT.TexCoord1 = mul(IN.Position, TexTransform);

//Position to light vector
OUT.LightVec = mul(IN.Position.xyz, (float3x3)World) - LightPos;

//Transform model-space vertex position to screen space:
OUT.Position = mul(IN.Position, WorldViewProj);
}

////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////
float4 MainPS(in MainV2P IN) : COLOR
{
//Read in values for light texture and color texture
float4 Color = tex2D(ColorTexSampler, IN.TexCoord0);
float4 Light = tex2Dproj(LightTexSampler, IN.TexCoord1);

//Squared distance from pixel to light
float LenSq = dot( IN.LightVec, IN.LightVec );

//Find the attenuation
float Attn = min(( LightFalloff * LightFalloff ) / LenSq, 1.2f);

//Compute lighting amount
float4 I = (Light * Attn);

//Color of texture * lighting amount
return Color * I;
}




To see what I'm talking about, you can download the little demo here. Try moving around and moving the light around and you will see the lines I am talking about, they are perpendicular to the direction of the light, at the height of the light.

-Chris

[Edited by - bengaltgrs on March 31, 2006 5:22:14 AM]

Share this post


Link to post
Share on other sites
Re:

//Position to light vector
OUT.LightVec = mul(IN.Position.xyz, (float3x3)World) - LightPos;


I know I occasionally neglect to update comments, but isn't that the light to position vector?

Share this post


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

  • Advertisement