|
2 registered members (TedMar, TipmyPip),
6,862
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Fade out based on angle
#61366
12/31/05 07:32
12/31/05 07:32
|
Joined: Jun 2001
Posts: 385 Eastern Washington State
Zio
OP
Senior Member
|
OP
Senior Member
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
Serious User
|
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 threadand 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: Zio]
#61369
01/24/06 11:52
01/24/06 11:52
|
Joined: Jun 2001
Posts: 385 Eastern Washington State
Zio
OP
Senior Member
|
OP
Senior Member
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
Serious User
|
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: Zio]
#61372
02/25/06 22:33
02/25/06 22:33
|
Joined: Aug 2000
Posts: 7,490
Orange Brat

Senior Expert
|

Senior Expert
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
|
|
|
|