Thanks all , just remember janbo made the house im just cleaning up after him
Quote: "Can't wait to get the Face palm and see what I missed.
give me the codez ! ... I can clean up myself ^^"
Mainly its the new Shadow_UpdateFrustumVertices you need , It makes a border based on the diagonal length to fit it perfectly to the scene.
The c code that need to get converted ( to stop more flicker ) is also in here , fWorldUnitsPerTexel basically you need the center of the depth camera to hit a texel exactly , so it dont flicker when you rotate the camera, but im getting to this later. think im going to do this in the sunvector as you can see i change this so it will be possible.
Still a mess but you asked for it, BTW: you did a great job on this janbo
function Shadow_UpdateFrustumVertices(Shadow_Distance#,LightMVPVectorAdd)
CameraVectorID=CreateVector3(GetCameraX(1),GetCameraY(1),GetCameraZ(1))
NearLeftTopVectorID=CreateVector3(Get3DVectorXFromScreen(0,0),Get3DVectorYFromScreen(0,0),Get3DVectorZFromScreen(0,0))
FarLeftTopVectorID=CreateVector3(GetVector3X(NearLeftTopVectorID)*Shadow_Distance#,GetVector3Y(NearLeftTopVectorID)*Shadow_Distance#,GetVector3Z(NearLeftTopVectorID)*Shadow_Distance#)
GetVector3Add(NearLeftTopVectorID,CameraVectorID)
GetVector3Add(FarLeftTopVectorID,CameraVectorID)
NearRightTopVectorID=CreateVector3(Get3DVectorXFromScreen(GetDeviceWidth(),0),Get3DVectorYFromScreen(GetDeviceWidth(),0),Get3DVectorZFromScreen(GetDeviceWidth(),0))
FarRightTopVectorID=CreateVector3(GetVector3X(NearRightTopVectorID)*Shadow_Distance#,GetVector3Y(NearRightTopVectorID)*Shadow_Distance#,GetVector3Z(NearRightTopVectorID)*Shadow_Distance#)
GetVector3Add(NearRightTopVectorID,CameraVectorID)
GetVector3Add(FarRightTopVectorID,CameraVectorID)
NearLeftBottomVectorID=CreateVector3(Get3DVectorXFromScreen(0,GetDeviceHeight()),Get3DVectorYFromScreen(0,GetDeviceHeight()),Get3DVectorZFromScreen(0,GetDeviceHeight()))
FarLeftBottomVectorID=CreateVector3(GetVector3X(NearLeftBottomVectorID)*Shadow_Distance#,GetVector3Y(NearLeftBottomVectorID)*Shadow_Distance#,GetVector3Z(NearLeftBottomVectorID)*Shadow_Distance#)
GetVector3Add(NearLeftBottomVectorID,CameraVectorID)
GetVector3Add(FarLeftBottomVectorID,CameraVectorID)
NearRightBottomVectorID=CreateVector3(Get3DVectorXFromScreen(GetDeviceWidth(),GetDeviceHeight()),Get3DVectorYFromScreen(GetDeviceWidth(),GetDeviceHeight()),Get3DVectorZFromScreen(GetDeviceWidth(),GetDeviceHeight()))
FarRightBottomVectorID=CreateVector3(GetVector3X(NearRightBottomVectorID)*Shadow_Distance#,GetVector3Y(NearRightBottomVectorID)*Shadow_Distance#,GetVector3Z(NearRightBottomVectorID)*Shadow_Distance#)
GetVector3Add(NearRightBottomVectorID,CameraVectorID)
GetVector3Add(FarRightBottomVectorID,CameraVectorID)
DeleteVector3(CameraVectorID)
local VectorID as integer[7]
VectorID[0]=NearLeftTopVectorID
VectorID[1]=FarLeftTopVectorID
VectorID[2]=NearRightTopVectorID
VectorID[3]=FarRightTopVectorID
VectorID[4]=NearLeftBottomVectorID
VectorID[5]=FarLeftBottomVectorID
VectorID[6]=NearRightBottomVectorID
VectorID[7]=FarRightBottomVectorID
border = CreateVector3(0,0,0)
SubstractVector3(border,FarLeftTopVectorID,FarRightBottomVectorID)
Diagonal# = getVector3Length(border)
DeleteVector3(border)
Shadow_MinX#=GetVector3X(VectorID[0])
Shadow_MinY#=GetVector3Y(VectorID[0])
Shadow_MinZ#=GetVector3Z(VectorID[0])
Shadow_MaxX#=GetVector3X(VectorID[0])
Shadow_MaxY#=GetVector3Y(VectorID[0])
Shadow_MaxZ#=GetVector3Z(VectorID[0])
for ID=1 to 7
if GetVector3X(VectorID[ID])>Shadow_MaxX#
Shadow_MaxX#=GetVector3X(VectorID[ID])
elseif GetVector3X(VectorID[ID])<Shadow_MinX#
Shadow_MinX#=GetVector3X(VectorID[ID])
endif
if GetVector3Y(VectorID[ID])>Shadow_MaxY#
Shadow_MaxY#=GetVector3Y(VectorID[ID])
elseif GetVector3Y(VectorID[ID])<Shadow_MinY#
Shadow_MinY#=GetVector3Y(VectorID[ID])
endif
if GetVector3Z(VectorID[ID])>Shadow_MaxZ#
Shadow_MaxZ#=GetVector3Z(VectorID[ID])
elseif GetVector3Z(VectorID[ID])<Shadow_MinZ#
Shadow_MinZ#=GetVector3Z(VectorID[ID])
endif
next ID
DeleteVector3(NearLeftTopVectorID)
DeleteVector3(FarLeftTopVectorID)
DeleteVector3(NearRightTopVectorID)
DeleteVector3(FarRightTopVectorID)
DeleteVector3(NearLeftBottomVectorID)
DeleteVector3(FarLeftBottomVectorID)
DeleteVector3(NearRightBottomVectorID)
DeleteVector3(FarRightBottomVectorID)
//Shadow_MaxZ#=Shadow_MaxZ#+10
// (Shadow_Distance#/9) save border when rotating y. and allow to stop some flicker.
borderx# = Diagonal# - (Shadow_MaxX# - Shadow_MinX# ) + (Shadow_Distance#/9.2)
bordery# = Diagonal# - (Shadow_MaxY# - Shadow_MinY# ) + (Shadow_Distance#/9.2)
Shadow_MaxX# = Shadow_MaxX# + borderx#
Shadow_MinX# = Shadow_MinX# - borderx#
Shadow_MaxY# = Shadow_MaxY# + bordery#
Shadow_MinY# = Shadow_MinY# - bordery#
// TODO: stop more flicker
//FLOAT fWorldUnitsPerTexel = fCascadeBound / (float)m_CopyOfCascadeConfig.m_iBufferSize;
//vWorldUnitsPerTexel = XMVectorSet( fWorldUnitsPerTexel, fWorldUnitsPerTexel, 0.0f, 0.0f );
//unitspertexel# = Diagonal# / 2048.0
CenterX#=(Shadow_MinX#+Shadow_MaxX#) * 0.50
CenterY#=(Shadow_MinY#+Shadow_MaxY#) * 0.50
CenterZ#=(Shadow_MinZ#+Shadow_MaxZ#) * 0.50
Width#=Shadow_MaxX# - Shadow_MinX#
Height#=Shadow_MaxY# - Shadow_MinY#
Depth#=Shadow_MaxZ#-Shadow_MinZ#
// TODO PE: Adjust to nearest 10 for less flicker.
// PE: Center update is not that important , we just fade away a little before.
flickerborder# = 8.0
cx = CenterX#/flickerborder# : CenterX# = cx * flickerborder#
cz = CenterZ#/flickerborder# : CenterZ# = cz * flickerborder#
cy = CenterY#/flickerborder# : CenterY# = cy * flickerborder#
Shadow_CameraNear2# = 0 //Shadow_MinZ# // Shadow_MinZ# // Shadow_CameraNear#
Shadow_CameraFar2# = Shadow_Distance# * 2.0 //Shadow_MaxZ# // Shadow_CameraFar#
sdirx# = GetVector3X(Shadow_SunVectorID) * 100.0
sdiry# = GetVector3Y(Shadow_SunVectorID) * 100.0
sdirz# = GetVector3Z(Shadow_SunVectorID) * 100.0
SetVector3(Shadow_AtVectorID,sdirx#+CenterX#,sdiry#+CenterY#,sdirz#+CenterZ#)
SetVector3(Shadow_EyeVectorID,CenterX#,CenterY#,CenterZ#)
ViewMatrixID=BuildLookAtLhMatrix4(Shadow_AtVectorID,Shadow_EyeVectorID)
ProjectionMatrixID=CreateMatrix4()
// OrthographicProjectionMatrix4(ProjectionMatrixID,Width#,Height#,Shadow_CameraNear2#,Shadow_CameraFar2#)
OrthographicProjectionMatrix4(ProjectionMatrixID,Width#,Height#,Shadow_CameraNear2#,Shadow_CameraFar2#)
ModelMatrixID=CreateMatrix4()
SetIdentityMatrix4(ModelMatrixID)
LightMVPMatrixID=CreateMatrix4()
Multiply2Matrix4(LightMVPMatrixID,ModelMatrixID,ViewMatrixID)
Multiply2Matrix4(LightMVPMatrixID,ProjectionMatrixID,LightMVPMatrixID)
SetShaderConstantArrayByName(Shadow_DepthStaticShaderID,"LightMVPVector",0,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_DepthStaticShaderID,"LightMVPVector",1,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_DepthStaticShaderID,"LightMVPVector",2,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_DepthStaticShaderID,"LightMVPVector",3,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantArrayByName(Shadow_DepthAnimationShaderID,"LightMVPVector",0,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_DepthAnimationShaderID,"LightMVPVector",1,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_DepthAnimationShaderID,"LightMVPVector",2,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_DepthAnimationShaderID,"LightMVPVector",3,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantArrayByName(Shadow_DepthStaticShader2ID,"LightMVPVector",0,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_DepthStaticShader2ID,"LightMVPVector",1,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_DepthStaticShader2ID,"LightMVPVector",2,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_DepthStaticShader2ID,"LightMVPVector",3,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantArrayByName(Shadow_DepthAnimationShader2ID,"LightMVPVector",0,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_DepthAnimationShader2ID,"LightMVPVector",1,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_DepthAnimationShader2ID,"LightMVPVector",2,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_DepthAnimationShader2ID,"LightMVPVector",3,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantArrayByName(Shadow_ShadowStaticShaderID,"LightMVPVector",0+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_ShadowStaticShaderID,"LightMVPVector",1+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_ShadowStaticShaderID,"LightMVPVector",2+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_ShadowStaticShaderID,"LightMVPVector",3+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantByName( Shadow_ShadowStaticShaderID, "shadowdist2", Shadow_Distance2#, Shadow_Distance2#, Shadow_Distance2#, Shadow_Distance2# )
SetShaderConstantByName( Shadow_ShadowStaticShaderID, "shadowdist", Shadow_Distance1#, Shadow_Distance1#, Shadow_Distance1#, Shadow_Distance1# )
SetShaderConstantByName( Shadow_ShadowStaticShaderID, "sundir", GetVector3X(Shadow_SunVectorID), GetVector3Y(Shadow_SunVectorID),GetVector3Z(Shadow_SunVectorID), Shadow_Distance1# )
SetShaderConstantArrayByName(Shadow_ShadowAnimationShaderID,"LightMVPVector",0+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,0),GetMatrix4Element(LightMVPMatrixID,4),GetMatrix4Element(LightMVPMatrixID,8),GetMatrix4Element(LightMVPMatrixID,12))
SetShaderConstantArrayByName(Shadow_ShadowAnimationShaderID,"LightMVPVector",1+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,1),GetMatrix4Element(LightMVPMatrixID,5),GetMatrix4Element(LightMVPMatrixID,9),GetMatrix4Element(LightMVPMatrixID,13))
SetShaderConstantArrayByName(Shadow_ShadowAnimationShaderID,"LightMVPVector",2+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,2),GetMatrix4Element(LightMVPMatrixID,6),GetMatrix4Element(LightMVPMatrixID,10),GetMatrix4Element(LightMVPMatrixID,14))
SetShaderConstantArrayByName(Shadow_ShadowAnimationShaderID,"LightMVPVector",3+LightMVPVectorAdd,GetMatrix4Element(LightMVPMatrixID,3),GetMatrix4Element(LightMVPMatrixID,7),GetMatrix4Element(LightMVPMatrixID,11),GetMatrix4Element(LightMVPMatrixID,15))
SetShaderConstantByName( Shadow_ShadowAnimationShaderID, "shadowdist2", Shadow_Distance2#,Shadow_Distance2#, Shadow_Distance2#, Shadow_Distance2# )
SetShaderConstantByName( Shadow_ShadowAnimationShaderID, "shadowdist", Shadow_Distance1#,Shadow_Distance1#, Shadow_Distance1#, Shadow_Distance1# )
SetShaderConstantByName( Shadow_ShadowAnimationShaderID, "sundir", GetVector3X(Shadow_SunVectorID), GetVector3Y(Shadow_SunVectorID),GetVector3Z(Shadow_SunVectorID), Shadow_Distance1# )
DeleteMatrix4(ModelMatrixID)
DeleteMatrix4(ViewMatrixID)
DeleteMatrix4(ProjectionMatrixID)
DeleteMatrix4(LightMVPMatrixID)
endfunction
All: you cant just put this in the old code and make it run , it still need a little change here and there , coming later, this is just for janbo.
best regards Preben Eriksen,