It is currently Sat Aug 22, 2020 3:36 am


All times are UTC




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Texture atlases, bleeding, mipmaps & filtering
PostPosted: Sun Dec 30, 2012 6:32 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
testing this with polyvox 0.2, irrlicht1.7.2(still not 1.8), dx9, shader 2.0( the shading is added direct from irrlichtshaderexample).
its almost beyzends code except that the materialnr is tunneled through colorred like 0xdeadc0de-code.
seems that something works but only something, the colors from texatlas are correct, but the textures are missing. that means that the material is correct sent to vertexshader and the pixelshader does something (in the lower line of voxels is the material 1,2,3,4,5,6,1 see pic (below you see the top of the textureatlas and above it are some voxels, you see that they have the colors from the first textures):
Image

please someone sees why the texture(the numbers i wrote in middle of the first textures) is missing?

Code:
// Global variables ------------------------------------------------------------------
float4x4 mWorldViewProj;  // World * View * Projection transformation
float4x4 mInvWorld;       // Inverted world matrix
float4x4 mTransWorld;     // Transposed world matrix
float3 mLightPos;         // Light position
float4 mLightColor;       // Light color
float4 mworldPos;
#define ATLAS_WIDTH 4096.0
#define TEXTURE_WIDTH 256.0
#define eOffset TEXTURE_WIDTH / ATLAS_WIDTH

// Vertex shader --------------------------------------------------------------------
struct VS_OUTPUT
{
   float4 Position   : POSITION;   // vertex position
   float4 Diffuse    : COLOR0;     // vertex diffuse color
   float4 textureAtlasOff   : TEXCOORD0;  // tex coords
};

VS_OUTPUT vertexMain( in float4 vPosition : POSITION,
                      in float3 vNormal   : NORMAL,
                      float2 texCoord     : TEXCOORD0,
         float4 tile1 : COLOR )
{
   VS_OUTPUT Output;
       
        //here code from irrlichtshaderexample for getting Output.Diffuse color
       
   mworldPos=vPosition + float4(0.5f, 0.5f, 0.5f, 0.5f);
     Output.textureAtlasOff = float4(0.0f, 0.0f, 0.0f, 0.0f);
     float idx = tile1.r * 256.0 -1;
     float blocky = floor(idx / 16.0);
     float blockx = (idx - blocky * 16.0);
     Output.textureAtlasOff = float4(blockx + 0.25f, blocky + 0.25f, 0.0, 0.0) *eOffset;

   return Output;
}


// Pixel shader -------------------------------------------------------------------------
struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color   
};

sampler2D tex0;
   
PS_OUTPUT pixelMain( float4 textureAtlasOffset : TEXCOORD0,
                     float4 Position : POSITION,
                     float4 Diffuse  : COLOR0 )
{
   PS_OUTPUT Output;

    float3 normal = cross(ddy(mworldPos.xyz),ddx(mworldPos.xyz));
    normal = normalize(normal);
   float2 uv0 = float2(1.0, 1.0);
     if(normal.x > 0.5) uv0 = frac(float2(-mworldPos.z, -mworldPos.y));
     if(normal.x < -0.5) uv0 = frac(float2(-mworldPos.z, mworldPos.y));
     if(normal.y > 0.5) uv0 = frac(mworldPos.xz);
     if(normal.y < -0.5) uv0 = frac(float2(-mworldPos.x, mworldPos.z));
     if(normal.z > 0.5) uv0 = frac(float2(mworldPos.x, -mworldPos.y));
     if(normal.z < -0.5) uv0 = frac(float2(-mworldPos.x,-mworldPos.y));
     textureAtlasOffset += float4(uv0 * 0.5,0.0,0.0)*eOffset;
   float4 col1=tex2D(tex0, textureAtlasOffset.xy);
   Output.RGBColor =  col1*Diffuse;
   return Output;
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Texture atlases, bleeding, mipmaps & filtering
PostPosted: Mon Dec 31, 2012 10:16 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Unfortunatly your image is very small, but if I understand correctly you are saying that each of the tiles is not just a solid colour but instead has a number drawn on it, and yet you are not seeing these numbers after the texture mapping is performed? Maybe you have a larger image to show?

One thing I notice is your use of mworldPos. This is a global variable and I would usually expect these to be set by the C++ program and read by the shaders. However, you are writing to it directly from the shader program, and I'm not sure if this is allowed or exactly what the implications are. I think I would expect you to pass the world position as another member of VS_OUTPUT:

Code:
struct VS_OUTPUT
{
   float4 Position   : POSITION;   // vertex position
   float4 Diffuse    : COLOR0;     // vertex diffuse color
   float4 textureAtlasOff   : TEXCOORD0;  // tex coords
   float4 WorldSpacePosition   : TEXCOORD1;  // The world space position
};


I'm not sure if this is actually your problem through. You migth also consider simplyfying the code so that you only have a single texture being applied (so you don't have to mess around with offsets) and get that working first. It might make it easier to see what the problem is.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Texture atlases, bleeding, mipmaps & filtering
PostPosted: Mon Dec 31, 2012 1:08 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
yes i first tested with one texture and it worked, but with one texture it anyway works for me in irrlicht without a shader, i wrote to the forum in July
(http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=185&start=10 ).

ok youre right the failure was that im always using the quick and dirty way ;-) with globals and here they should not be used it was quickanderror. there was no errormessage - i didnt expect that programming these shaders is like the spanish inquisition http://www.youtube.com/watch?v=Tym0MObFpTI
changed to your suggestion with the coordinates in TEXCOORD1 and it works ! Thank you very much Sir David!
(bigger pic now):
Image

the material is tunneled through color red in gnurfos irrlichtinterfacefunction, see link to other thread above.
Code:
mb->getVertexBuffer()[i].Color = irr::video::SColor(0,vertices[i].getMaterial(),0,0);

for all interested - how in irrlicht shader are called read irrlicht example:
http://irrlicht.sourceforge.net/docu/example010.html


thanks again and have a nice sylvester


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net