AShadow Lib : Refractive Water Question

Blitz3D Forums/Blitz3D Programming/AShadow Lib : Refractive Water Question

Hello,

Is it possible to remove some meshes/sprites from showing on the water's refraction ?

Only if you can code the D3D clipping to do that. Or maybe I didn't understand your question. I use AShadow with reflective/refractive/fog water.

ok, i have another problem, my GUI in game is build with sprites, if I turn on Glow or blur or DOF, the effects will also work on the GUI.... I really need to find a solution to exclude certain things from being process by the shaders, but how ? :/
Any help is welcome!

Those are PostProcess effects (Glow, blur, DOF). If you do your POst Process, and THEN your GUI, you shouldn't have any problems. I use FastImage, which, I think, shouldn't have issues with AShadow.

Also, if you can set your own RenderStates, then you could probably remove the effects yourself with the proper settings.

Here. I won't show you how this works. But, you'll be able to understand what Ashadow does with these RenderState codes.

;D3DCULL
Const D3DCULL_NONE				= 1
Const D3DCULL_CW				= 2
Const D3DCULL_CCW				= 3
		
;D3DSHADE_MODE
Const D3DSHADE_FLAT				= 1
Const D3DSHADE_GOURAUD			= 2
Const D3DSHADE_PHONG			= 3

;D3DFILL_MODE
Const D3DFILL_POINT				= 1
Const D3DFILL_WIREFRAME			= 2
Const D3DFILL_SOLID				= 3

;D3DSTENCILOP
Const D3DSTENCILOP_KEEP         = 1
Const D3DSTENCILOP_ZERO         = 2
Const D3DSTENCILOP_REPLACE      = 3
Const D3DSTENCILOP_INCRSAT      = 4
Const D3DSTENCILOP_DECRSAT      = 5
Const D3DSTENCILOP_INVERT       = 6
Const D3DSTENCILOP_INCR         = 7
Const D3DSTENCILOP_DECR         = 8
Const D3DSTENCILCAPS_TWOSIDED = 9

;D3DCMPFUNC
Const D3DCMP_NEVER              = 1
Const D3DCMP_LESS               = 2
Const D3DCMP_EQUAL              = 3
Const D3DCMP_LESSEQUAL          = 4
Const D3DCMP_GREATER            = 5
Const D3DCMP_NOTEQUAL           = 6
Const D3DCMP_GREATEREQUAL       = 7
Const D3DCMP_ALWAYS             = 8

;D3DBLEND
Const D3DBLEND_ZERO             = 1
Const D3DBLEND_ONE              = 2
Const D3DBLEND_SRCCOLOR         = 3
Const D3DBLEND_INVSRCCOLOR      = 4
Const D3DBLEND_SRCALPHA         = 5
Const D3DBLEND_INVSRCALPHA      = 6
Const D3DBLEND_DESTALPHA        = 7
Const D3DBLEND_INVDESTALPHA     = 8
Const D3DBLEND_DESTCOLOR        = 9
Const D3DBLEND_INVDESTCOLOR     = 10
Const D3DBLEND_SRCALPHASAT      = 11
Const D3DBLEND_BOTHSRCALPHA     = 12
Const D3DBLEND_BOTHINVSRCALPHA  = 13



; D3DRENDERSTATES
Const D3DRS_TEXTUREHANDLE      = 1
Const D3DRS_ANTIALIAS          = 2    ; D3DANTIALIASMODE
Const D3DRS_TEXTUREADDRESS     = 3
Const D3DRS_TEXTUREPERSPECTIVE = 4    ; True For perspective correction
Const D3DRS_WRAPU              = 5
Const D3DRS_WRAPV              = 6
Const D3DRS_ZENABLE            = 7    ; D3DZBUFFERTYPE (Or True/False For legacy)
Const D3DRS_FILLMODE           = 8    ; D3DFILL_MODE
Const D3DRS_SHADEMODE          = 9    ; D3DFILL_MODE
Const D3DRS_LINEPATTERN        = 10   ; D3DLINEPATTERN
Const D3DRS_MONOENABLE         = 11
Const D3DRS_ROP2               = 12
;Const D3DRS_LINEPATTERN        = 13
Const D3DRS_ZWRITEENABLE       = 14   ; True To enable z writes
Const D3DRS_ALPHATESTENABLE    = 15   ; True To enable alpha tests
Const D3DRS_LASTPIXEL          = 16   ; True For Last-pixel on lines
Const D3DRS_TEXTUREMAG         = 17   ; D3D7
Const D3DRS_TEXTUREMIN         = 18   ; D3D7
Const D3DRS_SRCBLEND           = 19   ; D3DBLEND
Const D3DRS_DESTBLEND          = 20   ; D3DBLEND
Const D3DRS_TEXTUREMAPBLEND    = 21   ; D3D7
Const D3DRS_CULLMODE           = 22   ; D3DCULL
Const D3DRS_ZFUNC              = 23   ; D3DCMPFUNC
Const D3DRS_ALPHAREF           = 24   ; D3DFIXED (long)
Const D3DRS_ALPHAFUNC          = 25   ; D3DCMPFUNC
Const D3DRS_DITHERENABLE       = 26   ; True To enable dithering
Const D3DRS_ALPHABLENDENABLE   = 27   ; True To enable alpha blending
Const D3DRS_FOGENABLE          = 28   ; True To enable fog blending
Const D3DRS_SPECULARENABLE     = 29   ; True To enable specular
Const D3DRS_ZVISIBLE           = 30   ; True To enable z checking
Const D3DRS_SUBPIXEL           = 31   ; D3D7
Const D3DRS_SUBPIXELX          = 32   ; D3D7
Const D3DRS_STIPPLEDALPHA      = 33   ; True To enable stippled alpha (RGB device only)
Const D3DRS_FOGCOLOR           = 34   ; D3DCOLOR Int ( (a shl 24) Or (r Shl 16) Or (g Shl 8) Or b )
Const D3DRS_FOGTABLEMODE       = 35   ; D3DFOGMODE
Const D3DRS_FOGSTART           = 36   ; Float Fog start (For both vertex And pixel fog) 
Const D3DRS_FOGEND             = 37   ; Float Fog End
Const D3DRS_FOGDENSITY         = 38   ; Fog Density
Const D3DRS_STIPPLEENABLE      = 39   ; 
Const D3DRS_EDGEANTIALIAS      = 40   ; True To enable edge antialiasing
Const D3DRS_COLORKEYENABLE     = 41   ; True To enable source colorkeyed textures
Const D3DRS_BORDERCOLOR        = 43   ; D3D7
Const D3DRS_TEXTUREADDRESSU    = 44   ; D3D7
Const D3DRS_TEXTUREADDRESSV    = 45   ; D3D7
Const D3DRS_MIPMAPLODBIAS      = 46   ; D3D7
Const D3DRS_ZBIAS              = 47   ; Int Z bias (D3D7, D3D8)
Const D3DRS_RANGEFOGENABLE     = 48   ; Enables range-based fog
Const D3DRS_ANISOTROPY         = 49
Const D3DRS_FLUSHBATCH         = 50
Const D3DRS_TRANSLUCENTSORTINDEPENDENT= 51 ; D3D7

; *** STENCIL OPS ***
Const D3DRS_STENCILENABLE      = 52   ; BOOL enable/disable stenciling
Const D3DRS_STENCILFAIL        = 53   ; D3DSTENCILOP To do If stencil test fails
Const D3DRS_STENCILZFAIL       = 54   ; D3DSTENCILOP To do If stencil test passes And Z test fails
Const D3DRS_STENCILPASS        = 55   ; D3DSTENCILOP To do If both stencil And Z tests pass
Const D3DRS_STENCILFUNC        = 56   ; D3DCMPFUNC fn.  Stencil Test passes If ((ref & mask) stencilfn (stencil & mask)) is True
Const D3DRS_STENCILREF         = 57   ; INT Reference value used in stencil test
Const D3DRS_STENCILMASK        = 58   ; Mask value used in stencil test  e.g (= $ffffffff)
Const D3DRS_STENCILWRITEMASK   = 59   ; Write mask applied To values written To stencil buffer e.g (= $ffffffff)

Const D3DRS_TEXTUREFACTOR      = 60   ; D3DCOLOR used For multi-texture blend
Const D3DRS_WRAP7              = 135
Const D3DRS_CLIPPING           = 136
Const D3DRS_LIGHTING           = 137
Const D3DRS_EXTENTS            = 138  ; D3D7
Const D3DRS_AMBIENT            = 139
Const D3DRS_FOGVERTEXMODE      = 140
Const D3DRS_COLORVERTEX        = 141
Const D3DRS_LOCALVIEWER        = 142
Const D3DRS_NORMALIZENORMALS   = 143
Const D3DRS_COLORKEYBLENDENABLE= 144  ; D3D7
Const D3DRS_DIFFUSEMATERIALSOURCE=145
Const D3DRS_SPECULARMATERIALSOURCE=146
Const D3DRS_AMBIENTMATERIALSOURCE= 147
Const D3DRS_EMISSIVEMATERIALSOURCE=148
Const D3DRS_VERTEXBLEND        = 151
Const D3DRS_CLIPPLANEENABLE    = 152
Const D3DRS_SOFTWAREVERTEXPROCESSING=153 ; D3D8
Const D3DRS_POINTSIZE          = 154
Const D3DRS_POINTSIZE_MIN      = 155
Const D3DRS_POINTSPRITEENABLE  = 156
Const D3DRS_MULTISAMPLEANTIALIAS=161
Const D3DRS_MULTISAMPLEMASK    = 162
Const D3DRS_PATCHEDGESTYLE     = 163
Const D3DRS_PATCHSEGMENTS      = 164 ; D3D8
Const D3DRS_DEBUGMONITORTOKEN  = 165
Const D3DRS_POINTSIZE_MAX      = 166
Const D3DRS_INDEXEDVERTEXBLENDENABLE = 167

Const D3DCLEAR_TARGET			= $00000001	;Clear target surface
Const D3DCLEAR_ZBUFFER			= $00000002	;Clear target z buffer
Const D3DCLEAR_STENCIL			= $00000004	;Clear Stencil
Const D3DCLEAR_ALL				= $00000007

Type RenderState				; BB Defaults
	Field ZEnable				; True
	Field AlphaTestEnable		; False
	Field SrcBlend				; 5	=	D3DBLEND_SRCALPHA
	Field DestBlend				; 6	=	D3DBLEND_INVSRCALPHA
	Field CullMode				; 3 = D3DCULL_CCW
	Field ZFunc					; 4 = D3DCMP_LESSEQUAL
	Field AlphaRef				; 128
	Field AlphaFunc				; 5 = D3DCMP_GREATER
	Field AlphaBlendEnable		; False
	Field ZBias					; 0
	Field StencilEnable			; False
	Field StencilFail			; 1 = D3DSTENCILOP_KEEP
	Field StencilZFail			; 1 = D3DSTENCILOP_KEEP
	Field StencilPass			; 1 = D3DSTENCILOP_KEEP
	Field StencilFunc			; 8 = D3DCMP_ALWAYS
	Field StencilRef			; 0
	Field StencilMask			; -1
	Field StencilWriteMask		; -1
End Type

Function D3D_Init()
      Direct3D7=SystemProperty$("Direct3D7")
      Direct3DDevice7=SystemProperty$("Direct3DDevice7")
      DirectDraw7=SystemProperty$("DirectDraw7")
      AppHWND=SystemProperty$("AppHWND")
      AppHINSTANCE=SystemProperty$("AppHINSTANCE")
      If Direct3D7=0 RuntimeError "FATAL ERROR: Can't get access to Drect3DDevice!"
      DX7_SetSystemProperties (Direct3D7,Direct3DDevice7,DirectDraw7,AppHWND,AppHINSTANCE)
End Function

; Use this after a D3D_Init to keep the original RenderState
Function StoreRenderState(r.RenderState)
	r\ZEnable 			= DX7_GetRenderState( D3DRS_ZENABLE)
	r\AlphaTestEnable 	= DX7_GetRenderState( D3DRS_ALPHATESTENABLE)
	r\SrcBlend			= DX7_GetRenderState( D3DRS_SRCBLEND)
	r\DestBlend			= DX7_GetRenderState( D3DRS_DESTBLEND)
	r\CullMode			= DX7_GetRenderState( D3DRS_CULLMODE)
	r\ZFunc				= DX7_GetRenderState( D3DRS_ZFUNC)
	r\AlphaRef			= DX7_GetRenderState( D3DRS_ALPHAREF)
	r\AlphaFunc			= DX7_GetRenderState( D3DRS_ALPHAFUNC)
	r\AlphaBlendEnable	= DX7_GetRenderState( D3DRS_ALPHABLENDENABLE)
	r\ZBias				= DX7_GetRenderState( D3DRS_ZBIAS)
	r\StencilEnable		= DX7_GetRenderState( D3DRS_STENCILENABLE)
	r\StencilFail		= DX7_GetRenderState( D3DRS_STENCILFAIL)
	r\StencilZFail		= DX7_GetRenderState( D3DRS_STENCILZFAIL)
	r\StencilPass		= DX7_GetRenderState( D3DRS_STENCILPASS)
	r\StencilFunc		= DX7_GetRenderState( D3DRS_STENCILFUNC)
	r\StencilRef		= DX7_GetRenderState( D3DRS_STENCILREF)
	r\StencilMask		= DX7_GetRenderState( D3DRS_STENCILMASK)
	r\StencilWriteMask	= DX7_GetRenderState( D3DRS_STENCILWRITEMASK)
End Function

; Use this for every screen refresh, to bring the RenderState back to original values
Function RestoreRenderState(r.RenderState)
	DX7_SetRenderState(D3DRS_ZENABLE,			r\ZEnable)
	DX7_SetRenderState(D3DRS_ALPHATESTENABLE,	r\AlphaTestEnable)
	DX7_SetRenderState(D3DRS_SRCBLEND,			r\SrcBlend)
	DX7_SetRenderState(D3DRS_DESTBLEND,			r\DestBlend)
	DX7_SetRenderState(D3DRS_CULLMODE,			r\CullMode)
	DX7_SetRenderState(D3DRS_ZFUNC,				r\ZFunc)
	DX7_SetRenderState(D3DRS_ALPHAREF,			r\AlphaRef)
	DX7_SetRenderState(D3DRS_ALPHAFUNC,			r\AlphaFunc)
	DX7_SetRenderState(D3DRS_ALPHABLENDENABLE,	r\AlphablendEnable)
	DX7_SetRenderState(D3DRS_ZBIAS,				r\ZBias)
	DX7_SetRenderState(D3DRS_STENCILENABLE,		r\StencilEnable)
	DX7_SetRenderState(D3DRS_STENCILFAIL,		r\StencilFail)
	DX7_SetRenderState(D3DRS_STENCILZFAIL,		r\StencilZFail)
	DX7_SetRenderState(D3DRS_STENCILPASS,		r\StencilPass)
	DX7_SetRenderState(D3DRS_STENCILFUNC,		r\StencilFunc)
	DX7_SetRenderState(D3DRS_STENCILREF,		r\StencilRef)
	DX7_SetRenderState(D3DRS_STENCILMASK,		r\StencilMask)
	DX7_SetRenderState(D3DRS_STENCILWRITEMASK,	r\StencilWriteMask)
End Function


This is my func_d3d.bb that I use in conjunction with my own version of Ashadow.bb, that uses these constants. I changed all the numbers with these so I can figure out what is going on in this complex set of tools. I suggest you do the same.

Cheers.

after PostProcess render, simply use RenderEntity(MySprite) and it will not be affected by bloom, DOF or any other postproces VFX

yeah, but the problem of doing that appears when you are working with other libraries as spritecandy or similars... You cannot do 'renderentity(entity)' because that part is done by the own function of the lib...

I've worked with FastImage and it works fine.
I start to work with fastfimage for this issue...

Regards!

..yup..thats truth if you are not using parent as a render entity...if you create pivot and make it parent for whole gui elements, and then using Rendernetity(CreatedParentPivot) then its will do work just fine...I tried that with Alpha GUI and its working just fine...I didnt try SpriteCandy but it should be same I think...as for FastImage, I find that its not working well on ATI cards(all sprites shown at the same time, regardless are they hidden or shown)..

Thanks everyone!

But I don't think I am understanding, I spent 2 hours reading the Ashadow.bb but I just can't get anywhere.
Here a simple code, trying to use 'renderentity()' but, looks like i am missing something?

Include "AShadowBBinclude/Ashadow.bb"

Graphics3D  800,600,16,2
SetBuffer BackBuffer()

cam=CreateCamera()

Ref_Glow_DarkPower=5
Ref_Glow_BlurPower=3
Ref_BlSprAlpha#=.22
CreateGlow cam, 180, 135 ,.4,.8
Ref_Glow_ON=0

CreateBlur cam,.0

CreateDOF ( cam, 4, 15, 1, 3, 0.35)
Ref_DOF=0

Pivottest = CreatePivot()
Spritetest = CreateSprite(Pivottest) ; ACreateSprite(Pivottest)
PositionEntity Pivottest,0,0,10

Pivottest2 = CreatePivot()
Spritetest2 = CreateSprite(Pivottest2)
EntityColor Spritetest2,255,0,0
PositionEntity Pivottest2,-1,0,15

Pivottest3 = CreatePivot()
Spritetest3 = CreateSprite(Pivottest3)
EntityColor Spritetest3,0,255,0
PositionEntity Pivottest3,-2,0,17

While Not KeyHit(1)
	KeyControl(cam,.01)
	mouselook(cam)
	If KeyHit(29)  Ref_Glow_ON=1-Ref_Glow_ON
	If KeyHit(33) Ref_DOF = 1 - Ref_DOF
	
	RenderWorld()		
	
	PostProcess_Render cam
	
	RenderEntity( Pivottest, cam)
	
	Text 5,105,"Press ''Ctrl'' for Glow-effect: "+Ref_Glow_ON
	Text 5,125,"Press ''F'' for DOF: "+Ref_DOF
	
	Flip
Wend
End

Function mouselook(ent)

	mxspd#=MouseXSpeed()*0.25
	myspd#=MouseYSpeed()*0.25

	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2	
	
	campitch#=EntityPitch(ent)+myspd#
	
	If campitch#<-85 Then campitch#=-85
	If campitch#>85 Then campitch#=85

	RotateEntity ent,campitch#,EntityYaw(ent)-mxspd#,EntityRoll(ent)
End Function
Function KeyControl(ent,mov#=1)
	If KeyDown(200) MoveEntity ent,0,0,mov
	If KeyDown(208) MoveEntity ent,0,0,-mov
	If KeyDown(205) MoveEntity ent,mov,0,0
	If KeyDown(203) MoveEntity ent,-mov,0,0
	If KeyDown(17) MoveEntity ent,0,0,mov
	If KeyDown(31) MoveEntity ent,0,0,-mov
	If KeyDown(32) MoveEntity ent,mov,0,0
	If KeyDown(30) MoveEntity ent,-mov,0,0
	If MouseDown(1) MoveEntity ent,0,0,mov
	If MouseDown(2) MoveEntity ent,0,0,-mov
End Function


Up Up ^^ please help ^^

..I'll email you working example with media when I get back home..

Sprite Candy uses a single surface system so simply do renderentity with that one used for the UI
shouldn't be too hard to find it in the sources :)

Graphics3d 1024,768,32,1
Camera=createcamera()

;loadstuff blah blah

;load one sprite and same rule apply to parent
lo=LoadTexture("lo.tga",2)
Global logo=CreateSprite(camera)
EntityTexture logo,lo
MoveEntity Logo,7,-5.5,8
PositionEntity logo,0,0,4,False
EntityOrder Logo,-1

;main loop
While Not KeyDown(1)

;your game loop stuff here blah blah

UpdateWorld
RenderWorld

;Ashadow stuff here
AUpdateWater (camera)

UpdateRefract camera

PostProcess_Render camera

;and now postprocessing stuff you want to be rendered over everything

RenderEntity (Logo,camera,0,0)




Flip False

Wend
end


Thats it..this settings working just fine if you put
parent of all HUD/GUI elements in to RenderEntity..
Settings you see here regarding Logo is for given resolution since I use to put it manually on proper position, so, suit yourself for some other screen size...I hope it helps..this working just fine here and none of my sprites or HUD is affected by Ashadow postprocessing /refracting if came over water, DOF, Bloom, etc/

thank you, but still it isn't working here ???

Please can you test that code on your computer, if you push L CTRL or F it will add some effects and it shouldn't right?

what the hell !!!!!!!!! :)

Include "AShadowBBinclude/Ashadow.bb"

Graphics3D 1024,768,32,2

;loadstuff blah blah

Camera=CreateCamera()

Ref_Glow_DarkPower=5
Ref_Glow_BlurPower=3
Ref_BlSprAlpha#=.22
CreateGlow Camera, 180, 135 ,.4,.8
Ref_Glow_ON=0

CreateBlur Camera,.0

CreateDOF ( Camera, 4, 15, 1, 3, 0.35)
Ref_DOF=0

;load one sprite and same rule apply to parent
;lo=LoadTexture("wall_00.jpg",2)
Global logo=CreateSprite(Camera)
;EntityTexture logo,lo
MoveEntity Logo,7,-5.5,8
PositionEntity logo,0,0,4,False
EntityOrder Logo,-1

;main loop
While Not KeyDown(1)

;your game loop stuff here blah blah
	If KeyHit(29)  Ref_Glow_ON=1-Ref_Glow_ON 	;L CTRL
	If KeyHit(33) Ref_DOF = 1 - Ref_DOF				;F
	
UpdateWorld
RenderWorld

;Ashadow stuff here
AUpdateWater (Camera)

UpdateRefract Camera

PostProcess_Render Camera

;and now postprocessing stuff you want to be rendered over everything

RenderEntity (Logo,Camera,0,0)

Text 10,10,Ref_Glow_ON
Text 10,20,Ref_DOF

Flip False

Wend
End


I'm in the ofice right now..I'll post it when i came back together with media I used and one compiled version..