Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,459 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Fade out based on angle #61366
12/31/05 07:32
12/31/05 07:32
Joined: Jun 2001
Posts: 385
Eastern Washington State
Z
Zio Offline OP
Senior Member
Zio  Offline OP
Senior Member
Z

Joined: Jun 2001
Posts: 385
Eastern Washington State
I'm trying to make sprites that fade out when the camera looks away from them. Example, when the camera is facing directly at a sprite, the sprite's alpha is 100, but when the camera is facing 90* in either direction, the sprite's alpha is 0.

I'm struggling to get this working with regular programming, and I'm very very close, but my math is too weak and I just can't get it right.

As I've pulled out all my hair, I decided to see if a shader could do this and if so, maybe I could talk/bribe someone into making one for me since I can't write shaders myself.

Re: Fade out based on angle [Re: Zio] #61367
12/31/05 10:44
12/31/05 10:44
Joined: Oct 2003
Posts: 1,550
United Kingdom
indiGLOW Offline
Serious User
indiGLOW  Offline
Serious User

Joined: Oct 2003
Posts: 1,550
United Kingdom
You could simply compare the angle of the sprite to the revers angles of the camera...

If the sprite <> camera.pan * -1 alter the alpha accordingly...

That would seem the simplest method to me. Of course you could use a little more code and get more info that might help you, take a look at this thread thread
and then reference the manual for vec_to_angle and associated functions.

Hope that helps
And no...not a shader i think


The Art of Conversation is dead : Discuss
Re: Fade out based on angle [Re: indiGLOW] #61368
12/31/05 18:32
12/31/05 18:32
Joined: Jun 2001
Posts: 385
Eastern Washington State
Z
Zio Offline OP
Senior Member
Zio  Offline OP
Senior Member
Z

Joined: Jun 2001
Posts: 385
Eastern Washington State
That's basically what I've been trying so far. I managed to get code that works when the sprite is facing 0. It fades just right depending on the cameras angle. However when the sprite is facing a direction other than 0, the fade messes up when the camera angle hits certian points (like 1~360, or 179~-180 it seems)

Got a lot more debugging in place now so I can watch my vars closely, maybe now I can rewrite it again and get it working.

Re: Fade out based on angle [Re: Zio] #61369
01/24/06 11:52
01/24/06 11:52
Joined: Jun 2001
Posts: 385
Eastern Washington State
Z
Zio Offline OP
Senior Member
Zio  Offline OP
Senior Member
Z

Joined: Jun 2001
Posts: 385
Eastern Washington State
I'd really like to use a shader solution for this since I can't get it working in c-script, my math is just too weak. I found something I think may help.

I was browsing through a games files and ran across a shader that sounded interesting.

Vertex Shader:
Code:
#define maxTextureCoordinate      0
#define vTextureCoordinateSetMAIN vTextureCoordinateSet0

dcl_position0 vPosition
dcl_normal vNormal

//-- transform the normal into world space
m3x3 r0.xyz, vNormal, cObjectWorldMatrix

//-- compute direction to eye
m4x3 r1.xyz, vPosition, cObjectWorldMatrix
sub r2.xyz, cCameraPosition, r1

//-- normalize direction to eye
dp3 r2.w, r2, r2
rsq r2.w, r2.w
mul r2.xyz, r2, r2.w

//-- compute texture coordinates for low angle fade
dp3 oT1.x, r0, r2
mov oT1.y, c0_0

mov oT0, vTextureCoordinateSetMAIN



By the comments, that sounds like just the sort of thing I'm looking for. But I know absolutely nothing when it comes to shaders, so I can't edit it myself or anything, but I figured maybe someone here could make sense of it and write up something I could use. Then again, someone who knows shader asm can see what it's doing, and could probably tell me the c-script alternative. That'd be awesome too! The comments almost tell me enough to write a c-script version, but my math is extremely weak and I just don't know how to use the vec_* commands well enough to do what it says it's doing.

Anyway, there is also a pixel shader that goes with it, but the file appears to be corrupt so I'm not sure if any important parts are missing:

Pixel Shader:
Code:
// sample diffuse texture map
tex t0
tex t1

//fade at low angles
mul r0, r0, t1.a // *corrupt looking text here that wont paste*



I don't know if thats of any use to you guys, but if it is, I would be VERY grateful if someone could put it together for me. My nebula's would look so much better if I could eliminate the sharp hard looking effect you get when looking at a sprite from the 'side'.

Re: Fade out based on angle [Re: Zio] #61370
02/13/06 05:11
02/13/06 05:11
Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
BlueBeast Offline
Serious User
BlueBeast  Offline
Serious User

Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
I'd like to bump this because I'd like something like this as well!


Any takers?

Jason


Gamestudio Pro 6.4
Pentium 4 3.0 GHz 800MHz BUS
AtiRadeon 9800 pro 256Mb 21" Monitor
1 Gig DDR RAM
36 Gig RAPTOR SATA+ 120 Gig SATA
SB Audigy 2 w/ 450 watt Logitech Z680 5.1

www.nordicepitaph.com
Re: Fade out based on angle [Re: BlueBeast] #61371
02/13/06 16:21
02/13/06 16:21
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
you can just do a dot product in the vertex shader and use the result to multiply with your alpha in the pixel shader:

define an hlsl function like this:
float4 Dofresnel(float3 N,float3 P)
{
float3 D = (float3)vecViewPos-P;
return (1 * dot(N,normalize(D)));
}

somewhere in your vertex shader :
float3 N = normalize(mul(inNormal,matWorld));
float3 P = mul(inPos,matWorld);
Out. fresnel = Dofresnel(N,P);

and then in your pixel shader just:
half fres=saturate(In.fresnel*3);
color.a=color.a*fres;


obviously this isn't complete code.. but it gives you the idea. I use this code for a fresnel lighting effect, but the principle is the same.
dot(worldnormal, normalize(viewpos-worldposition))


Sphere Engine--the premier A6 graphics plugin.
Re: Fade out based on angle [Re: Zio] #61372
02/25/06 22:33
02/25/06 22:33
Joined: Aug 2000
Posts: 7,490
O
Orange Brat Offline

Senior Expert
Orange Brat  Offline

Senior Expert
O

Joined: Aug 2000
Posts: 7,490
Quote:

I'm trying to make sprites that fade out when the camera looks away from them. Example, when the camera is facing directly at a sprite, the sprite's alpha is 100, but when the camera is facing 90* in either direction, the sprite's alpha is 0.

I'm struggling to get this working with regular programming, and I'm very very close, but my math is too weak and I just can't get it right.

As I've pulled out all my hair, I decided to see if a shader could do this and if so, maybe I could talk/bribe someone into making one for me since I can't write shaders myself.




AUM 34 and 36 has something similar to this(updated 36 version is below). It's a sun flare/glare script. When you look towards the sun entity, the panel's alpha increases and vice versa:

Code:

var angles_to_sun[3];

bmap flarepan_tga = <flarepan.tga>;

entity* aum_sun;

panel flare_pan
{
pos_x = 0;
pos_y = 0;
bmap = flarepan_tga;
flags = overlay, refresh, transparent, visible;
}

action my_own_sun
{
// my.invisible = on; // remove the comment if you want to hide the sun model
my.passable = on;
aum_sun = my;
}

starter get_sun_angles()
{
while (aum_sun == null) {wait (1);}
while (player == null) {wait (1);}
vec_set (temp.x, aum_sun.x);
vec_sub (temp.x, player.x);
vec_to_angle (angles_to_sun, temp); // got the (pan, tilt) angles from the initial position of the player to the sun
while (1)
{
camera.pan %= 360;
temp.x = 0.2 * abs(camera.pan - angles_to_sun[0]); // play with 0.2
temp.y = 0.2 * abs(camera.tilt - angles_to_sun[1]); // play with 0.2
flare_pan.alpha = 100 / ((temp.x + 1) * (temp.y + 1));
wait (1);
}
}




My User Contributions master list - my initial post links are down but scroll down page to find list to active links

Moderated by  Blink, Hummel, Superku 

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