News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

[OpenGL]Real time Shadow

Started by Farabi, May 29, 2012, 09:27:22 PM

Previous topic - Next topic

Farabi

At first the shadow look good. But if you run the physic engine by pressing the "O" button, you'll see when the object touch the ground the shadow is miss pointing at the ground. This was happend because I dont know the distance between each object. If I take the depth texture, can I rotate it and project it so I can know the distance where the shadow should be appear?

Here is the demo
http://ompldr.org/vZHp0ZQ/GraphicDemo.zip

"O" PLay the physic
"G" move the light source left
"J" move the light source right
"A-W-S-D" move the camera

Also, I'd like to know the CPU Usage on your computers, on my laptop it was 66%. Too heavy for such a scene.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

hutch--

Onan, it all worked here on my XP SP3, processor usage on this Intel Core2 quad with 1% to 2%, all the key operations worked correctly.

Ther was no problem with processor usage at all.

Farabi

Quote from: hutch-- on May 29, 2012, 10:11:17 PM
Onan, it all worked here on my XP SP3, processor usage on this Intel Core2 quad with 1% to 2%, all the key operations worked correctly.

Ther was no problem with processor usage at all.

Thanks. Your computer is very fast, I got 60% of CPU Usage.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

Anyone know about shadow volume? I need to know each distance where the shadow should fall, I tried to use physic engine but my computers is not fast enought for it. Shadow volume is the fastes way to do it.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

On Here, we can easly determine the distance between object with ground. But in fact, I never get it working.
http://www.angelfire.com/games5/duktroa/RealTimeShadowTutorial.htm

I got a lots of limitation on my integrated VGA, but I need to get it done. So far, I got 66% for the experimental realtime shadow with 33 FPS. I bet if I know how to determine the distance from object to ground I can do it on 66% CPU usage with 33 FPS too as long as I dont need to copy the depth texture. It is way too slow, it will turned off my laptop because of overheat. Anyone know anyway to determine between object distance to ground?
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi



This is where the shadow should fall. But I dont know how to determine the distance beetween the light source and the light fall. If I used the the depth buffer, it cost too expensive on my system and can cause my computer to shut down. There got to be some other way since I saw lots of example successfully determine the distance.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

I guess there is not much people know how to do shadowing on 3D image render. This is thing is an advance topic and only few people know it.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

we are all waiting for you to figure it out, so we can learn from you   :P

qWord

Quote from: Farabi on June 02, 2012, 06:00:17 PM
I guess there is not much people know how to do shadowing on 3D image render. This is thing is an advance topic and only few people know it.
maybe, but most people are capable to implement it based on examples and tutorials  ;)
MREAL macros - when you need floating point arithmetic while assembling!

Farabi

Quote from: qWord on June 02, 2012, 10:31:59 PM
Quote from: Farabi on June 02, 2012, 06:00:17 PM
I guess there is not much people know how to do shadowing on 3D image render. This is thing is an advance topic and only few people know it.
maybe, but most people are capable to implement it based on examples and tutorials  ;)

I tried all the example arround, but it was not dynamic, when then objec is moving, not the light, the shadow is dissappear, I want to make that the shadow is dynamically drawn everywhere with less CPU Usage.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

#10
I set up google page in here http://code.google.com/p/fgameengine/

Making a shadow system on a low end computer is pain in the ass. Im confused with playstation 2, my laptop GPU should be faster than that, but I cant beat the graphic system. The can make lots of realtime shadow, dynamic lighting and many more. I dot know how they did that.

I tried to create a tri-ray collision detect but I failed, I hope that someone can fix it for me.




fCheckSamClockDir proc uses esi edi lpTri:dword,norm:dword
LOCAL testi, testj, testk:real4
LOCAL dotprod:real4
LOCAL tmp,tmp2:real4

mov esi,lpTri
mov edi,norm

fld [esi].Tri.pt2.y
fsub [esi].Tri.pt1.y
fstp tmp

fld [esi].Tri.pt3.z
fsub [esi].Tri.pt1.z
fmul tmp
fstp tmp

fld [esi].Tri.pt3.y
fsub [esi].Tri.pt1.y
fstp tmp

fld [esi].Tri.pt2.z
fsub [esi].Tri.pt1.z
fmul tmp2
fstp tmp2

fld tmp
fsub tmp2
fstp testi
;--------------------------------------------------------------------------------

fld [esi].Tri.pt2.z
fsub [esi].Tri.pt1.z
fstp tmp

fld [esi].Tri.pt3.x
fsub [esi].Tri.pt1.x
fmul tmp
fstp tmp

fld [esi].Tri.pt3.z
fsub [esi].Tri.pt1.z
fstp tmp

fld [esi].Tri.pt2.x
fsub [esi].Tri.pt1.x
fmul tmp2
fstp tmp2

fld tmp
fsub tmp2
fstp testj
;--------------------------------------------------------------------------------
fld [esi].Tri.pt2.x
fsub [esi].Tri.pt1.x
fstp tmp

fld [esi].Tri.pt3.y
fsub [esi].Tri.pt1.y
fmul tmp
fstp tmp

fld [esi].Tri.pt3.x
fsub [esi].Tri.pt1.x
fstp tmp

fld [esi].Tri.pt2.y
fsub [esi].Tri.pt1.y
fmul tmp2
fstp tmp2

fld tmp
fsub tmp2
fstp testj
;--------------------------------------------------------------------------------

fld testi
fmul [edi].VERTEX.x
fstp tmp

fld testj
fmul [edi].VERTEX.y
fadd tmp
fstp tmp

fld testk
fmul [edi].VERTEX.z
fadd tmp
fstp dotprod

FCMP dotprod,FP4(0.)
.if SIGN?
xor eax,eax
.else
mov eax,1
.endif


ret
fCheckSamClockDir endp

fRayTriIntersect proc uses esi edi ebx lpRay:dword,lpTri:dword,lpIntersect:dword
LOCAL v1:VERTEX
LOCAL v2:VERTEX
LOCAL norm:VERTEX
LOCAL dotprod:real4
LOCAL t:real4
LOCAL tmp,tmp2:real4
LOCAL PCHECK:Tri
LOCAL q:qword
LOCAL buff[256]:dword

mov esi,lpTri
mov edi,lpRay
mov ebx,lpIntersect

invoke Vec_Sub,addr v1,addr [esi].Tri.pt2,addr [esi].Tri.pt1
invoke Vec_Sub,addr v2,addr [esi].Tri.pt3,addr [esi].Tri.pt2

invoke Vec_CrossProduct,addr norm,addr v1,addr v2
invoke Vec_DotProduct,addr norm,addr [edi].Ray.vector
fstp dotprod

FCMP dotprod,FP4(0.)
jl @f
xor eax,eax
ret
@@:

fld [edi].Ray.linept.x
fsub [esi].Tri.pt1.x
fmul norm.x
fstp tmp
fld [edi].Ray.linept.y
fsub [esi].Tri.pt1.y
fmul norm.y
fadd tmp
fstp tmp
fld [edi].Ray.linept.z
fsub [esi].Tri.pt1.z
fmul norm.z
fadd tmp
fchs
fstp tmp

fld norm.x
fmul [edi].Ray.vector.x
fstp tmp2
fld norm.y
fmul [edi].Ray.vector.y
fadd tmp2
fstp tmp2
fld norm.z
fmul [edi].Ray.vector.z
fadd tmp2
fstp tmp2

fld tmp
fdiv tmp2
fstp t

FCMP t,FP4(0.)
jnl @f
xor eax,eax
dec eax
ret
@@:

fld [edi].Ray.vector.x
fmul t
fadd [edi].Ray.linept.x
fstp [ebx].VERTEX.x

fld [edi].Ray.vector.y
fmul t
fadd [edi].Ray.linept.y
fstp [ebx].VERTEX.y

fld [edi].Ray.vector.z
fmul t
fadd [edi].Ray.linept.z
fstp [ebx].VERTEX.z

invoke MemCopy,lpTri,addr PCHECK,sizeof Tri
invoke MemCopy,ebx,addr PCHECK.pt3,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
invoke MemCopy,addr [esi].Tri.pt2,addr PCHECK.pt1,sizeof VERTEX
invoke MemCopy,addr [esi].Tri.pt3,addr PCHECK.pt2,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
invoke MemCopy,addr [esi].Tri.pt3,addr PCHECK.pt1,sizeof VERTEX
invoke MemCopy,addr [esi].Tri.pt1,addr PCHECK.pt2,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
ret
.endif
.endif
.endif



xor eax,eax
ret
fRayTriIntersect endp

fRayTriIntersect2 proc uses esi edi ebx lpRay:dword,lpTri:dword,lpIntersect:dword
LOCAL edge1[3],edge2[3],tvec[3],pvec[3],qvec[3]:real4
LOCAL det,inv_det,t,u,v:real4
LOCAL con1,con2:dword

mov esi,lpTri
mov edi,lpRay
mov ebx,lpIntersect

invoke Vec_Sub,addr edge1,addr [esi].Tri.pt2,addr [esi].Tri.pt1
invoke Vec_Sub,addr edge2,addr [esi].Tri.pt2,addr [esi].Tri.pt1

invoke Vec_CrossProduct,addr pvec,addr [edi].Ray.vector,addr edge2
invoke Vec_DotProduct,addr edge1,addr pvec
fstp det

mov con1,0
mov con2,0

FCMP det,FP4(-0.000001)
jng @f
mov con1,1
@@:

FCMP det,FP4(0.000001)
jnl @f
mov con2,1
@@:

mov eax,con1
and eax,con2
.if eax==1
dec eax
ret
.endif

fld1
fdiv det
fstp inv_det

invoke Vec_Sub,addr tvec,addr [edi].Ray.linept,addr [esi].Tri.pt1
invoke Vec_DotProduct,addr tvec,addr pvec
fmul inv_det
fstp u

mov con1,0
mov con2,0

FCMP u,FP4(0.00)
jng @f
mov con1,1
@@:

FCMP u,FP4(1.00000)
jnl @f
mov con2,1
@@:
mov eax,con1
or eax,con2
.if eax==1
dec eax
ret
.endif

fld u
fstp [ebx].VERTEX.x

invoke Vec_CrossProduct,addr qvec,addr tvec,addr edge1
invoke Vec_DotProduct,addr [edi].Ray.vector,addr qvec
fmul inv_det
fstp v

mov con1,0
mov con2,0

FCMP v,FP4(0.00)
jng @f
mov con1,1
@@:

fld u
fadd v
fstp v

FCMP v,FP4(1.00000)
jnl @f
mov con2,1
@@:
mov eax,con1
or eax,con2
.if eax==1
dec eax
ret
.endif

fld v
fstp [ebx].VERTEX.y

invoke Vec_DotProduct,addr edge2,addr qvec
fmul inv_det
fstp t

fld t
fstp [ebx].VERTEX.z
mov eax,1


ret
fRayTriIntersect2 endp


I found it here http://www.gamedev.net/topic/202886-ray-tri-intersection/
http://www.angelfire.com/fl/houseofbartlett/solutions/line2tri.html#Code

I hope by making this work I can reduce the CPU usage by 30%.


Honestly, in the end, Im not going to use my game engine to create a game, It just fun studying it. After I got the basic inner working work,  I'll use the profesional one.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

Anyone tried my application on Vista, I tried it on my litle bro laptop using Vista OS, and it doesnot working. Anyone know why? I think the OpenGL32.dll is sill on system32. But I got blank screen.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

i googled "opengl vista problem" and got over 2 million hits   :P

Farabi

What is make my shadow algorigtm did not working is bug on my sis mirage 3 driver. When I tried it on vista, it is workin fine. I think I need to change my OS to win7 maybe it will fix it.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

Okay, this one is better and faster, except the tank model causing a heavy CPU Usage becaus it has too many vertex and I had no time yet to create the silhoute algorithm, but the shadow look good.

http://fgameengine.googlecode.com/files/GraphicDemo.zip

http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165