Sign in to follow this  

Point Sprite Size into World Space

This topic is 4747 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, I made a Vertex Shader for my point sprites, but since im changing their sizes, I need to scale them acording to worldspace insted of screen space? Anyone know how to do that? [Edited by - MetaKnight on December 15, 2004 8:42:10 AM]

Share this post


Link to post
Share on other sites
If I'm reading this correctly, you should be able to simply pass in the worldMatrix into the vertex shader and use that (in addition to the worldViewProj matrix, of course).

Share this post


Link to post
Share on other sites
Yeah I tried every matrix and the matviewproj, when I use them it just ends up making the points smaller as I get closer, it should be getting bigger.

Im only setting ->SetRenderState(D3DRS_POINTSPRITEENABLE,TRUE);
is there anything else I should set? Even though im making my own sizes?

Share this post


Link to post
Share on other sites
Oh okay, here is is:
[Source]
float4x4 matViewProjection;
float4x4 matView;
float4x4 matWorld;



sampler2D maintex;
float Time;



struct vertexInput {
float3 position : POSITION;
float4 tex1 : TEXCOORD0; // velocity for each point
};

struct vertexOutput {
float4 Position : POSITION;
float4 COUT: COLOR0;
float Point : PSIZE; // this is the size
};


//------------------------------------
vertexOutput VSP(vertexInput IN)
{
vertexOutput OUT;
IN.position += IN.tex1*Time ;
OUT.Position = mul( float4(IN.position , 1.0) , matViewProjection);
OUT.Point = mul(5,matWorld); // here's where the problem is with scaling
OUT.COUT = float4(1,1,1,1);
return OUT;
}



Share this post


Link to post
Share on other sites
Oh, well in this case you should not need to be using any of the transform matricies for the scaling. The location will use that, but the scale doesn't.

So just use normal multiplication. If you need to scale them relative to their distance you will have to also know the location of the "eye" or camera, which you must pass in from the core program. Then some simple math to find the distance (need to know some trig here) -- then just use


Out.Point = absoluteScaling * distanceScaling;
// Absolute can be whatever size you want, depending on how big you want them to appear; distance is what you just calculated between eye and point



EDIT: A good link if you want some background on this stuff is HERE

Share this post


Link to post
Share on other sites
Ah yeah, it seems the matrix doesnt seem to help at all for scaling

In the end i got this eqation to find out the scale:

S s = Vh * Si * sqrt(1/(A + B * De + C *( De2 )))

That works perfectly! , thanks rjackets!

Share this post


Link to post
Share on other sites

This topic is 4747 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.

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