Jump to content
  • Advertisement
Sign in to follow this  
hotpixel

[SOLVED][SORT OF] HLSL working fine except with Point Sprites?!

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

Hi there, I usually like to figure things out by myself but this is just doing my head in! I am coding in C# with the April 07 release of DirectX 9.0c SDK. I have made a 3D environment with an omni light in the middle. I wrote the fx file myself, it shades everything within a spherical space around the light postion and shades it accordingly. my HLSL code: struct VertexToPixel { float4 Position : POSITION; float2 TexCoords : TEXCOORD0; float3 Normal : TEXCOORD1; float3 Position3D : TEXCOORD2; }; struct PixelToFrame { float4 Color : COLOR0; }; float4x4 xWorld; float4x4 xViewProj; float4x4 xWorldViewProjection; float4 xLightPos; float xLightPower = 1.0f; Texture xColoredTexture; sampler ColoredTextureSampler = sampler_state { texture = <xColoredTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;}; VertexToPixel SimplestVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal : NORMAL) { VertexToPixel Output = (VertexToPixel)0; xWorldViewProjection = mul(xWorld, xViewProj); Output.Position = mul(inPos, xWorldViewProjection); Output.TexCoords = inTexCoords; Output.Normal = inNormal; Output.Position3D = mul(inPos, xWorld); return Output; } PixelToFrame OurFirstPixelShader(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; float3 LightDir = xLightPos - PSIn.Position3D; float distance = sqrt(LightDir.x*LightDir.x + LightDir.y*LightDir.y + LightDir.z*LightDir.z); Output.Color = tex2D(ColoredTextureSampler, PSIn.TexCoords)-(distance/100); return Output; } technique Simplest { pass Pass0 { VertexShader = compile vs_2_0 SimplestVertexShader(); PixelShader = compile ps_2_0 OurFirstPixelShader(); } } This works beautifully and everything is shaded just how I want it until I use point sprites, the point sprites do not render how I want them to. They all seem to shade as though they were positioned in a Vector3(0.0f,0.0f,0.0f) position no matter where I position them in the space. But what is bugging me is the fact that my shader works out the color depending on position and the HLSL is positioning them correctly just not shading them IT MAKES NO SENSE!!! Surely if I had the VertexDeclaration wrong then they would be positioned wrong?! I was just wondering if there was some quirk with point sprites and HLSL's. Many thanks, Andy [Edited by - hotpixel on July 16, 2008 6:40:26 AM]

Share this post


Link to post
Share on other sites
Advertisement

I'm no guru, so I'm probably entirely wrong [smile]

Anyway, for some rampant speculation it might be a quirk with point sprites. I've never used them in any scenario where they needed to be lit and now that I think of it, I haven't seen any tutorials or samples that do this. It might make some sense, since something magical goes on between the vertex shader and the pixel shader to make that single vertex into a quad. Chances are this causes non-typical data, like Position3D, to get lost.

Try some different outputs from the pixel shader to investigate. For starters, output a solid color to make sure it's getting applied. Next ouput the Postion3D.xyz as the Output.Color.rgb (scale your coords to roughly fit the 0-1 range). If that makes the sprite turn up all black, it's a sure indication Position3D got lost. If that's the case and no one else has a better idea, the last resort would be to create the quads yourself and use these instead of the point sprites.

Share this post


Link to post
Share on other sites
Okay this is very strange and unexplainable...

I have done what remigius suggested and the point sprites are coloured solid if I assign them a solid colour, ie:

Output.Color = 1.0f;

fine the point sprite is white.

Then when I try:

Output.Color.rgb = PSIn.Position3D.xyz;

They aren't black as remigius suggests but the top left vertex is shaded black, top right is red, bottom left green and bottom right yellow, all merging into each other in the middle and unchanging as they reposition (within a 1.0f space). This does suggest that remigius is correct and that Position3D gets lost in translation to the pixel shader which somehow misinterprets them as vertex colours and ignores the values they contain populating them with black, red, green and yellow values.

I do have a very basic possible explanation, because the pixel shader has to construct 4 vertices and two triangle faces from a single vertex (I'm just guessing here!) perhaps the original position of that vertex is discarded before it enters the pixel shader? (answers on a postcard please!)

I have a custom 4 vertex tile class that I will use like a point sprite, it will use more resources but hey point sprites aren't working how I want them!

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.

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

Sign me up!