Тема: Тени (Xors3d)
Показать сообщение отдельно
Старый 02.01.2009, 10:45   #3
Максим
Оператор ЭВМ
 
Аватар для Максим
 
Регистрация: 10.11.2008
Сообщений: 29
Написано 0 полезных сообщений
(для 0 пользователей)
Ответ: Тени (Xors3d)

Насколько мне известно, эффект надо применять на каждый чайлд
Об этом я знаю , я так иделаю . Но вот когда чайлдов много , то при запуске - "долго думается" , а потом вылетает ошибка . Вот мне интересно , почему ?
;========================================================
;=                  Shadow Mapping Demo                 =
;========================================================
Include "xors3d.bb"

;initialization
xAppTitle "Shadow Mapping"
xGraphics3D 800, 600, 32, False, 1
xCreateDSS(1024, 1024)

; the size of shadowmap texture
Const SMAP_SIZE = 1024

;setting texture filtering mode
xSetTextureFiltering TF_ANISOTROPIC

;enabling antialiasing
xAntiAlias True


;objects loading
tModel=xLoadMesh("Data\map01\3dModels\map01A2.b3d")
tModel2=xLoadMesh("Data\map01\3dModels\map01A.b3d")
tModel3=xLoadMesh("Data\map01\3dModels\map01A3.b3d")
tModel4=xLoadMesh("Data\map01\3dModels\map01A4.b3d")
tModel5=xLoadMesh("Data\map01\3dModels\map01A5.b3d")
tModel6=xLoadMesh("Data\map01\3dModels\map01A6.b3d")
tModel7=xLoadMesh("Data\map01\3dModels\map01A7.b3d")

;creating the camera
cam = xCreateCamera()
xPositionEntity cam, 100, 100, 100
xRotateEntity   cam, 35, 135, 0
pivot = xCreatePivot()
cam2 = xCreateCamera(pivot)
xPositionEntity cam2, 0, 130, -130
xRotateEntity   cam2, 45, 0, 0
xCameraViewport cam2, 0, 0, SMAP_SIZE, SMAP_SIZE
xCameraClsColor cam2, 255, 255, 255
xHideEntity cam2

;creating the sun ;)
sun = xCreateSphere(16, cam2)
xScaleEntity sun, 5, 5, 5

;font loading
arial = xLoadFont("Arial", 12)

;creating the texture for a shadowmap
smap = xCreateTexture(SMAP_SIZE, SMAP_SIZE, 16 + 32 + 256) ;256 - использование float-point текстуры (D3DFMT_R32F)

;shaders loading
sm_vs1 = xLoadVertexShader("Shaders\sm_vs1.txt", "main", VS_2_0)
sm_vs2 = xLoadVertexShader("Shaders\sm_vs2.txt", "main", VS_2_0)
sm_ps1 = xLoadPixelShader("Shaders\sm_ps1.txt", "main", PS_2_0)
sm_ps2 = xLoadPixelShader("Shaders\sm_ps2.txt", "main", PS_2_0)

;main loop
While Not xKeyDown(1) Or xWinMessage("WM_CLOSE")

	;rendering the scene to the shadowmap
	xSetBuffer xTextureBuffer(smap)
	
	;switching the cameras
	xHideEntity cam
	xShowEntity cam2
	
	;setting the shaders for shadowmap rendering
	xSetEntityVertexShader tModel,sm_vs1
	xSetEntityPixelShader tModel,sm_ps1
	xSetEntityVertexShader tModel2, sm_vs1
	xSetEntityPixelShader tModel2,sm_ps1
	xSetEntityVertexShader tModel3,sm_vs1
	xSetEntityPixelShader tModel3,sm_ps1
	xSetEntityVertexShader tModel4,sm_vs1
	xSetEntityPixelShader tModel4,sm_ps1
	xSetEntityVertexShader tModel5,sm_vs1
	xSetEntityPixelShader tModel5,sm_ps1
	xSetEntityVertexShader tModel6,sm_vs1
	xSetEntityPixelShader tModel6,sm_ps1
	xSetEntityVertexShader tModel7,sm_vs1
	xSetEntityPixelShader tModel7,sm_ps1
	
	;setting the constants
	xSetVertexShaderMatrixSemantic tModel, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel2, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel3, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel4, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel5, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel6, "matWorldViewProj", WORLDVIEWPROJ
	xSetVertexShaderMatrixSemantic tModel7, "matWorldViewProj", WORLDVIEWPROJ
	
	;actually rendering
	xRenderWorld
	
	;setting the backbuufer as a rendertarget
	xSetBuffer xBackBuffer()
	
	;switching the cameras back
	xHideEntity cam2
	xShowEntity cam
	
	;setting the shaders for a final rendering
    xSetEntityVertexShader tModel,sm_ps2
	xSetEntityPixelShader tModel,sm_vs2
	xSetEntityVertexShader tModel2, sm_vs2
	xSetEntityPixelShader tModel2,sm_ps2
	xSetEntityVertexShader tModel3,sm_vs2
	xSetEntityPixelShader tModel3,sm_ps2
	xSetEntityVertexShader tModel4,sm_vs2
	xSetEntityPixelShader tModel4,sm_ps2
	xSetEntityVertexShader tModel5,sm_vs2
	xSetEntityPixelShader tModel5,sm_ps2
	xSetEntityVertexShader tModel6,sm_vs2
	xSetEntityPixelShader tModel6,sm_ps2
	xSetEntityVertexShader tModel7,sm_vs2
	xSetEntityPixelShader tModel7,sm_ps2
	
	;writing the view and projection matrices of the second camera to the additional matrix
	xSetAdditionalMatrix(cam2, 0, ADDVIEW)
	xSetAdditionalMatrix(cam2, 1, ADDPROJ)
	
	;setting the constants
    xSetVertexShaderMatrixSemantic tModel, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel, "samShadow", smap
	xSetPixelShaderInt tModel, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel, "matView", VIEW
	xSetPixelShaderEntityTexture tModel, "texBase"

	xSetVertexShaderMatrixSemantic tModel2, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel2, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel2, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel2, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel2, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel2, "samShadow", smap
	xSetPixelShaderInt tModel2, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel2, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel2, "matView", VIEW
	xSetPixelShaderEntityTexture tModel2, "texBase"

	xSetVertexShaderMatrixSemantic tModel3, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel3, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel3, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel3, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel3, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel3, "samShadow", smap
	xSetPixelShaderInt tModel3, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel3, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel3, "matView", VIEW
	xSetPixelShaderEntityTexture tModel3, "texBase"

	xSetVertexShaderMatrixSemantic tModel4, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel4, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel4, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel4, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel4, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel4, "samShadow", smap
	xSetPixelShaderInt tModel4, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel4, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel4, "matView", VIEW
	xSetPixelShaderEntityTexture tModel4, "texBase"

	xSetVertexShaderMatrixSemantic tModel5, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel5, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel5, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel5, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel5, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel5, "samShadow", smap
	xSetPixelShaderInt tModel5, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel5, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel5, "matView", VIEW
	xSetPixelShaderEntityTexture tModel5, "texBase"

	xSetVertexShaderMatrixSemantic tModel6, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel6, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel6, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel6, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel6, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel6, "samShadow", smap
	xSetPixelShaderInt tModel6, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel6, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel6, "matView", VIEW
	xSetPixelShaderEntityTexture tModel6, "texBase"

	xSetVertexShaderMatrixSemantic tModel7, "matWorldView", WORLDVIEW
	xSetVertexShaderMatrixSemantic tModel7, "matProj", PROJ
	xSetVertexShaderMatrixSemantic tModel7, "matLightView", ADDITIONAL1
	xSetVertexShaderMatrixSemantic tModel7, "matLightProj", ADDITIONAL2
	xSetVertexShaderMatrixSemantic tModel7, "matViewInv", VIEWINVERSE
	xSetPixelShaderTexture tModel7, "samShadow", smap
	xSetPixelShaderInt tModel7, "SMAP_SIZE", SMAP_SIZE
	xSetPixelShaderVectorF tModel7, "vLightPos", xEntityX(cam2, True), xEntityY(cam2, True), xEntityZ(cam2, True)
	xSetPixelShaderMatrixSemantic tModel7, "matView", VIEW
	xSetPixelShaderEntityTexture tModel7, "texBase"
	
	;camera moving
	If xKeyDown(KEY_W)    Then xMoveEntity cam,  0,  0,  1
	If xKeyDown(KEY_S)    Then xMoveEntity cam,  0,  0, -1
	If xKeyDown(KEY_A)    Then xMoveEntity cam, -1,  0,  0
	If xKeyDown(KEY_D)    Then xMoveEntity cam,  1,  0,  0
	If xKeyDown(KEY_PGUP) Then xMoveEntity cam,  0,  1,  0
	If xKeyDown(KEY_PGDN) Then xMoveEntity cam,  0, -1,  0
	;camera rotating
	If xKeyDown(KEY_UP)    Then xTurnEntity cam, -1,  0,  0, True
	If xKeyDown(KEY_DOWN)  Then xTurnEntity cam,  1,  0,  0, True
	If xKeyDown(KEY_LEFT)  Then xTurnEntity cam,  0,  1,  0, True
	If xKeyDown(KEY_RIGHT) Then xTurnEntity cam,  0, -1,  0, True
	
	;light source rotating
	xTurnEntity pivot, 0, -0.1, 0
	
	;updating and rendering the world
	xUpdateWorld
	xRenderWorld
	
	;fps and triangle counter
	xText 10, 10, "FPS: " + xGetFPS()
	xText 10, 30, "TrisRendered: " + xTrisRendered()
	xText 10, 60, "Up\Down\Letf\Right - rotate camera"
	xText 10, 80, "W\A\S\D - move camera"
	;drawing the scene
	xFlip

Wend
В чем проблема подскажите , пожалуйста .

И еще просьба . Дайте ,пожалуйста, кто-нибудь пример паралакса .
__________________
===================

===================

Последний раз редактировалось Максим, 02.01.2009 в 13:48.
(Offline)
 
Ответить с цитированием