Strange Alpha

Blitz3D Forums/Blitz3D Beginners Area/Strange Alpha

Santiworld(Posted 2016) [#1]
Hi, sometimes i have the same problem with a entity with alpha < 1

in this case, i have a
waterplane = createwaterplane()
entityalpha waterplane,.8

no have diferent results if i change camerarange, camerafog.


only fix the problem when i use entityalpha waterplane,1

what can i do to fix this?

regards!


RustyKristi(Posted 2016) [#2]
Hey Santiworld, maybe you can send some info on how did you made those water planes? Is that the mirror feature built-in with b3d or are you using FastExt water?

It looks great btw :)


Rick Nasher(Posted 2016) [#3]
If using FastExt water then I'm curious how you masked the edges of the plane, for I managed to do something like that but it gave me lot's of headaches.


Guy Fawkes(Posted 2016) [#4]
Yea, I'd like to know as well =D

~GF


Santiworld(Posted 2016) [#5]
Hi!,

i'm using FastExt for the water plane.
i go to use fastext when the wind is slow, and no waves 3d.
maibe is something about the CAM - parents, i don't know.
but i found the sky = createsphere() dissapear in the reflection sometimes.

i dont know why..
if i use ENTITYALPHA WATERPLANE,1 the problem is solved.



If using FastExt water then I'm curious how you masked the edges of the plane, for I managed to do something like that but it gave me lot's of headaches.



hi!, you need to fade the horizont with this things:

make the camerafogcolor same to the cameraclscolor.
make the spheresky or just the sky color in the horizont same color of the camerafogcolor!

or use a sky with 100% transparent in the horizont, and 5 degress up fade to 100% opaque.
so you have a transparent sky horizont, and you see the fog fade with the cameraclscolor.


This is a very important when you need to see large distances!, i change the camerarange and camerafogrange
CameraRange cam,EntityDistance(cam,cam_pivot)*.1,1000000
ScaleEntity cielo,400000,200000,400000	
CameraFogRange cam,EntityDistance(cam,cam_pivot)*.1,2000000

If view => 2 Then ;inside view
		CameraRange cam,.1,10000
		ScaleEntity cielo,1000,500,1000	
	End If



sorry my english, if i don't understand the question right, make the question again please! :)


if you won't i can upload a scene with water, sky, fog, cam, light, etc for you.


my scene have Stars sky for the night, i use alpha to change nights and days, in storm i make the sky grey and add clouds and rain.


Santiworld(Posted 2016) [#6]
share code functions
cam created.
createwater
update_reflection_and_refraction
Create_sky

some part of the code is off with comention ;, becouse i testing diferent ways to improve the graphics.

Function crear_cielo()
	
	e#=3.5 
	e2# = 1.1;.9
	c1 = 190*e2;50*e
	c2 = 200*e2;60*e
	c3 = 235*e2;70*e
	;CameraRange cam,1,10000
	CameraFogColor cam,c1,c2,c3
	;CameraFogRange cam,2000,5000
	CameraClsColor cam,c1,c2,c3
	
	cielo = CreateSphere(16)
	FlipMesh cielo
	;cielo = LoadMesh("objetos\sky\cielo.b3d")
	EntityTexture cielo,LoadTexture("objetos\sky\cielo.bmp")
	ec# = 34000
	ScaleEntity cielo,ec,ec,ec
	;EntityColor cielo,100,100,255
	EntityFX cielo,1+8
	;FlipMesh cielo
	;EntityOrder cielo,9999
	UpdateNormals cielo
	surf = GetSurface( cielo,1)
	vertices = CountVertices(surf)
	triangles = CountTriangles(surf)
	witdh = MeshWidth(cielo)
	
	For i = 0 To vertices -1
		
		y = VertexY(surf,i) *120 
		If y > 255 Then y = 255
		If y => 0 Then 
			y=Abs(y)*3
			;cielo celeste mediodia
			VertexColor surf,i,c1-y,c2-y*.5,c3-y*.35
			
			;cielo atardecer
			VertexColor surf,i,c1-y,c2-y*.5,c3-y*.35
		Else
			VertexColor surf,i,c1,c2,c3
		End If
		
		;		x=.5+Abs(VertexX(surf,i)*.01)
		;		VertexColor  surf,i, VertexRed(surf,i)*x,VertexGreen(surf,i)*x,VertexBlue(surf,i)*x
		
	Next
	
	
;	e#=10000
;	cielo = LoadMesh("objetos\sky\cielo.b3d")
;	ScaleEntity cielo,e*.3,e*.1,e*.3
;	EntityOrder cielo,99
;	EntityFX cielo,1
;	EntityShininess cielo,1
	
	e=2200
	;EntityFX cielo,1;+2
	;ScaleEntity cielo,3*e,1*e,3*e
	;EntityOrder cielo,54
	
	estrellas = CreateSphere(8);LoadMesh("objetos\sky\stars.b3d")
	t_est = LoadTexture("objetos\sky\ministars.jpg")
	ScaleTexture  t_est,.125*.25,.25*.25
	
	EntityTexture estrellas,t_est
	ec# = 4800
	ScaleEntity estrellas,ec,ec,ec
	EntityOrder estrellas,9999
	EntityFX estrellas,1
	;EntityShininess estrellas,1
	;TurnEntity estrellas,0,0,20
	FlipMesh estrellas
	
	
;	cielo = CreateSphere();LoadMesh("objetos\sky\cielo.b3d")
;	t_cielo = LoadTexture("objetos\sky\cielo1.jpg")
;	ScaleTexture t_cielo,1,.5
;	EntityTexture cielo,t_cielo
;	
;	ec# = 10000
;	ScaleEntity cielo,ec,ec*.3,ec
;	;EntityColor cielo,100,100,255
;	EntityFX cielo,1+8+16
;	FlipMesh cielo
;	EntityOrder cielo,9999
;	UpdateNormals cielo
;	TurnEntity cielo,0,130+180,0
	
	
End Function


 ; Camara y Entorno

Global cam_pivot = CreatePivot()
Global cam_pivot_2 = CreatePivot(cam_pivot)
Global cam = CreateCamera(cam_pivot_2)
MoveEntity cam,0,0,-20
PointEntity cam,cam_pivot_2
TurnEntity cam_pivot_2,30,0,0
Global camera = cam



Function CreateWater()
	
	;create distortion (bump) texture
	BumpTexture = LoadAnimTexture ( "media\water_anim.jpg", 9, 64, 64, 0, 32 )
	TextureBlend BumpTexture, FE_BUMP									; <<<< 	Новый бленд для бампа 
	ScaleTexture BumpTexture,1,1;0.0015,0.0025
	;create water plane
	WaterPlane = CreatePlane( 8); LoadMesh("water\water.b3d")		;CreatePlane();LoadMesh("media\water32.3ds")
	
	;ScaleMesh WaterPlane,20,1,20
	EntityFX WaterPlane,1
	EntityColor WaterPlane,99,88,79
	EntityColor WaterPlane,255,255,255
	EntityShininess WaterPlane,1
	;create clipplane for cut off under water	
	WaterClipplane = CreateClipplane (  WaterPlane  )					; <<<<< при создании сразу можно выровнять по заданному ентити
	AlignClipplane WaterClipplane, WaterPlane
	
	EntityColor WaterPlane,200,190,180
	
	;If g_shadow = 1 Then EntityTexture WaterPlane, shadowtexture, 0, 3
	
	
	
	AlphaCubemap = LoadTexture("media\grad.png",1+2+16+32+128)
	TextureBlend AlphaCubemap, FE_ALPHAMODULATE						; <<<<	Новый бленд для управления прозрачностью
	ClipPivot = CreatePivot()
	ClipPivotUp = CreatePivot()  :  RotateEntity ClipPivotUp,0,0,180   :   PositionEntity ClipPivotUp, 0, 0.05, 0
	
	
	
End Function



Function underwater()
	
	SoundVolume s_splash,.031
	
	If EntityY(cam,1) <= 0 Then  
		
		If UnderWaterFlag = 0 Then 
			UnderWaterFlag = 1
			PlaySound s_splash
			RotateEntity WaterPlane,180,0,0
			;EntityAlpha WaterPlane,.7
		End If
		
	Else
		
		If UnderWaterFlag = 1 Then 
			UnderWaterFlag = 0
			PlaySound s_splash
			RotateEntity WaterPlane,0,0,0
			;EntityAlpha WaterPlane,.95
			
		End If
	End If
	
	If UnderWaterFlag = 0 Then 
		ChannelVolume c_oleaje2,1-EntityY(cam,1)*.001	
		ChannelVolume c_bajoagua2,0	
		;EntityAlpha WaterPlane,1-Abs(EntityPitch(cam,1))*.00016
	Else
		ChannelVolume c_bajoagua2,.1+Abs(EntityY(cam,1))*.01	
		
	End If
	
	If UnderWaterFlag = 1 Then 
		
		h#= Abs(EntityY#(cam,1))*1
		submarina = 1
		CameraFogMode cam,True
		c1 = 0
		c2 = 200 - h
		c3 = 230 - h
		If c2 < 0 Then c2 = 0
		If c3 < 0 Then c3 = 0
		e#=.3
		
		;RotateEntity watermesh,90,0,0
		;If h < 50 Then CameraFogRange cam,1,300-h*2
		;CameraRange cam,.1,1000
		CameraFogColor cam,c1*e,c2*e,c3*e
		CameraClsColor cam,c1*e,c2*e,c3*e
		;ShowEntity caustica\entidad
		;ShowEntity grade1\entidad
		;EntityAlpha caustica\entidad,1-(h#*.005)
		;HideEntity entorno
		
		ChannelVolume c_oleaje2,0	
		;ChannelVolume c_bajoagua2,1+(h#*.005)	
		CameraFogRange cam,0,50
		CameraFogMode cam,1
		;EntityAlpha WaterPlane,.7+h*.005	
		
		EntityFX cielo,8
	Else
		EntityFX cielo,8
		
	End If
	;CameraRange cam,1,10000
	;EntityAlpha WaterPlane,1
	
End Function


Function reflejar_y_refractar_agua()
	
	
	
			; ---- рендерим отражение в текстуру (воду отключим)
		; render reflection to texture (hide water)
	
	;CameraFogMode camera,0
	HideEntity camerasprite
	
	ShowClipplane WaterClipplane
	AlignClipplane WaterClipplane, ClipPivot
	
	HideEntity WaterPlane
	
	MirrorCamera camera, WaterPlane								; вспомогательная функция - отражает камеру от плоскости
	SetBuffer TextureBuffer(ReflectTexture)
	CameraViewport camera, 0,0, TextureWidth(ReflectTexture), TextureHeight(ReflectTexture)
	ScaleEntity camera,1,Float(GraphicsHeight())/Float(GraphicsWidth()),1		; пропорция камеры должна быть как у экрана! (а наша текстура квадратная)
	RenderWorld
	RestoreCamera camera										; вспомогательная функция - восстанавливает позицию камеры после отражения
	
	
	
	; ---- рендерим в текстуру мир с водой, на которую натянуто отражение и кубемап-текстура прозрачности (отсекаем то, что выше воды, чтобы не искажалось в воде)
	; render refraction with water (set reflection texture to water)
	AlignClipplane WaterClipplane, ClipPivotUp
	
	ShowEntity WaterPlane
	EntityTexture WaterPlane, ReflectTexture, 0, 0			; <<<<<< текстура отражения
	EntityTexture WaterPlane, AlphaCubemap, 0, 1			; <<<<<< текстура прозрачности воды
	If UnderWaterFlag Then
	;	EntityAlpha WaterPlane,0.95
	Else
	;	EntityAlpha WaterPlane,0.85
	EndIf
	;EntityColor WaterPlane,255,255,255
	
	SetBuffer TextureBuffer(RefractAndReflectTexture)
	CameraViewport camera, 0,0, TextureWidth(RefractAndReflectTexture), TextureHeight(RefractAndReflectTexture)
	ScaleEntity camera,1,Float(GraphicsHeight())/Float(GraphicsWidth()),1		; пропорция камеры должна быть как у экрана! (а наша текстура квадратная)
	RenderWorld
	
	
		; ---- рендерим мир на экран, на водную поверхность кладем текстуру искажения и текстуру преломления (в ней уже есть и отражение)
		; render world (set refraction texture to water)
	
	If UnderWaterFlag
		ShowEntity camerasprite
	;	CameraFogMode camera,1
	;	CameraFogRange camera,0.5,25
	;	CameraFogColor camera,20,20,40
	Else
		HideEntity camerasprite
	;	CameraFogMode camera,1
	;	CameraFogRange camera,20,250
	;	CameraFogColor camera,212,242,244
	EndIf
	
	HideClipplane WaterClipplane
	
	
	ShowEntity WaterPlane
	EntityTexture WaterPlane, BumpTexture, (BumpTextureFrame Mod 32), 0
	EntityTexture WaterPlane, RefractAndReflectTexture, 0, 1
	EntityAlpha WaterPlane,1
	EntityColor WaterPlane,220,230,240
	EntityColor WaterPlane, 200,185,180
	ScaleTexture BumpTexture,5,5
	
	SetBuffer BackBuffer()
	CameraViewport camera, 0,0, GraphicsWidth(), GraphicsHeight()
	ScaleEntity camera,1,1,1		; восстановим пропорцию камеры
		;RenderWorld
	
	
	If (MilliSecs()-BumpTextureFrameF)>33 Then
		BumpTextureFrame = BumpTextureFrame + 1
		BumpTextureFrameF = MilliSecs()
	EndIf
	
	; ---- управление камерой + проверка под водой-ли камера, если да, то переворачиваем плоскость воды и клип-плейны
	; input management
	
		;MouseLook camera
	
		;If KeyHit(2) Then PositionEntity camera, -10.3, 1.3, 34  :  RotateEntity camera, 0, 52, 0
		;If KeyHit(3) Then PositionEntity camera, 2, 14.5, 12.8  :  RotateEntity camera, 53, -163, 0
		;If KeyHit(5) Then PositionEntity camera, 0, 3, 0  :  RotateEntity camera, 0, 0, 0
	
		; camera under water?
	If EntityY(camera,1)>=0 Then				; Камера под водой?
		UnderWaterFlag = 0
		RotateEntity WaterPlane,0,0,0
		RotateEntity ClipPivot,0,0,0
		RotateEntity ClipPivotUp,0,0,180
		PositionEntity ClipPivotUp, 0, 0.205, 0
		EntityAlpha WaterPlane,1
	Else
		UnderWaterFlag = 1
		RotateEntity WaterPlane,0,0,180
		RotateEntity ClipPivot,0,0,180
		RotateEntity ClipPivotUp,0,0,0
		PositionEntity ClipPivotUp, 0, -0.205, 0
		EntityAlpha WaterPlane,1-Abs(EntityPitch(cam,1))*.00016
	EndIf
	
	
	
	
End Function


the msg no post in forum :(


Santiworld(Posted 2016) [#7]
in this 2 pictures can see the problem.

is like sometimes the waterplane is invisible.
the fog works in the sails, in background, and you can see in the refraccion of the sails (the color of the sky is ok inside the sail mesh)

but the wather is not visible, no reflecction of the underground mesh.