alpha fading effect

Blitz3D Forums/Blitz3D Programming/alpha fading effect

skyfire1(Posted 2005) [#1]
i noticed that in some 3d person shooters, they use a effect that makes a surface gradually become invisible the closer they're are to the camera. how would i accomplish a similiar effect in blitz3d?


Eric(Posted 2005) [#2]
EntityAutoFade ... If I remember correctly.

Regards,
Eric

Yep...Just checked

EntityAutoFade entity,near#,far#
Parameters:
entity - entity handle
near# - distance in front of the camera at which entity's will start being faded
far# - distance in front of the camera at which entity's will stop being faded (and will be invisible)
Description:
Enables auto fading for an entity. This will cause an entity's alpha level to be adjusted at distances between near and far to create a 'fade-in' effect.


skyfire1(Posted 2005) [#3]
but i need to fade individual surfaces on the mesh the closer they get to the camera..


sswift(Posted 2005) [#4]
He's got it backwards. :-)

; -------------------------------------------------------------------------------------------------------------------
; This function allows you to do the reverse of a linear interpolation between two values.
;
; Instead of specifying the tween value, you specify the value which you want the know the tween of.
;
; Essentially, this function will tell you where a value is between two other values.  If the value is between
; the two values, then the result will be in the range of 0..1.
; -------------------------------------------------------------------------------------------------------------------
Function AniBOB_InverseTween#(X1#, X2#, Median#)
	
	; If the difference between x1 and x2 is 0, then there is no tween value which will give you the value of
	; median, unless median is equal to x1 or x2, in which case all tween values will give you the correct result.
	; So we just return 0 for the tweening value if the difference is 0.

	If (X2# - X1#) <> 0
		Return (Median# - X1#) / (X2# - X1#)
	Else
		Return 0
	EndIf
	
End Function



Use this.

X2 should be the distance at which you want the entity to be opaque, and X1 should be the distance at which you want it to be transparent. Median# is the current distance of the object from the camera. You can use the EntityDistance function to get this. Or use D# = Sqr((X1#-X2#)^2 + (Y1#-Y2#)^2 + (Z1#-Z2#)^2)

Then take the number that comes out of this function, and if it is greater than 1, set it to 1. And if it is less than 0, set it to 0.

Calculate this value every frame, and set the entity's alpha to it. Then your entity will fade in as it approaches the camera.


aab(Posted 2005) [#5]
ar...
It is possible through editing VertexAlpha() but it isnt something i would do realtime: It would probobly be faster composing objects of various smaller objects and using something like :
EntityAlpha entity,(DistanceToCamera#/CloseToStartFading#)


sswift(Posted 2005) [#6]
EntityAlpha will do the job, no need to use vertex alpha.


jfk EO-11110(Posted 2005) [#7]
Like sswift said, use something like

dis#=entitydistance(camera,character)
 char_al#=1.0
 if dis#<2.0
  char_al#= dis#/2.0
 endif
 entityalpha character, char_al#

Where 2.0 may be replaced by a variable too.