Jump to content

  • Log In with Google      Sign In   
  • Create Account

Carradine

Member Since 24 Aug 2001
Offline Last Active Mar 21 2016 09:04 PM

Topics I've Started

Citing Parts of Wikipedia Text in a Video Game.

29 November 2015 - 08:36 PM

Hello, I am currently developing a game that has many real object in it, and in the description of these objects I would like to show a little "educational" excerpt of text in order to add some "flavor text" to the objects in the game.  I usually just take a few sentences or a paragraph of text from a Wikipedia page and put it into the game.

 

Is there a specific way I need to cite the text?  After doing a bit of reading it looked like I could just reference the article like using "Parenthetical Reference" like so:

 

Most sandstone is composed of quartz and/or feldspar because these are the most common minerals in the Earth's crust ("Sandstone," Wikipedia: The Free Encyclopedia )

 

Later I wish to start doing my own research on the subjects, but for now I just want to get a quick bit of information into the game.

 

This this type of reference acceptable for citing text in wikipedia?  Do I need to provide more information?  Do I have to search for publish dates, or Authors each time I want to do this and add them in?

 

 


Questions converting out of outdated .X mesh files

03 June 2015 - 02:15 PM

I am currently in the process of doing some large updates to my game, and my next possibly large task is to overhaul my mesh object and animation loading system, and I am really in need of some advice and information on how to go about this next step as I have some specific reasons I want to do this.
 
The main reason I am posting this is because I really need to have some specific questions answered which will greatly help me in figuring out how I can go about this before I jump into a code overhaul that may be futile if it does not give me what I want.  My specific questions are listed at the end of the post.
 
Simply put, I want to upgrade the code I use to load objects into the game.  The main reasons I want to do this is:
 
- I am currently using only outdated ".x" file formats and would possibly want to use other formats, as I have heard that .x files may actually be not very optimal for loading purpuses.
 
-  I wish to attempt to make the load time for objects quicker, including the possiblility of asyncronous loading/multithreading options (if possible) by allowing other types of files which may be more efficient than .x files.
 
My game is coded in C++, using DirectX9.  My main loading functions are LoadMeshFromX() functions calls, which are functions that no longer exist past DirectX 9 if I ever wish to upgrade.
 
My current research leads me to think that my best bet is to convert to the "ASSIMP" library.  It seems like It is a popular library to load objects.
I am NOT looking to upgrade my actual in-game mesh/animation systems.  I still wish to store all loaded information back into the DirectX9 framework.
 
If anyone can answer or guide me in answering these questions I have It would be greatly appreciated!
 
Questions I would like to know the answer to:
 
- The overall main purpose of this is to attempt to make my load times for objects faster, if even just a small amount.  Is loading other types of exported formats (like .OBJ files) more efficient/faster than the outdated .X file format?
 
- Would convering to a new library like "ASSIMP" even be useful, since I can can convert most art assets into .x mesh/animations files from virtually any art program.  Are .x files that much different from more popular export types like .OBJ files?  Are .X files slower to load or do not hold as much useful information as other export types?
 
- Is the "ASSIMP" library the best option?  Are there other suggestions of code/libraries to use?
 
- My game is already set up to wait to load in objects while the game is running and only display them when they are loaded and complete.    Does anyone have any expereinces, or know of any other good online articles that may describe asyncronous/multithread loading of objects?
 
Thanks for any advice you can give me on this!
 

Slope-scale depth bias shadow map in HLSL

05 November 2014 - 02:41 PM

I have been searching the web for days for an answer to this, but I apparently cannot find what I need to, or I am overlooking the answer and not knowing it.

 

I have the issue of projective-aliasing happening with the terrain in my game, and apparently I need to use a slope-scale bias as well to calculate the shadow.

 

I know that the algorithm is:

m*SLOPESCALE + DEPTHBIAS

\Where m = max( | ∂z/∂x | , | ∂z/∂y | )

 

But apparently I am uncertain how to implement this inside of an HLSL shader.  I already use a depth bias, I just need to compute the slope-scale bias as well.

 

Here is my code:

 

To render the shadow map:

technique Technique0Shadow
{
pass Pass0
{
Lighting = False;
CullMode = NONE;


VertexShader = compile vs_2_0 VS_Shadow();
PixelShader  = compile ps_2_0 PS_Shadow();

}
}
shadowType VS_Shadow( vertex IN )
{
shadowType OUT;

OUT.position = mul( worldViewProj, float4(IN.position, 1) );

OUT.fDepth.z = OUT.position.z;

return OUT;
}
pixel PS_Shadow( shadowType IN )
{
    pixel OUT;

    OUT.color = float4(IN.fDepth.z,IN.fDepth.z,IN.fDepth.z,1.0f);

    return OUT;
}

And here is the HLSL code for rendering the shadow onto the terrain ( edited for simplicity )

 

Vertex Shader:

fragment TerrainVS_Shadow( vertex IN )
{
    fragment OUT;
   
    OUT.color = float4(IN.color.r,IN.color.g,IN.color.b,IN.color.a);


    OUT.hposition = mul( worldViewProj, float4(IN.position, 1) );

    OUT.vProjCoord = mul( float4(IN.position, 1), g_matTexture );
    OUT.vProjCoord2 = mul( float4(IN.position, 1), g_matTexture2 );

    float4 posWorld = mul(float4(IN.position, 1), worldMat);

    OUT.distCalc = posWorld;

    return OUT;
}

 

pixel shader, the depth bias is 0.0005f;

pixel TerrainPS_Shadow( fragment IN )
{
    pixel OUT;
    
if ( IN.vProjCoord.x/IN.vProjCoord.w < 1.0f && IN.vProjCoord.x/IN.vProjCoord.w > 0.0f && IN.vProjCoord.y/IN.vProjCoord.w < 1.0f && IN.vProjCoord.y/IN.vProjCoord.w > 0.0f )
{
    fShadowTerm = tex2Dproj( ShadowSampler, IN.vProjCoord ) < (IN.vProjCoord.z - 0.005f) ? 0.4f : 1.0f;
}

OUT.color = float4(0,0,0,fShadowTerm  );


    return OUT;
}

My question is, how do I implement the slope-scale bias into my code as well?  How do I add the equation: m*SLOPESCALE + DEPTHBIAS as the overall bias so I can eliminate my projective-aliasing?

 

Thanks for any info you can give!

 

 

 


DirectX Save Render Target as a Separate Texture

15 September 2014 - 08:43 PM

I am having an issue beginning to implement cascading shadow maps.  I already have shadows already rendering, however when I try to render multiple shadow maps with the same code, I am unable to "capture" the current shadow map texture to use for the render loop.

 

For example I am trying to render 2 shadow maps using two different ortho views:

 

for( int lpShadow = 0; lpShadow < 2; lpShadow++ )
{


    if( lpShadow == 0 )
   {
        D3DXMatrixOrthoRH( &shadowProj, (float)(d3ddm.Width)/10,(float)(d3ddm.Height)/10, -60.0f, 60.0f );
    }
    else if( lpShadow == 1 )
    {
        D3DXMatrixOrthoRH( &shadowProj, (float)(d3ddm.Width)/40,(float)(d3ddm.Height)/40, -10.0f, 10.0f );
    }


    D3DXMATRIX matLightViewProj = shadowWorld * shadowView * shadowProj;
    g_pEffect->SetMatrix( "g_matLightViewProj", &matLightViewProj );


    // Grab the old render target and depth buffer
    g_pd3dDevice->GetRenderTarget( 0, &g_pOldColorRT );
    g_pd3dDevice->GetDepthStencilSurface( &g_pOldDepthRT );
    
    // Render the scene depth to the shadow map
    g_pd3dDevice->SetRenderTarget( 0, g_pShadowSurf );
    g_pd3dDevice->SetDepthStencilSurface( g_pShadowDepth );
    
    // Clear the viewport
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0 );


    //Main rendering code loop here....
    /////////
    /////////


    // Restore the render target and depth buffer
    g_pd3dDevice->SetRenderTarget( 0, g_pOldColorRT );
    g_pd3dDevice->SetDepthStencilSurface( g_pOldDepthRT );
    SAFE_RELEASE( g_pOldColorRT );
    SAFE_RELEASE( g_pOldDepthRT );


    //Then finally put the texture into the shader
    g_pEffect->SetTexture( "tShadowMap2", g_pShadowMap );


}

I initialize the textures and surfaces like so

if( FAILED( g_pd3dDevice->CreateTexture( VGlobal::SHADOW_MAP_SIZE, VGlobal::SHADOW_MAP_SIZE, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_R32F, D3DPOOL_DEFAULT, &g_pShadowMap, NULL ) ) )
{
    MessageBox( hWnd, "Unable to create shadow map!", ERROR, MB_OK | MB_ICONERROR );
    return E_FAIL;
}


// Grab the texture's surface
g_pShadowMap->GetSurfaceLevel( 0, &g_pShadowSurf );

My issue is I am failing to understand how to loop through my Shadow Map rendering loop above, and extract the texture out of g_pShadowMap for each loop that I want to render.  I simply want to make it its own texture resource, use it in the shader for the current loop, then discard it at the end of the render process.  Right now it only uses the last surface as all of its shadow map textures which is quite obvious.

 

I have tried using StretchRect(), CopySurfaceToSurface(), many other types of copy commands, but I cannot seem to grasp how to simply copy a texture resource out of the shadow map render target, and make it a separate texture out of g_pShadowMap.

 

I have also tried to use multiple render targets for each loop, however I do not seem to understand or grasp how this is possible.  I also tried to make g_pShadowMap an array, but simply assigning the second element to the render target does not seem to work.

 

Thanks for any help!

 


Detecting a shadow z-depth collision under terrain polygons

10 September 2014 - 01:42 AM

I may have been looking in the wrong places for this answer, but I cannot find anything that answers this question, if you have an answer that would be great!

 

I have just implemented shadow maps into my game.  They seem to work fine, however I have the issue where the z-depth calculation still considered a polygon of my terrain not shadowed when the light vector is positioned below the terrain, and I am looking to see if there is a simple solution to this.

 

For example, if the light vector in the world is placed underneath the terrain, and light upward towards the terrain, the z-depth buffer still collides with the polygon exactly, thus flagging the location is not shaded, as in normal lighting calculations.

 

My question is, is there a simply way to calculate that the ray is colliding with the polygon underneath it like in the shader?  Is there a way to tell if the light vector calculation hit a counter clockwise, or clockwise polygon?

 

One answer I was thinking was to make a large outside rendered box on the edge of the rendered world below the terrain, that way the light vector will collide with a polygon underneath the terrain at all times.  However this is a problem since this does not help with terrain on the edge that just ends, it would be tough to render a vertical wall slice for each polygon terrain just for these calculations.

 

Another method I was thinking of was re-render the entire terrain but at a slightly lower height, that way it would hit the lower terrain before the upper terrain, but that would be massively un-optimized and not a perfect solution. 

 

Again thanks for any help!


PARTNERS