The MASM Forum

General => The Workshop => Topic started by: Farabi on May 29, 2012, 09:27:22 PM

Title: [OpenGL]Real time Shadow
Post by: Farabi on May 29, 2012, 09:27:22 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: 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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on May 29, 2012, 11:27:44 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on May 31, 2012, 03:02:03 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 02, 2012, 02:32:16 AM
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?
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 02, 2012, 12:53:58 PM
(http://ompldr.org/vZTF6cQ/shadow.PNG)

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.
Title: Re: [OpenGL]Real time Shadow
Post by: 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.
Title: Re: [OpenGL]Real time Shadow
Post by: dedndave on June 02, 2012, 10:08:54 PM
we are all waiting for you to figure it out, so we can learn from you   :P
Title: Re: [OpenGL]Real time Shadow
Post by: 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  ;)
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 03, 2012, 12:16:15 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 04, 2012, 01:27:25 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 06, 2012, 10:16:40 PM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: dedndave on June 07, 2012, 12:37:56 AM
i googled "opengl vista problem" and got over 2 million hits   :P
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 08, 2012, 10:32:29 AM
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.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 09, 2012, 06:30:37 PM
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://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/282679_3558214914129_1306289698_n.jpg)
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 12, 2012, 04:04:17 PM
(http://a1.sphotos.ak.fbcdn.net/hphotos-ak-snc7/295074_3570261855295_1309429737_n.jpg)

Hufff, after a long time strugling I found a way, anyway, a game company contacting me to join them. Great news. They saw all of this and willing want me to join them. Im a lucky guy.

Anyway, it is a pain in the ass handling with a weird bug on VGA drivers. There is a lot of tech that are not working. I think my tech here is the only tech they did not know so it was worked. If the newest driver make this things gone, I will always buy nVidia card.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 12, 2012, 04:35:57 PM
(http://a3.sphotos.ak.fbcdn.net/hphotos-ak-ash3/599825_3570349257480_1132172378_n.jpg)

Now I know how to made this kind of light. I'll try to make it realtime.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 15, 2012, 12:44:44 AM
Another realtime shadow and physic Demo
(http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/s480x480/246444_3579522246799_2043921485_n.jpg)

http://fgameengine.googlecode.com/files/SimpleShadow.zip
http://fgameengine.googlecode.com/files/Houses.zip
Title: Re: [OpenGL]Real time Shadow
Post by: P1 on June 15, 2012, 09:18:44 AM
It appears to me, that there is two sources of light in your demo.

So it is confusing to look at.

Regards,  P1   8)
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on June 15, 2012, 09:30:01 AM
Quote from: P1 on June 15, 2012, 09:18:44 AM
It appears to me, that there is two sources of light in your demo.

So it is confusing to look at.

Regards,  P1   8)

Yes, the second demo had 2 source of lighting. I'll fix that. Thanks.
Title: Re: [OpenGL]Real time Shadow
Post by: Farabi on July 06, 2012, 04:07:19 PM
I wont gain any benefit keeping this on my own https://fgameengine.googlecode.com/files/fGESrc_J2012.zip

In fact, I had my job when I releasing the code.
Honestly, there is no cool function or math formula on it, the only thing make people interested on it is the lightmap technique that Im not telling to the others. And now the simple planar shadow.
Im working on the shadow volume right now, and after it done, there is no need to develop it further since it would be the last thing I should understand. Maybe I'll make a 3D software renderer to kill some time.