forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   3D-программирование (http://forum.boolean.name/forumdisplay.php?f=12)
-   -   Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика? (http://forum.boolean.name/showthread.php?t=14899)

dsd 15.06.2011 19:31

Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
Скажите мне похоже что кубики отбрасывают тень на два шарика или совсем не похоже?

Еще скажите сколько фпсов это дает на вашем компе. На нетбуке с пародией на ускоритель дает с включенным дебагом до 60 фпс. В среднем 45-50.

А также, что рациональней? Создавать плоскость для отсечения при рендере объектов за тем для которого рендрится лайтмапа или просто установить камераранж на расстояние слегка меньшее, чем расстояние от теневой камеры до объекта для которого делается лайтмап?

п.с. Код должен заработать после вставки в пустое окно в блитце, ибо загружает только шрифт ариал и все.

Код:

Graphics3D 0,0,0,1
SetBuffer BackBuffer()
Dither 0
Global lightmap,shadowtex,sushi,dsd,camera,pivot,mxs#,mys#,light,fntarial,ground,groundsurf
Global aimofshadow,x#,y#,z#,groundshadowtex,timer,timerforframe
Global shadowcamera,sizeofshadow=512
;hmm...
Global supershadowcamera,testcube,supersizeofshadow=64,superlightmap,superlightmap2

kuandaa_eneo_mtihani ;init of my code
kuandaa_mazingira_kwa_ajili_ya_kivuli_cha_mega ;sets dupershadowcamera

;testscene creation
createsushi(10,15,10,7)
groundloader(16,16,10)


testentity=CreateSphere()
;ScaleMesh testcube,0.1,0.1,0.1
PositionEntity testentity,10,15,10
EntityTexture testentity,shadowtex,0,6
EntityColor testentity,255,0,0
RotateMesh testentity,45,0,45

testentity2=CreateSphere()
PositionEntity testentity2,10,3,10
EntityTexture testentity2,shadowtex,0,6

EntityFX CreateSphere(4,light),1

;end of testscene creation

;for somekind of viewing results of currently calculated lightmaps
;mmm=CreateSprite()
;PositionEntity mmm,8,10,20
;ScaleSprite mmm,4,4
;EntityTexture mmm,superlightmap,0,0
;mmmm=CreateSprite()
;PositionEntity mmmm,0,10,20
;ScaleSprite mmmm,4,4
;EntityTexture mmmm,lightmap,0,0



.maincycle
timer=CreateTimer(30)
While Not KeyHit( 1 )
timerforframe=MilliSecs()

MoveEntity light,Cos(MilliSecs()/50),0,Cos(MilliSecs()/50)
updatesushi
castshadow
castshadow2(testentity,superlightmap)
castshadow2(testentity2,superlightmap2)

RenderWorld
control(0.5)
info
Flip 0
Wend

Function kuandaa_mazingira_kwa_ajili_ya_kivuli_cha_mega()
supershadowcamera=CreateCamera(light)
CameraViewport supershadowcamera,0,0,supersizeofshadow,supersizeofshadow
CameraProjMode supershadowcamera,2
CameraClsColor supershadowcamera,105,105,105
End Function



Function FitShadow2(entity)
For z=1 To CountSurfaces(entity)
entitysurf=GetSurface(entity,z)
For i=0 To CountVertices(entitysurf)-1
CameraProject(supershadowcamera,VertexX#(entitysurf,i),VertexY#(entitysurf,i),VertexZ#(entitysurf,i))
VertexTexCoords entitysurf,i,ProjectedX#()/supersizeofshadow,ProjectedY#()/supersizeofshadow,0,1
Next
Next
End Function


Function castshadow2(selectedmesh,currentlightmap)

PointEntity supershadowcamera,selectedmesh

;zooming to object
CameraZoom supershadowcamera,0.15*Sqr(MeshWidth(selectedmesh)^2+MeshDepth(selectedmesh)^2+MeshHeight(selectedmesh)^2)
;setting texture set for lightmap and right order for cameras
        CameraProjMode camera,0
        CameraProjMode supershadowcamera,2
        TextureBlend groundshadowtex,1
        TextureBlend lightmap,0
        TextureBlend shadowtex,1
       
        ; for not rendring objects behind of current
        clipplane=CreateSprite()
        EntityColor clipplane,105,105,105
        ScaleSprite clipplane,5,5
        PositionEntity clipplane,EntityX(selectedmesh,1),EntityY(selectedmesh,1),EntityZ(selectedmesh,1)
        HideEntity selectedmesh
RenderWorld
        ;reseting for normal render
        ShowEntity selectedmesh
        TextureBlend groundshadowtex,0
        TextureBlend lightmap,5
        TextureBlend shadowtex,0
        ;aplying results
FitShadow2(selectedmesh)       
TextureCoords currentlightmap,1
EntityTexture selectedmesh,currentlightmap,0,7

CopyRect 0,0,supersizeofshadow,supersizeofshadow,0,0,BackBuffer(),TextureBuffer(currentlightmap)
CameraProjMode camera,1
CameraProjMode supershadowcamera,0
        ;clearing entitys which become totaly useless
        FreeEntity clipplane

End Function

Function kuandaa_eneo_mtihani()

pivot=CreatePivot()
PositionEntity pivot,0,5,0

camera=CreateCamera(pivot)
RotateEntity camera,0,0,0
CameraProjMode camera,1
CameraClsColor camera,120,120,250
CameraFogMode camera,1
CameraFogRange camera,90,120
CameraFogColor camera,120,120,250

light=CreateLight()
PositionEntity light,0,100,0

fntarial=LoadFont("Arial",16,1)
SetFont fntarial

AimOfShadow=CreatePivot()


groundshadowtex=CreateTexture(1,1,256)
SetBuffer TextureBuffer(groundshadowtex)
Color 105,105,105
Line 0,0,1,1
SetBuffer BackBuffer()

lightmap=CreateTexture(sizeofshadow,sizeofshadow,256)
TextureBlend lightmap,3
TextureCoords lightmap,1

superlightmap=CreateTexture(supersizeofshadow,supersizeofshadow,256)
TextureBlend superlightmap,5

superlightmap2=CreateTexture(supersizeofshadow,supersizeofshadow,256)
TextureBlend superlightmap2,5



shadowtex=CreateTexture(1,1,256)
SetBuffer TextureBuffer(shadowtex)
Color 35,35,35
Line 0,0,1,1
SetBuffer BackBuffer()


shadowcamera=CreateCamera(light)
CameraViewport shadowcamera,0,0,sizeofshadow,sizeofshadow
CameraProjMode shadowcamera,0
CameraZoom shadowcamera,0.03 ; here needs function calibrate()
CameraClsColor shadowcamera,105,105,105



End Function

Function createsushi(x#,y#,z#,segments)

sushi=CreateSphere(segments)
ScaleMesh sushi,5,5,5
PositionEntity sushi,x#,y#,z#
EntityTexture sushi,shadowtex,0,6
RotateEntity sushi,30,270,0
sushisurf=GetSurface(sushi,1)

dsd=CreatePivot()
For i=0 To CountVertices(sushisurf)-1
If VertexX(sushisurf,i)<>0 And VertexZ(sushisurf,i)<>0 Then
bsb=CreateCube(dsd)
ScaleMesh bsb,0.4,0.4,0.4
PositionEntity bsb,VertexX(sushisurf,i),VertexY(sushisurf,i),VertexZ(sushisurf,i)
EntityColor bsb,0,0,255
EntityTexture bsb,shadowtex,0,6
EndIf

Next

HideEntity sushi
End Function

Function updatesushi()

PositionEntity dsd,EntityX(sushi),EntityY(sushi),EntityZ(sushi)
RotateEntity dsd,EntityPitch(sushi),EntityYaw(sushi),EntityRoll(sushi)


TurnEntity sushi,0,0.5,0


For i=1 To CountChildren(dsd)

sinus#=Sin(MilliSecs()/20+5*i)

sinus2#=Sin(MilliSecs()/50+3*i)
ScaleEntity GetChild(dsd,i),sinus#,sinus#,sinus#
;EntityFX GetChild(dsd,i),Int(5*Sin(MilliSecs()/50+3*i))
EntityColor GetChild(dsd,i),255*sinus#,25*(1-sinus#),255*sinus#
EntityAlpha GetChild(dsd,i),Abs(sinus2#)
TurnEntity GetChild(dsd,i),0,-0.3,0.4
Next

End Function

Function control(speed#)
If KeyDown(2) Then WireFrame True Else WireFrame False

If MouseDown(2) Then
mxs#=mxs#+(MouseXSpeed()/5.0)
mys#=mys#+(MouseYSpeed()/5.0)
RotateEntity camera,mys#,-mxs#,0
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
EndIf
If KeyDown(17) Then MoveEntity camera,0,0,speed#
If KeyDown(31) Then MoveEntity camera,0,0,-speed#
If KeyDown(30) Then MoveEntity camera,-speed#,0,0
If KeyDown(32) Then MoveEntity camera,speed#,0,0
;PositionEntity pivot,EntityX(pivot),MouseZ()*3,EntityZ(pivot)

PositionEntity pivot,EntityX#(camera,1),EntityY#(camera,1),EntityZ#(camera,1)
PositionEntity camera,0,0,0

End Function

Function GroundLoader(b,d,gridsize)
Ground=CreateMesh()
GroundSurf=CreateSurface(Ground)
For y=-d To d
        For x=-b To b
                v0=AddVertex(Groundsurf,gridsize*x,Rnd(-gridsize/5,gridsize/5),gridsize*y,(x+b)/2/b,(y+d)/2/d)
        Next
Next
qvert=CountVertices(groundsurf)
For i=0 To qvert-1
v0=i
x#=VertexX#(groundsurf,V0)
y#=VertexZ#(groundsurf,V0)

bize=i+3*b                                                       
If bize>qvert-1 Then bize=qvert-1       
        For z=i To bize                                       
                If (VertexX#(groundsurf,z)-gridsize=x#) And (VertexZ#(groundsurf,z)=y#) Then v1=z
                If (VertexX#(groundsurf,z)=x#) And (VertexZ#(groundsurf,z)-gridsize=y#) Then v2=z
                If (VertexX#(groundsurf,z)-gridsize=x#) And (VertexZ#(groundsurf,z)-gridsize=y#) Then v3=z
               
        Next
       
If v0<>v1 And v2<>v3 Then AddTriangle(GroundSurf,v1,v0,v2) : AddTriangle(GroundSurf,v3,v1,v2) :v1=v2=v3=0
Next
UpdateNormals ground
EntityTexture ground,lightmap,0,1
EntityTexture ground,groundshadowtex,0,7

PositionEntity ground,0,0,0
End Function

Function FitShadow(entitysurf)

; here some magic happens

For i=0 To CountVertices(entitysurf)-1
        CameraProject(shadowcamera,VertexX#(entitysurf,i),VertexY#(entitysurf,i),VertexZ#(entitysurf,i))

                If ProjectedX()>=0 And ProjectedX()<=sizeofshadow And ProjectedY()>=0 And ProjectedY()<=sizeofshadow
                        VertexTexCoords entitysurf,i,ProjectedX#()/sizeofshadow,ProjectedY#()/sizeofshadow,0,1
                Else
                ;and here this magic bug should be 8 of 'if'
                        If ProjectedX()<0 And ProjectedY()<0 Then VertexTexCoords entitysurf,i,0,0,0,1
                        If ProjectedX()<0 And ProjectedY()>sizeofshadow Then VertexTexCoords entitysurf,i,0,1,0,1
                        If ProjectedX()>sizeofshadow And ProjectedY()<0 Then VertexTexCoords entitysurf,i,1,0,0,1
                        If ProjectedX()>sizeofshadow And ProjectedY()>sizeofshadow Then VertexTexCoords entitysurf,i,1,1,0,1
                EndIf
Next
End Function

Function CastShadow()
PositionEntity AimOfShadow,EntityX#(camera,1),0,EntityZ#(camera,1)
PointEntity shadowcamera,AimOfShadow
        CameraProjMode shadowcamera,2
        CameraProjMode camera,0
        CameraProjMode supershadowcamera,0
        TextureBlend groundshadowtex,1
        TextureBlend lightmap,0
        TextureBlend shadowtex,1
        AntiAlias True
        ClsColor 105,105,105
RenderWorld
        AntiAlias False
        TextureBlend shadowtex,0
        TextureBlend groundshadowtex,0
        TextureBlend lightmap,5
                FitShadow(GroundSurf)
                CopyRect 0,0,sizeofshadow,sizeofshadow,0,0,BackBuffer(),TextureBuffer(lightmap)

        CameraProjMode shadowcamera,0
        CameraProjMode camera,1
        CameraProjMode supershadowcamera,2
       
End Function

Function ShowTime()
Color 30,30,30
Rect 0,0,54,16
Color 200,200,200
Rect 2,2,50,12,1
Color 70,70,70
Text 2,0,CurrentTime$()



End Function
Function info()
ShowTime
If KeyDown(59) Then
          Text 200,1,"poss fps:"+(1000/(1+(MilliSecs()-timerforframe)))
        Text 280,1,"msPF: "+(MilliSecs()-timerforframe)
        WaitTimer(timer)
        Text 160,1,"fps:"+(1000/(MilliSecs()-timerforframe))
        Text 60,1,"triangles: "+TrisRendered()
Else
        Text 20,580,"F1 for additional info"
        WaitTimer(timer)
        Text 200,580,"Hold mouse(2) for mouselook. a,w,s,d for navigate"
EndIf

End Function


Извиняюсь за многословность :)

baton4ik 15.06.2011 19:34

Ответ: Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
Цитата:

Сообщение от dsd (Сообщение 191619)
kuandaa_mazingira_kwa_ajili_ya_kivuli_cha_mega ;sets dupershadowcamera

O_O
Ты случайно не тот чувак, о котором я рассказывал?
Цитата:

Сообщение от baton4ik (Сообщение 180047)
первому посоветовал blitzmax и высказал своё удивление по поводу названия его константы (он открывал код. Вот название: "TIMEBETWEENENEMYBULLETS").


dsd 15.06.2011 19:38

Ответ: Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
Не, просто после пары недель генерации разных имен суахили мне показался вполне привлекательной альтернативой :D

dsd 19.06.2011 11:23

Ответ: Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
Екзешник и скриншот

Gector 19.06.2011 12:35

Ответ: Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
FPS: 30:dontknow:(Экзешник)
Машина.
Двухядерная по 2,2
Видео GF 8500 GT
Оперативка: 2 гб

dsd 19.06.2011 14:30

Ответ: Тени. Скажите мне похоже что кубики отбрасывают тень на два шарика?
 
30 это после обрезки фпс вэйттаймером.
А максимальное возможное колво это следующее значение.
Последние значение миллисекунды на кадр.


Часовой пояс GMT +4, время: 12:45.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot