hi all.. i`m trying to find a way to make a sprite display a different texture based on its direction and speed based on screen coordinates.. ie, relative to eye (camera) so if it is moving fast across screen -x it displays one thing, and if its moving very slowly in scrren +x it displays another etc..
any help appreciated,
cheers,
Mark
different sprites based on SCREEN direction
3384 3 2- MWainwright
- Member
- 119 posts
- Joined: July 2005
- Offline
- craiglhoffman
- Member
- 252 posts
- Joined: July 2005
- Offline
- jason_iversen
- Member
- 12544 posts
- Joined: July 2005
- Offline
Hey there,
I'd temporarily transform the particles into camera space - either just the overall transformation, using the Object Merge transform SOP capabilities, or I'd write a small SOP that will do the equivalent of a toNDC() operation (look here for a hint: http://www.odforce.net/tips/velocity.htm [odforce.net]
Now you can just check the sign of $VX (velocity in X) component to find out whether your particle is moving screen left or screen right.
I find many seemlingly more complex problems are more easily dealt with once you've prepared you inputs in the most efficient way - in this case pre-transforming your particles to an easy space for quick comparison.
Hope this helps,
Jason
PS. You can also do a cheap transform-into-camera-space without any VEX by using the UVTextureSOP to project UV coordinates from camera and then you can shift the particles into their texture space with the Point SOP by putting $MAPU,V,W into the translate positions. You can easily shift the points back again afterwards if you stash the original translates - or if you use the second input of the PointSOP and copy back the original positions.
CAVEAT: Shifting points about with VEX and with the PointSOP will NOT transform any vectors - so your “v” attribute will still be in the old space, or so I believe. I think the VEX sop from the tutorial could be extended fairly easily to support transforming “v” properly into camera space however. But I always say if it's easier to use a built-in method as with the ObjectMerge idea, do that even if it's less “pure”.
I'd temporarily transform the particles into camera space - either just the overall transformation, using the Object Merge transform SOP capabilities, or I'd write a small SOP that will do the equivalent of a toNDC() operation (look here for a hint: http://www.odforce.net/tips/velocity.htm [odforce.net]
Now you can just check the sign of $VX (velocity in X) component to find out whether your particle is moving screen left or screen right.
I find many seemlingly more complex problems are more easily dealt with once you've prepared you inputs in the most efficient way - in this case pre-transforming your particles to an easy space for quick comparison.
Hope this helps,
Jason
PS. You can also do a cheap transform-into-camera-space without any VEX by using the UVTextureSOP to project UV coordinates from camera and then you can shift the particles into their texture space with the Point SOP by putting $MAPU,V,W into the translate positions. You can easily shift the points back again afterwards if you stash the original translates - or if you use the second input of the PointSOP and copy back the original positions.
CAVEAT: Shifting points about with VEX and with the PointSOP will NOT transform any vectors - so your “v” attribute will still be in the old space, or so I believe. I think the VEX sop from the tutorial could be extended fairly easily to support transforming “v” properly into camera space however. But I always say if it's easier to use a built-in method as with the ObjectMerge idea, do that even if it's less “pure”.
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- tallkien
- Member
- 225 posts
- Joined: July 2005
- Offline
just shooting off a wild theory here since I have no way of verifying this right now
Say your cam has a lookat, the vector << t - t >> is screen centre and vector << t - t >> is the direction of each particle (ignore the y component or set it to 0 to simplify things). The angle between these vectors gives you how far off screen centre each particle is, and the sign of the angle will tell you in which direction.
Then Mod(clamp(Angle)) and use it to drive your textures :? … I think…
Hope this is useful
cheers
tallkien
Say your cam has a lookat, the vector << t - t >> is screen centre and vector << t - t >> is the direction of each particle (ignore the y component or set it to 0 to simplify things). The angle between these vectors gives you how far off screen centre each particle is, and the sign of the angle will tell you in which direction.
Then Mod(clamp(Angle)) and use it to drive your textures :? … I think…
Hope this is useful
cheers
tallkien
-
- Quick Links