RE: [Algorithms] Perspective shadow maps problems
Brought to you by:
vexxed72
From: Gary M. <ga...@va...> - 2002-11-21 17:42:49
|
Also, how much didyou have to play with your near clip plane to get them to work? Has this been a huge problem? Thanks again, Gary > -----Original Message----- > From: Tamas Schlagl [mailto:Tam...@cl...] > Sent: Thursday, November 21, 2002 2:04 AM > To: gda...@li... > Subject: Re: [Algorithms] Perspective shadow maps problems > > > Hi! > > Maybe my old psm emails help you! > > I'm playing a lot with psm, and after some "hacking" i made this: > www.clevers.com > > bye, fanthomas > > > This came form the author of the paper: > > Hmm, > > I am not a DX expert and I don't know your matrix class, but > the following > things seem suspicious to me: > > - just adding 0.5 does not map -1..1 to 0..1. Furthermore, I > guess that > emulateViewport already maps to the right range, so you > probably don't have > to do anything here. > > - why do you compute MV*P ? Do you use row or column vectors? Usually, > column > vectors are used that are multiplied to the matrices from the > right. In that > case, you have to compute P*MV, i.e. it first does the modelview > transformation and then the projection. > > - in post-perspective space, parallel lights become point > lights. So the > post-perspective light is *not* orthogonal! > > Maybe this helped, > > Marc > > > On Friday 23 August 2002 11:47, you wrote: > > Hello! > > > > > > I read your Perspective Shadow Mapping paper, after that I > try to use in > > our upcoming game called Steel Of Haste ( you can see > screenshots & movie > > at www.clevers.com ). > > So I have an working version but I have a one intresting > problem and an > > other question, please help me if you can! > > > > The problem description: > > The game use DX8.1 so the ppspace isn't the [-1,1]^3 cube, but > > [-1,1],[-1,1],[0,1] cube. > > Definetly I use one directional light. > > If I do everything like you write down on your website,I have an > > intresting effect: > > When I rotate or move my camera ( the light direction not do > > anything), the shadows start move away ( go from his > position, like i move > > the > > light direction ). On the shadow I see something like a > perspective > > distorsion from the camera. > > As I think this is because my light postition in > post-perstective > > space isn't at a right position, but why ? Maybe becouse I do some > > conversion on the lightpos.z ???? > > For a quick & dirty sollution i substract from the > cameradirection the > > cameradirection paraler part of light direction, after that > the cameradir > > is perpendicular for the light direction, > > and after this the shadow working perfectly, but i have > other atrifacts :/ > > Do you know what is the problem ??? I included the > source code of the > > matrix generation..... maybe this help a little.... > > > > The question: > > In my application a lot of big objects cast shadow, so i > decised i not > > move the camera back until every object (witch make shadow for the > screen ) > > included in the camera space, but use > > 2 shadowmap. Do you implemented the 2 shadowmap sollution > ??? How this > > working ??? > > > > > > > > Thank you, > > Tamas Schlagl > > > > > > P.S.: I hope you can read my letter, sorry, my engilsh is > very poor. :/ > > > > The source code: > > > > //..........Get the light direction................. > > LightDir.Set( GETVAR(LDir[0]), GETVAR(LDir[1]), GETVAR(LDir[2]) ); > > LightDir.Norm(); > > LightPos = -LightDir; // At now, the lightpos must > be -LightDir > > (becouse the DX can't xchange the shadowmap-z < pixel-z > equation... :( > > > > //........... my actual camera for the scene................ > > Camera_lookAt = CameraC->GetTarget(); > > CameraPos = CameraC->GetPos(); > > CameraDir = Camera_lookAt - CameraPos ; > > CameraDir.Norm(); > > > > // CameraDir -= CameraDir || LightDir; > // CameraDir = > > CameraID - ( CameraDir paraler part of LightDir ) ??????? > WHY ??????? > > CameraDir.Norm(); > > Camera_lookAt = CameraPos + CameraDir; > > > > ///.... setup the shadowmap camera.......... > > CameraCamera.Ident(); > > CameraCamera.SetupViewport( GETVAR( NearPlane ) , GETVAR( > FarPlane ), 1, > > GETVAR( Fov ), 0,0,SHADOWMAP_SIZE, SHADOWMAP_SIZE ); // get the > > nearplane & the farplane & use the real fov! > > CameraCamera.SetPos( CameraPos ); > > CameraCamera.SetTarget( Camera_lookAt ); > > CameraCamera.SetUpVector( CameraC->GetUpVector() ); > > Render->EmulateViewport( CameraCamera, 0, NULL ); > // generate > > camera matrix & projection matrix > > > > CameraMatrix = Render->GetCameraMatrix(); > // get > > the matrixes > > ProjMat = Render->GetProjectionMatrix(); > > CameraMatrix.Concat( &ProjMat ); > // > > make the viewmatrix ( MV*P ) > > > > > //............................................................ > .......... > > LightPos.Rotate_w0( CameraMatrix ); > // > > rotate the lightpos ( x,y,z,0 ) to screenspace ! > > > //............................................................ > .......... > > > > > > > //............................................................ > .......... > > HACK! We are in DX so not [-1,1] cube ! z = [0,1] !!! > > LightPos.z += 0.5f; > > Light_lookAt = cVector( 0,0,0.5 ); > > > //............................................................ > .......... > > > > //.................................. SM > camera........................ > > LightCamera.Ident(); > > LightCamera.SetupViewport( GETVAR( LightNear ), GETVAR( > LightFar ), 1, 0, > > 0,0,SHADOWMAP_SIZE,SHADOWMAP_SIZE ); > > LightCamera.SetOrtho( true ); // ORTHOGONAL VIEW!!! > > LightCamera.SetPos( LightPos ); > > LightCamera.SetTarget( Light_lookAt ); > > LightCamera.SetUpVector( cVector(0,0,1) ); // Z is > the up vector! > > Render->EmulateViewport( LightCamera, GETVAR( PlaneSize ), > NULL ); // > > generate LMV & LP > > > > LightM = Render->GetCameraMatrix(); > > LightProj = Render->GetProjectionMatrix(); > > LightM.Concat( &LightProj ); // > create the > > LightMatrix > > > > CameraCamera.SetXpos( 1 ); > > CameraCamera.SetYpos( 1 ); > > CameraCamera.SetWidht( SHADOWMAP_SIZE - 2 ); > > CameraCamera.SetHeight( SHADOWMAP_SIZE - 2 ); > > Render->SetViewport( CameraCamera, 0, &LightM ); // Use the > CCamera > > for the rendering to the shadowmap BUT the PROJECTION > MATRIX MULTIPLIDE > > WITH THE LIGHTMATRIX! > > > > LightMatrix = Render->GetCameraMatrix(); > > LightProj = Render->GetProjectionMatrix(); > > LightMatrix.Concat( &LightProj ); > // > THIS > > IS THE matrix what we use as TextureMatrix when we want to use the > > shadowmap! > > > > // LightMatrix contain: MV*P*MVL*PL > > -- > E-Mail: Mar...@me... > phone: +49 3643 583733 (fax: -3709) > > > > > This from Ulrich: > > On Aug 23, 2002 at 03:31 +0200, Tamas Schlagl wrote: > > > > The problem description: > > The game use DX8.1 so the ppspace isn't the [-1,1]^3 cube, but > > [-1,1],[-1,1],[0,1] cube. > > Definetly I use one directional light. > > If I do everything like you write down on your > website,I have an > > intresting effect: > > When I rotate or move my camera ( the light direction not do > > anything), the shadows start move away ( go from his > position, like i > move > > the > > light direction ). On the shadow I see something like > a perspective > > distorsion from the camera. > > As I think this is because my light postition in > post-perstective > > space > > isn't at a right position, but why ? Maybe becouse I do > some conversion > > on the lightpos.z ???? > > See note below... > > > The question: > > In my application a lot of big objects cast shadow, so > i decised i not > > move the camera back until every object (witch make shadow for the > screen ) > > included in the camera space, but use > > 2 shadowmap. Do you implemented the 2 shadowmap sollution > ??? Do you > know > > how this > > working ??? > > I haven't thought about that really... does it work well? > > > > //............................................................ > .......... > > HACK! We are in DX so not [-1,1] cube ! z = [0,1] !!! > > .............................. > > LightPos.z += 0.5f; > > I'm pretty sure you want this instead: > > LightPos.z = (LightPos.z + 1.0f) * 0.5f; > > It's hard to say, though -- matrix math always confuses me, and to be > honest I'm a little rusty since I haven't worked on this in a while... > > -- > Thatcher Ulrich > http://tulrich.com > > > And some other: > > Thanks for visiting my website. > > I'm very grad for receiving your mail. > My english is very poor too. > so, I can't explain all of my website in english. > > Please, look my documentation for the light matrix > to make the perspective shadow map. > > Waiting for your cool game! > Thanks. > > IMAGIRE Takashi > > -------------------------------------------------------------- > -------------- > --- > The light matrix of p.s.m. is decomposed into the following element. > > m=[View][Projection][Post Space Scaling][Post View Inverse][Light > View][Light Projection][Offset] > > View: > View matrix is to move to the position of a camera. > > 0269: D3DXVECTOR4 eye = > D3DXVECTOR4(0.0f,1.4f*MeshRadius,2.5f*MeshRadius,1); > 0270: D3DXMatrixLookAtLH(&mView, (D3DXVECTOR3*)&eye > 0271: , &D3DXVECTOR3(0,0,0) > 0272: , &D3DXVECTOR3(0,1,0)); > > Projection: > Projection matrix is to carry out perspective transformation. > With this matrix, you can control the field of view. > Because this field of view of perspective has nothig to do > with the one of > camera. > You can control the field of view appropriately according to > the resolution > of shadow map. > > 0289: q = 1.0f/(z_max-z_min); > 0292: mProjMap = D3DXMATRIX(1,0,0,0, > 0293: 0,1,0,0, > 0294: 0,0,q,1, > 0295: 0,0,-q*z_min,0) * mScale; > > Post Space Scaling: > This matrix scales the post perspective space > to made the close to the world space dimension measurements. > This projection matrix will map the z coordinates, z_min ... z_max > in the view space to 0 ... 1. > Since the range is narrow, matrix converts the coordinate to > the one which > is easy to use. > I adjust te parameters to make the unit vector located at the origin > in the original world space have the almost same magnitude after > transformed. > > 0290: float d = D3DXVec3Length((D3DXVECTOR3*)&eye); > 0291: D3DXMatrixScaling(&mScale, d, d, 10000.0f*d*d); > > Post View Inverse: > The matrix is the transformation from the post perspective > space to the > world space. > To get this matrix, you can use the same way to get a view matrix. > Like the view matrix tranforms from the world space to the > camera space, > you can think of the positon & direction in the post perspective space > as the after transformed space > (in the case of view matrix, this would be the camera space), > and D3DXMatrixLookAtLH, the origin in post perspective space > will be transformed to the origin in the space after projecting. > > 0299: D3DXVECTOR4 cent = D3DXVECTOR4(0,0,0,1); > 0300: D3DXVECTOR4 zdir = D3DXVECTOR4(0,0,1,1); > 0301: D3DXVECTOR4 udir = D3DXVECTOR4(0,1,0,1); > 0302: D3DXVec4Transform(¢, ¢, &mVPm); D3DXVec4Scale(¢, > ¢, 1.0f/cent.w); > 0303: D3DXVec4Transform(&zdir, &zdir, &mVPm); D3DXVec4Scale(&zdir, > &zdir, 1.0f/zdir.w); > 0304: D3DXVec4Transform(&udir, &udir, &mVPm); D3DXVec4Scale(&udir, > &udir, 1.0f/udir.w); > 0305: D3DXMatrixLookAtLH(&mViewI, (D3DXVECTOR3*)¢, > (D3DXVECTOR3*)&zdir, (D3DXVECTOR3*)&udir); > 0308: D3DXMatrixScaling(&mSign,-1, -1, 1); > ****: mViewI = mViewI * mSign; > > > Light View: > It is the ordinary view matrix where the light is used as camera. > > 0312: const float zoom =30.f; > 0313: D3DXVECTOR4 eyeP; > 0314: D3DXVec3Transform(&eyeP, &D3DXVECTOR3(zoom*lightDir.x, > zoom*lightDir.y, zoom*lightDir.z), &mVPI); > 0315: D3DXVec4Scale(&eyeP, &eyeP, 1.0f/eyeP.w); > 0316: D3DXMatrixLookAtLH(&mLightView, (D3DXVECTOR3*)&eyeP, > &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,1,0)); > > Light Projection: > It is the ordinary projection matrix where the light is used > as camera. > This matrix can adjust the resoluton of the screen reflected > to a shadow > map. > > 0319: const float lz_min = 20.0f; > 0320: const float lz_max = 300.0f; > 0321: D3DXMatrixPerspectiveFovLH(&mProjL > 0322: ,60.0f*PI/180.0f > 0323: ,1 > 0324: ,lz_min, lz_max > 0325: ); > > Offset: > It shifts the origin of screen to adjust the domain of screen > coordinate. > p.s.m. does not use the domain that is far from the camera, > and to use the texture effectively, this shifts the center of texture. > > 0328: D3DXMatrixTranslation(&mShift, -0.5f, 0.5f, 0); > 0329: mLP =mVPI * mLightView * mProjL * mShift; > > > > > ------------------------- other ---------------------------- > > Looks fantastic ! > Could you outline what do you mean by "in own style" please ? > It really > motivates me , could you reveal some specs (shadow map res, > visible range of > scene its applied > onto etc.) ? > > Thank you for your time > > Petr S. > > --------------- Puvodni zprava --------------- > Od: "Tamas Schlagl" <Tam...@cl...> > Odpovedet: "Tamas Schlagl" <Tam...@cl...> > Datum: Wed, 25 Sep 2002 08:24:39 +0200 > > >Hello! > > > > > >I'm implemented "in own style", you can see at > www.clevers.com (screenshots > >& movie ). > >This is a very clever trick for shadow maps, but make some > new artifacts... > > > >bye, > >Tamas Schlagl > >Lead Programmer > >Clever's Games Ltd > > > > > >----- Original Message ----- > >From: "Petr Smilek" <gu...@pr...> > >To: <gda...@li...> > >Sent: Tuesday, September 24, 2002 9:50 PM > >Subject: [Algorithms] Perspective shadow maps > > > > > >> Hi, > >> does anybody successfuly implemented and used > >> perspective shadow maps (except authors) in practice ? > >> Is there some demo showing them in action available ? > >> Thank you in advance. > >> > >> Petr S. > >> > >> > >> ------------------------------------------------------- > >> This sf.net email is sponsored by:ThinkGeek > >> Welcome to geek heaven. > >> http://thinkgeek.com/sf > >> _______________________________________________ > >> GDAlgorithms-list mailing list > >> GDA...@li... > >> https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > >> Archives: > >> http://sourceforge.net/mailarchive/forum.php?forum_id=6188 > >> > > > > > > Thanks, I'll keep trying :) > > bye, > Petr S. > > --------------- Puvodni zprava --------------- > Od: "Tamas Schlagl" <Tam...@cl...> > Odpovedet: "Tamas Schlagl" <Tam...@cl...> > Datum: Thu, 26 Sep 2002 09:44:56 +0200 > > >Hello, > > > >First of all, some specs: map res: 1024x1024, visible range: 250. > > > >So, I know 4 people, who implented this (psm), but everybody > use other > >technics for converting the light position to post > perspective space... > this > >means "in own style" :) > >The biggest problem with psm is the faliure of z, based on > perspective > >space. To avoid this you must use vertexshaders ( add some > "tolerance" > based > >on w ).... > > > > > >bye, > >Tamas Schlagl > > > >----- Original Message ----- > >From: "Petr Smilek" <gu...@pr...> > >To: "Tamas Schlagl" <Tam...@cl...> > >Sent: Wednesday, September 25, 2002 12:43 PM > >Subject: Re: [Algorithms] Perspective shadow maps > > > > > >> Looks fantastic ! > >> Could you outline what do you mean by "in own style" > please ? It really > >motivates me , could you reveal some specs (shadow map res, > visible range > of > >scene its applied > >> onto etc.) ? > >> > >> Thank you for your time > >> > >> Petr S. > > > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=6188 > |