• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lucky6969b

Whoops! wrong Texture mapping, why does it happen?

2 posts in this topic

In CreateMeshContainer
[code]
// if materials provided, copy them
if( NumMaterials > 0 )
{
memcpy( pMeshContainer->pMaterials, pMaterials, sizeof( D3DXMATERIAL ) * NumMaterials );
for( iMaterial = 0; iMaterial < NumMaterials; iMaterial++ )
{
if( pMeshContainer->pMaterials[iMaterial].pTextureFilename != NULL )
{
LPDIRECT3DTEXTURE9 texture = NULL;
WCHAR strTexturePath[MAX_PATH];
WCHAR wszBuf[MAX_PATH] = L"Data\\";
MultiByteToWideChar( CP_ACP, 0, pMeshContainer->pMaterials[iMaterial].pTextureFilename, -1, strTexturePath, MAX_PATH );


wcsncat(wszBuf, strTexturePath, wcslen(wszBuf)+wcslen(strTexturePath));

if( FAILED( D3DXCreateTextureFromFileW( pd3dDevice, wszBuf,
&texture) ) )
{
pMeshContainer->textures.clear();
}
else
{
pMeshContainer->textures.push_back(texture);
}
// don't remember a pointer into the dynamic memory, just forget the name after loading
pMeshContainer->pMaterials[iMaterial].pTextureFilename = NULL;
}



}
}
else // if no materials provided, use a default one
{
pMeshContainer->pMaterials[0].pTextureFilename = NULL;
memset( &pMeshContainer->pMaterials[0].MatD3D, 0, sizeof( D3DMATERIAL9 ) );
pMeshContainer->pMaterials[0].MatD3D.Diffuse.r = 0.5f;
pMeshContainer->pMaterials[0].MatD3D.Diffuse.g = 0.5f;
pMeshContainer->pMaterials[0].MatD3D.Diffuse.b = 0.5f;
pMeshContainer->pMaterials[0].MatD3D.Specular = pMeshContainer->pMaterials[0].MatD3D.Diffuse;
}
[/code]

In Rendering code,
[code]
for (iAttrib = 0; iAttrib < pMeshContainer->NumAttributeGroups; iAttrib++)
{
D3DXMATRIX invWorld;
D3DXMatrixInverse(&invWorld, NULL, &pFrame->CombinedTransformationMatrix);
D3DXMatrixTranspose(&invWorld, &invWorld);
//Normal Static Mesh
g_pNormalEffect->SetMatrix("gWVP", &(pFrame->CombinedTransformationMatrix * (m_Cam.GetViewMatrix() * m_Cam.GetProjMatrix())));
g_pNormalEffect->SetMatrix("gWorld", &pFrame->CombinedTransformationMatrix);
g_pNormalEffect->SetMatrix("gWorldInvTrans", &invWorld);
D3DXHANDLE hTech = g_pNormalEffect->GetTechniqueByName("PhongDirLtTexTech");
g_pNormalEffect->SetTechnique(hTech);
// Sum of all ambient and emissive contribution
D3DXCOLOR color1( pMeshContainer->pMaterials[iAttrib].MatD3D.Ambient );
D3DXCOLOR color2( .25, .25, .25, 1.0 );
D3DXCOLOR ambEmm;
D3DXColorModulate( &ambEmm, &color1, &color2 );
ambEmm += D3DXCOLOR( pMeshContainer->pMaterials[iAttrib].MatD3D.Emissive );
//Render the mesh
// set material color properties
g_pNormalEffect->SetVector( "MaterialDiffuse",
( D3DXVECTOR4* )&(
pMeshContainer->pMaterials[iAttrib].MatD3D.Diffuse ) );
g_pNormalEffect->SetVector( "MaterialAmbient", ( D3DXVECTOR4* )&ambEmm ) ;
if (pMeshContainer->pMaterials[iAttrib].MatD3D.Diffuse.a < 1.0f)
{
//g_pEffect1->SetValue("vMaterialColor", &boneMesh->materials[i].Diffuse, sizeof(D3DCOLORVALUE));
//m_pDevice->SetMaterial(&boneMesh->materials[i]);


if (!pMeshContainer->textures.empty())
g_pNormalEffect->SetTexture("gTex", pMeshContainer->textures[iAttrib]);
g_pNormalEffect->Begin(NULL, NULL);
g_pNormalEffect->BeginPass(0);
pMeshContainer->MeshData.pMesh->DrawSubset(iAttrib);

g_pNormalEffect->EndPass();
g_pNormalEffect->End();
}
}
}
[/code]

In shader,
[code]
float4 lhtDir = {0.0f, 0.0f, -1.0f, 1.0f}; //light Direction
float4 LightAmbient = {0.3f, 0.3f, 0.3f, 0.3f};
float4 LightDiffuse = {0.6f, 0.6f, 0.6f, 1.0f}; // Light Diffuse
float4 LightSpec = {0.3f, 0.3f, 0.3f, 0.3f};
float4 MaterialAmbient : MATERIALAMBIENT = {0.1f, 0.1f, 0.1f, 1.0f};
float4 MaterialDiffuse : MATERIALDIFFUSE = {0.8f, 0.8f, 0.8f, 1.0f};
float4 MaterialSpec : MATERIALSPECULAR = {0.1f, 0.1f, 0.1f, 0.1f};
extern float SpecPower = 0.5f;
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gWVP; // World-View-Projection

uniform extern float3 gEyePosW;
uniform extern texture gTex;
sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = WRAP;
AddressV = WRAP;
};

struct OutputVS
{
float4 posH : POSITION0;
float3 normalW : TEXCOORD0;
float3 toEyeW : TEXCOORD1;
float2 tex0 : TEXCOORD2;
};
OutputVS PhongDirLtTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0: TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;

// Transform normal to world space.
outVS.normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;

// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;

// Compute the unit vector from the vertex to the eye.
outVS.toEyeW = gEyePosW - posW;

// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);

// Pass on texture coordinates to be interpolated in rasterization.
outVS.tex0 = tex0;
// Done--return the output.
return outVS;
}
float4 PhongDirLtTexPS(float3 normalW : TEXCOORD0, float3 toEyeW : TEXCOORD1, float2 tex0 : TEXCOORD2) : COLOR
{
// Interpolated normals can become unnormal--so normalize.
normalW = normalize(normalW);
toEyeW = normalize(toEyeW);

// Light vector is opposite the direction of the light.
//float3 lightVecW = -gLight.dirW;
float3 lightVecW = lhtDir;

// Compute the reflection vector.
float3 r = reflect(-lightVecW, normalW);

// Determine how much (if any) specular light makes it into the eye.
float t = pow(max(dot(r, toEyeW), 0.0f), SpecPower);

// Determine the diffuse light intensity that strikes the vertex.
float s = max(dot(lightVecW, normalW), 0.0f);

// Compute the ambient, diffuse and specular terms separatly.
float3 spec = t*(MaterialSpec*LightSpec).rgb;
float3 diffuse = s*(MaterialDiffuse*LightDiffuse).rgb;
float3 ambient = MaterialAmbient*LightAmbient;

// Get the texture color.
float4 texColor = tex2D(TexS, tex0);

// Combine the color from lighting with the texture color.
float3 color = (ambient + diffuse)*texColor.rgb + spec;
//float3 color = (ambient + diffuse).rgb + spec;

// Sum all the terms together and copy over the diffuse alpha.
return float4(color, MaterialDiffuse.a*texColor.a);
//return float4(color, MaterialDiffuse.a);

}
technique PhongDirLtTexTech
{
pass P0
{
Lighting = true;
AlphaBlendEnable = TRUE;
DestBlend = INVSRCALPHA;
SrcBlend = SRCALPHA;
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_2_0 PhongDirLtTexVS();
pixelShader = compile ps_2_0 PhongDirLtTexPS();
}
}
[/code]

The full alpha execution path is symmetrical.
Anyone shed some lights on this?
Thanks
Jack Edited by lucky6969b
0

Share this post


Link to post
Share on other sites
Sorry what is it supposed to look like? If you have a texture applied that shouldn't have been, then I'd check this branch:

[CODE]
if (!pMeshContainer->textures.empty())
g_pNormalEffect->SetTexture("gTex", pMeshContainer->textures[iAttrib]);
[/CODE]

Maybe you're expecting a texture there and are not getting it so the shader is reading the last set texture. In fact you're reading that texture no matter what it seems, so if that ever did happen you'd see some artifacts.
0

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1351788781' post='4996236']
Sorry what is it supposed to look like? If you have a texture applied that shouldn't have been, then I'd check this branch:

[CODE]
if (!pMeshContainer->textures.empty())
g_pNormalEffect->SetTexture("gTex", pMeshContainer->textures[iAttrib]);
[/CODE]

Maybe you're expecting a texture there and are not getting it so the shader is reading the last set texture. In fact you're reading that texture no matter what it seems, so if that ever did happen you'd see some artifacts.
[/quote]

Hello Seabolt,
My problem is that the texture should be applied to the skydome instead of the warehouse. The others are not artifacts, they are supposed to be buildings around the site.
What is general way to reset a texture after applying to a first object?

[code]
g_pNormalEffect->SetTexture("gTex", NULL);
[/code]
Try this after render the subset, however, the entire scene is a patch of blackness now
Thanks for your consideration.
Jack Edited by lucky6969b
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0