Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, TedMar, Ayumi), 800 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 3 of 5 1 2 3 4 5
Re: Projective Texture Mapping - Spotlight Flashl [Re: frazzle] #181153
02/08/08 18:48
02/08/08 18:48
Joined: Jul 2005
Posts: 421
Germany
DoC Offline
Senior Member
DoC  Offline
Senior Member

Joined: Jul 2005
Posts: 421
Germany
Does anyone can convert it to wdl ? I had try it but give up ;_;

Re: Projective Texture Mapping - Spotlight Flashl [Re: DoC] #181154
02/09/08 19:02
02/09/08 19:02
Joined: May 2007
Posts: 7
R
Reigel_Seven Offline
Newbie
Reigel_Seven  Offline
Newbie
R

Joined: May 2007
Posts: 7
Down below is the first Grafton example converted to WDL. Just save this code as something like "grafton1.wdl", then include it in your main script file right above your other includes, like this:

include <grafton1.wdl>;

It seems like only one entity can emit a spotlight at a time with this code, but as many entities as you need can be spotlit. You can either assign the "action Spotlight()" to your player and "action Spotlit_object()" to the entities to be spotlit, or you can do the following:

Place the following code somewhere in a while loop for the entity to emit the spotlight, like the player:

Code:
 
// send my position to shader (vecSkill1.xyzw)
mtlSpotlit.skill1 = float(my.x);
mtlSpotlit.skill2 = float(my.z); // z and y must be reversed!
mtlSpotlit.skill3 = float(my.y);
mtlSpotlit.skill4 = float(650); // spotlights range

// send my direction to shader (vecSkill2.xyzw)
vec_for_angle(temp_vec.x, vector((my.pan), my.tilt, my.roll)); //turn my angles into a dir vector
mtlSpotlit.skill5 = float(temp_vec.x);
mtlSpotlit.skill6 = float(temp_vec.z); // z and y must be reversed!
mtlSpotlit.skill7 = float(temp_vec.y);



And you can put this little code in any script linked to an entity you want spotlit:

Code:
 
my.material = mtlSpotlit;



Alternatively, you could just assign the "mtlSpotlit" material in WED to any entities you want spotlit, since many of your entites may not even have or need a C-Script.

The following is the code for the spotlight. Just use the "PP_Spot.fx" file from the Grafton example.

Code:
 
//
// By Joseph Duffey Jan 2008
// For the GameStudio Community
//
// Converted to WDL format by Reigel Seven 2008
//
// Example 1: Projective Texturing Spotlight with specular

//=======================================================================================
// VARIABLES
//=======================================================================================

var temp_vec[3]; // for temporary vectors
FONT standard_font = "Arial",1,14;

var pTexAdj[16];

//=======================================================================================
// CAMERA ACTION
//=======================================================================================

action Spectator()
{
//set(me,INVISIBLE | PASSABLE);
my.invisible = on;
my.passable = on;

// while(!player)
// {
// wait(1);
// }
vec_set(camera.x, my.x);

while(me)
{
vec_set(temp_vec,player.x);
vec_sub(temp_vec,camera.x);
vec_to_angle(camera.pan,temp_vec);
wait(1);
}
}

//=======================================================================================
// MATERIAL FOR OBJECTS LIT BY SPOTLIGHT
//=======================================================================================

MATERIAL mtlSpotlit
{
ambient_red = 12; // The ambient color - a dark grey.
ambient_green = 10;
ambient_blue = 8;
effect = "PP_Spot.fx"; // The effect file containing the vertex shader, pixel shader and technique.
}

//=======================================================================================
// SPOTLIGHT CODE
//=======================================================================================

action Spotlight()
{
//player = me;
while(1)
{
// move me with keyboard keys
// c_move(me, vector((key_w - key_s)*time_step*8,0,0), nullvector, IGNORE_PASSABLE | GLIDE);
// c_rotate(me, vector((key_cul-key_cur)*time_step*8, (key_cuu-key_cud)*time_step*8,0), IGNORE_PASSABLE );

// send my position to shader (vecSkill1.xyzw)
mtlSpotlit.skill1 = float(my.x);
mtlSpotlit.skill2 = float(my.z); // z and y must be reversed!
mtlSpotlit.skill3 = float(my.y);
mtlSpotlit.skill4 = float(650); // spotlights range

// send my direction to shader (vecSkill2.xyzw)
vec_for_angle(temp_vec.x, vector((my.pan), my.tilt, my.roll)); //turn my angles into a dir vector
mtlSpotlit.skill5 = float(temp_vec.x);
mtlSpotlit.skill6 = float(temp_vec.z); // z and y must be reversed!
mtlSpotlit.skill7 = float(temp_vec.y);

wait(1);
}
}

//=======================================================================================
// ACTION FOR OBJECTS LIT BY SPOTLIGHT
//=======================================================================================

action Spotlit_object()
{
my.material = mtlSpotlit;
}



I'm afraid I may have forgotten something, so please let me know if I did. I hope this helps somebody!

- Reigel Seven

Re: Projective Texture Mapping - Spotlight Flashl [Re: Reigel_Seven] #181155
02/10/08 13:25
02/10/08 13:25
Joined: Jul 2005
Posts: 421
Germany
DoC Offline
Senior Member
DoC  Offline
Senior Member

Joined: Jul 2005
Posts: 421
Germany
thats really cool your my men, it works, with the PP but now someone it will works with PT? aaaand with the sportlight jpg? someone how know it?

Then Im complete happy...
but I must say it again Reigel_Seven your great

Re: Projective Texture Mapping - Spotlight Flashl [Re: DoC] #181156
02/11/08 22:16
02/11/08 22:16
Joined: May 2007
Posts: 7
R
Reigel_Seven Offline
Newbie
Reigel_Seven  Offline
Newbie
R

Joined: May 2007
Posts: 7
No problem, DoC. I've been trying to convert the PT examples, but haven't had much luck.I've gotten them to run, but you can't see the projected texture. If I get it working I'll post it, but don't count on it

Re: Projective Texture Mapping - Spotlight Flashl [Re: Reigel_Seven] #181157
02/11/08 22:44
02/11/08 22:44
Joined: Jul 2005
Posts: 421
Germany
DoC Offline
Senior Member
DoC  Offline
Senior Member

Joined: Jul 2005
Posts: 421
Germany
i think the problem is the view with the skin that dont work in wdl...
one day i learn lite-c.... but this day can wait ^__^

Re: Projective Texture Mapping - Spotlight Flashl [Re: DoC] #181158
02/14/08 12:51
02/14/08 12:51
Joined: Oct 2007
Posts: 27
S
Skeksis Offline
Newbie
Skeksis  Offline
Newbie
S

Joined: Oct 2007
Posts: 27
Just saw this thread for the first time, this is a great contribution, thank you grafton, i've been looking for something like this for a while. also thanks to reigel seven for converting it to c-script.

Re: Projective Texture Mapping - Spotlight Flashl [Re: Skeksis] #181159
02/16/08 09:17
02/16/08 09:17
Joined: Oct 2007
Posts: 27
S
Skeksis Offline
Newbie
Skeksis  Offline
Newbie
S

Joined: Oct 2007
Posts: 27
I was just trying the c-script version, it works great but I was wondering if it's possible to convert the shadow mapping aswell.
Also, I noticed that the material only reacts to the spotlight, I don't really know anything about shaders, but I was wondering how difficult it would be to add support for a few more lights.

Re: Projective Texture Mapping - Spotlight Flashl [Re: Skeksis] #181160
02/16/08 19:23
02/16/08 19:23
Joined: May 2007
Posts: 7
R
Reigel_Seven Offline
Newbie
Reigel_Seven  Offline
Newbie
R

Joined: May 2007
Posts: 7
Yeah, the shadow mapping can be converted very easily, but for some reason I can't even see the shadows on my computer, whether I'm running the C-Script version or the Lite-C version. I can't figure out why.

Anywho, I'm working on adding support for a few more lights, but it may take a while, considering I know NOTHING about shader programming. I'm hoping I can basically just cut and paste from the DOOM 3 lighting shader. I'll post after I give it a try.

Re: Projective Texture Mapping - Spotlight Flashl [Re: Reigel_Seven] #181161
02/17/08 09:19
02/17/08 09:19
Joined: Oct 2007
Posts: 27
S
Skeksis Offline
Newbie
Skeksis  Offline
Newbie
S

Joined: Oct 2007
Posts: 27
This will be an awesome contribution if you successfully add support for multiple lights. I hope you can figure it out, good luck.

Re: Projective Texture Mapping - Spotlight Flashl [Re: Skeksis] #181162
02/17/08 13:19
02/17/08 13:19
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
what would be a good addition for realistic purpose:

get the dot product of the model normal and the normal from vertex to cam position and then use it with the "alpha" of the projection. So that only faces facing the light get lighted.

Page 3 of 5 1 2 3 4 5

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1