1 registered members (AndrewAMD),
1,534
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: [REQ] Spotlight Shader
[Re: Grafton]
#341049
09/09/10 23:17
09/09/10 23:17
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hi Rei. Give this one a try... Its VERY MUCH a work-in-progress though. Its just a pixel shader so all you do is attach it to the camera and set up a few material skills. This STAND-ALONE demo should explain all you need. Just give it a level in the start of "main()" and run it...
#include <acknex.h>
#include <default.c>
MATERIAL* mTorch =
{ effect = "
Texture TargetMap;
float4 vecViewPort, vecSkill1, vecSkill5, vecSkill9;
sampler2D TexMap = sampler_state { Texture = <TargetMap>; };
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
float4 PS_Torch( float2 tex:TEXCOORD0 ):COLOR
{
float ratio = vecViewPort.x/vecViewPort.y;
float2 dir = vecSkill1.xy - tex;
float r_dist = sqrt( pow(dir.x*ratio, 2) + pow(dir.y,2) ) ;
float4 color = lerp(0, tex2D(TexMap,tex), saturate((r_dist-vecSkill1.w)*vecSkill5.w));
return saturate(tex2D(TexMap,tex) + color * vecSkill5/64);
}
//---------------------------------------------------------------------------------------
technique Torch { pass p0 { PixelShader = compile ps_2_0 PS_Torch(); } }
//---------------------------------------------------------------------------------------
";
}
VIEW* vTorch = { material = mTorch; flags=CHILD|PROCESS_TARGET; }
function main()
{ wait(1); level_load("testlevel.wmb"); wait(5);
//Position and Size Settings
var density=0.5, radius=0.35, mouse_x=0, mouse_y=0;
mTorch.skill1 = floatv(mouse_x); //X_POS == focus X position (range 0 to 1)
mTorch.skill2 = floatv(mouse_y); //Y_POS == focus Y position (range 0 to 1)
mTorch.skill3 = floatv(density); //DENSITY == small, around 0.5 (range -1 to 1)
mTorch.skill4 = floatv(radius); //RADIUS == small, around 0.2 (range 0 to 1)
//Contrast color Settings
var speed=-15;
mTorch.skill5 = floatv(125); //Torch "contrast" color Red component
mTorch.skill6 = floatv(125); //Torch "contrast" color Green component
mTorch.skill7 = floatv(125); //Torch "contrast" color Blue component
mTorch.skill8 = floatv(speed); //FADESPEED == around 0.25 (range 0 to 5)
while(1)
{
if(key_space) camera.stage = NULL; //hold space to DISABLE torch
else camera.stage = vTorch;
mouse_x = clamp(mouse_cursor.x, 0, screen_size.x)/screen_size.x;
mouse_y = clamp(mouse_cursor.y, 0, screen_size.y)/screen_size.y;
DEBUG_VAR( mouse_x, 50);
DEBUG_VAR( mouse_y, 70);
if(key_cuu) density += 0.01;
if(key_cud) density -= 0.01;
DEBUG_VAR( density, 90);
if(key_cur) radius += 0.01;
if(key_cul) radius -= 0.01;
DEBUG_VAR( radius, 110);
mTorch.skill1 = floatv(mouse_x);
mTorch.skill2 = floatv(mouse_y);
mTorch.skill3 = floatv(density);
mTorch.skill4 = floatv(radius);
if(key_pgup) speed += 0.01;
if(key_pgdn) speed -= 0.01;
DEBUG_VAR( speed, 150);
mTorch.skill8 = floatv(speed);
wait(1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: [REQ] Spotlight Shader
[Re: EvilSOB]
#341084
09/10/10 14:13
09/10/10 14:13
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Thanks EvilSOB, it is really easy to understand. I will implant it in the game to see how much faster it will be I will give you a feedback as soon as I am ready Thanks again and best regards, Rei
|
|
|
Re: [REQ] Spotlight Shader
[Re: Rei_Ayanami]
#341134
09/11/10 11:23
09/11/10 11:23
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Hiya, I really like it, because it is fast. But I also have a problem: As it takes the before rendered camera view, it does not make black (or really dark) parts brighter. As there are scenes in the game, where nearly everything should be black (of course not the flash-lighted parts), this is not so good. Another problem I have, is that I get problems when changing the resolutions. I have no idea what the problem could be.. So thank you very much and I'd like to know which improvements you want to make Best regards, Rei
Last edited by Rei_Ayanami; 09/11/10 11:38.
|
|
|
Re: [REQ] Spotlight Shader
[Re: Rei_Ayanami]
#341157
09/12/10 04:57
09/12/10 04:57
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I agree on both points, but cant do anything about them. I just hoped this "simplistic" shader would be 'good enough'. A PP shader can only work with the rendered result, and therefore cannot 'extract' the real colors from an 'un-lit' or darkened view. (UNLESS the PP shader is "creating" the darkness, rather than creating a light) Ah well... That never looks to good IMHO anyway... But I must question why arent you just using a dynamic-light for the torch? Like this?
ENTITY* torch = NULL;
void torch_startup()
{
while(!level_ent) wait(1); //wait till level is loaded.
if(torch==NULL) { torch = me = ent_create(0,0,0); }
//
// torch DEFAULT settings
my.skill1 = 1; //default to torch ON
my.skill2 = 1000; //default to lightrange 1000
//
set(me, PASSABLE|INVISIBLE|SPOTLIGHT);
vec_set(d3d_spotlightcone, vector(15,15,1)); //set torch cone-shape
while(torch)
{
if(my.skill1==1) my.lightrange = my.skill2;
else my.lightrange=0;
//
vec_set(my.x, camera.x); //follow camera position
vec_set(my.pan, camera.pan); //follow camera direction
//
wait(1);
}
}
The problem with the center-position moving on screen-changes, I THINK, is more my demo code rather than my shader. (But thats beside the point now)
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|