Jump to content
  • Advertisement
Sign in to follow this  
anders211

skybox - issue with not working

This topic is 2201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I have cube mesh in .x file and cubemap texture in .jpg file. Cubemap texture is mapped to uv coordinates on the cube mesh. In my App I load mesh from .x file and I can render well my cubeMesh (I don't use any effect, shader etc.). So as we see instances of cube mesh and cubemap texture are loaded succesfully as they can be rendered.

So then I change my code to support skybox and here I have a big issue, because when my mesh is like that in .x file:

 

Mesh { // Cube mesh
8;
-1.000000;-1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000; 1.000000;-1.000000;,
1.000000; 1.000000; 1.000000;,
1.000000; 1.000000;-1.000000;,
1.000000;-1.000000; 1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;;
 

 

after render all scene is black. If I change values to those ones in x file:

 

8;
-20.000000;-20.000000; 20.000000;,
-20.000000; 20.000000; 20.000000;,
-20.000000; 20.000000;-20.000000;,
20.000000; 20.000000; 20.000000;,
20.000000; 20.000000;-20.000000;,
20.000000;-20.000000; 20.000000;,
20.000000;-20.000000;-20.000000;,
-20.000000;-20.000000;-20.000000;;
 

then after render my scene is OK however without skybox textures (like it wasn't drawn).

So I suppose mesh with 20 values must be used and additionaly I have an issue in either my code or in effect file.

Here is my effect file:

uniform extern float4x4 MatView;
uniform extern float4x4 MatProj;
uniform extern texture textura;

sampler Sampl = sampler_state
{
Texture = textura;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};

void VS(in float3 pos : POSITION,
out float4 SkyPos : POSITION,
out float3 SkyCoord: TEXCOORD0)
{
//alternative method
float4x4 matViewNoTrans = {MatView[0], MatView[1], MatView[2], float4(0.0f, 0.0f, 0.0f, 1.0f)};
SkyPos = mul(float4(pos,1.0f), mul(matViewNoTrans, MatProj));

//float3 rotatedPos = mul(pos, MatView); => BUG IN TUTORIAL, we cannot multiply float3 by float4x4
// Calculate projection, moving all vertices to the far clip plane (w and z both 1.0)
//SkyPos = mul(float4(rotatedPos, 1), MatProj).xyww;

SkyCoord = pos;
}

vector PS(in float3 SkyCoord: TEXCOORD0) : COLOR
{
vector color = texCUBE(Sampl, SkyCoord);
return color;
}

technique skybox
{
pass P0
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_0 PS();

//ZEnable = false;
ZWriteEnable = false;
//AlphaBlendEnable = false;
CullMode = None;
//AlphaTestEnable = false;
}
}
 

 

And here is my code (it is hard to place the whole, however I corelate each string MatView,MatProj,Textura, skybox technique with D3DXHANDLE). And then I invoke effect->SetMatrix(D3DXHANDLE of MatView, MatProj) etc.

 

 

 


 

 

else if(type == Model::Skybox)
{
if(!skybox->effect)
return;
skybox->effect->activateTechnique();
skybox->effect->begin();
//pDev->SetRenderState(D3DRS_LIGHTING, FALSE );
for(u32 i=0; i< skybox->subsets; ++i)
{
//skip materials

//Set textures
skybox->effect->setTexture(Effect::p_Textura, skybox->texture);

//if(skybox->material != NULL)
//pDev->SetMaterial(skybox->material);
//pDev->SetTexture(0, skybox->texture);

//Draw mesh subset
for(u32 j=0; j<skybox->effect->getNumPasses(); ++j)
{
skybox->effect->beginPass(j);
if(skybox->mesh != NULL) //mesh
skybox->mesh->DrawSubset(i);
else //progressive mesh
skybox->pmesh->DrawSubset(i);
skybox->effect->endPass();
}
}

//pDev->SetRenderState(D3DRS_LIGHTING, TRUE );
skybox->effect->end();
pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
pDev->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
 

 

 


}My code was executed for animated skinned meshes and works OK (of course a bit different than the above, but similar), so everything should be OK with my logic which corelate C++ code with effect files, so I rather suspect that the problem is either with my effect file or there is lack of something in my code, for example turning off light because mesh doesn't have normals. However I checked and the results are the same with lighting enable and disable. So do You have any ideas what might be wrong?

Edited by anders211

Share this post


Link to post
Share on other sites
Advertisement

When I ignore skybox effect file and render just with uncommented code then I have such results:

A.) http://img9.imageshack.us/img9/913/camerafarawaay.png

B.) http://img541.imageshack.us/img541/9762/camerainthemiddleofcube.png

 

When I use effect file code then my renders when camera is far away and near point 0,0,0 are both as in case B.

Maybe this would be a hint for someone what might be wrong?

Share this post


Link to post
Share on other sites
In your 3d editor you need to inverse the normals of the faces inside you're cube. This will allow the inside faces to be appropriately lit.

Share this post


Link to post
Share on other sites

Hi,

Unfortunatelly after deep investigation it is something wrong with pixel shader function. II suppose texCUBE doesn't work or SkyCoord is wrongly calculated. If I change the code to something like that:

vector PS(in float3 SkyCoord: TEXCOORD0) : COLOR
{
vector color = texCUBE(Sampl, SkyCoord);
color.r = 1.0f
return color;
}
 

then I see red color. I suppose that I will have to resign with this stupid shaders and use skybox based on fixed function pipeline, because who knows what doesn't work here. I am a bit dissapointed, life is shit, everything is such a hard task in this directX. Developing C++ games is much much complex than working in embedded C++.

Edited by anders211

Share this post


Link to post
Share on other sites

I suppose that I will have to resign with this stupid shaders and use skybox based on fixed function pipeline, because who knows what doesn't work here. I am a bit dissapointed, life is shit, everything is such a hard task in this directX. Developing C++ games is much much complex than working in embedded C++.

 

Whoa!! Relax, life is not shit smile.png You will get used to the DirectX concepts, they are mostly stolen from OpenGL anyway smile.png  Designing a general purpose OS for state of the art consumer hardware using multi-cores is much more complex than working on some single core, embedded C++ RTOS, but games shouldn't be that much harder smile.png BTW - its worth the extra effort to learn the shader method of doing this instead of using fixed function pipeline.

Edited by Steve_Segreto

Share this post


Link to post
Share on other sites

In your vertex shader function declaration try to use "SkyPos : VPOS" instead of "SkyPos : POSITION". Also as a small tip for this code:

 

//float3 rotatedPos = mul(pos, MatView); => BUG IN TUTORIAL, we cannot multiply float3 by float4x4
// Calculate projection, moving all vertices to the far clip plane (w and z both 1.0)
//SkyPos = mul(float4(rotatedPos, 1), MatProj).xyww;

 

you actually can modify the original code like this:

 

float3 rotatedPos = mul(pos, (float3x3)MatView);
// Calculate projection, moving all vertices to the far clip plane (w and z both 1.0)
SkyPos = mul(float4(rotatedPos, 1), MatProj).xyww;
Edited by GuardianX

Share this post


Link to post
Share on other sites

Do not start cursing at the system. That is why you have pix, why don't you debug it in pix to see where you are going off.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!