cast ray to LightObjectType
by J0linar · in Torque 3D Professional · 11/28/2013 (7:44 am) · 6 replies
Hi, as Rons recent Blog brought me to the idea
to use a raycast for sun and light objects
How wise would that be and did anyone tried that so far?
The idea is pretty simple,
use a raycast to LightObjects
and as a result when/if hit the dirt lens gui would appear on the screen
Note: the script is ust a starting point and not complete yet!
Now am far from tryin this out but am looking for some helpfull advice
so if someone has a better idea
throw it in :D
to use a raycast for sun and light objects
How wise would that be and did anyone tried that so far?
The idea is pretty simple,
use a raycast to LightObjects
and as a result when/if hit the dirt lens gui would appear on the screen
function serverCmdDirtLens(%client)
{
// get the player object
%player = %client.player;
// with %distance set to 4, we can activate things that are 4m away.
%distance = 4;
// determine where the player is looking, and scale it out by a factor
// of %distance. By default, this gives us a 4m long vector
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, %distance);
// define the start and end coordinates of the ray
%startPoint = %player.getEyeTransform();
%endPoint = VectorAdd(%startPoint,%vec);
// set the mask to only return a hit on specified objects
%searchMasks = $TypeMasks::LightObjectType;
// cast ray starting at startPoint ending at endPoint with mask, ignoring %player
%scanTarg = ContainerRayCast (%startPoint, %endPoint, %searchMasks, %player);
// call the function on the object's datablock
if(%scanTarg)
%scanTarg.getDataBlock().interact(%scanTarg,%client);
}Note: the script is ust a starting point and not complete yet!
Now am far from tryin this out but am looking for some helpfull advice
so if someone has a better idea
throw it in :D
About the author
http://j0linar.blogspot.co.at/
#2
since shaders are not really my skillrange.
Anyways i will see with what i can come up with and i do get that a cast ray might not be great a solution but it would be automated -
Player faces light objects
= DirtLens appears on hud
Player moves out of light
= Dirtlens gets fade out
11/28/2013 (7:53 am)
I was looking for a shader solution but thats actually tricky especiallysince shaders are not really my skillrange.
Anyways i will see with what i can come up with and i do get that a cast ray might not be great a solution but it would be automated -
Player faces light objects
= DirtLens appears on hud
Player moves out of light
= Dirtlens gets fade out
#3
game/shaders/common/postFx/lightRay/lightRayP.hlsl
that file has everything u need to know about calculating light positions on screen and displaying a texture due to its position on screen
11/28/2013 (8:07 am)
never too late to learn boss :D game/shaders/common/postFx/lightRay/lightRayP.hlsl
that file has everything u need to know about calculating light positions on screen and displaying a texture due to its position on screen
#4
whats up with the standard flare textures
and there should be a way to exploit that and well there is one :D
i still have to workout my dirtlens textures
as currently they are not displaying well and that is mainly because of the borders.

however
this whole bla bla might result in source code changes aswell
as its not really great if you have a dirtlens but no sun or lightflare
and therefore i plan to rework that part so that both can be used at the same time -
that just means adding a duplicate of the flare function itself - to enable the usage of the flare and dirtlens textures at the same time.
11/28/2013 (9:13 am)
Hmm, tbh after looking thru the shader i started to ask myselfwhats up with the standard flare textures
and there should be a way to exploit that and well there is one :D
i still have to workout my dirtlens textures
as currently they are not displaying well and that is mainly because of the borders.

however
this whole bla bla might result in source code changes aswell
as its not really great if you have a dirtlens but no sun or lightflare
and therefore i plan to rework that part so that both can be used at the same time -
that just means adding a duplicate of the flare function itself - to enable the usage of the flare and dirtlens textures at the same time.
#5
11/28/2013 (9:17 am)
i actually did mean for you to write your own shader based on the lightray shader approach lol this would have allowed both to be used at the same time
#6
11/28/2013 (9:51 am)
This looks promising, keep it up is looking good :-)
Thomas Fluff Harris
CTRL-INTELLIGENCE Ltd
Lens flares only appear when the screen has the sun in them and get brighter/ bigger the more the player is looking directly at the sun.
This would give u an idea of how to implement it in the shader?