Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

adrian_134

Member Since 14 Jan 2012
Offline Last Active Sep 27 2012 05:30 PM
-----

Topics I've Started

Android Intent - How can i open file

20 June 2012 - 01:53 AM

Hello!

To open image or sound we can use this code:
public String getExt(String filename){
      
   int dotIndex = 0;
   for(int i = filename.length()-1; i >= 0; i--)
   {
      if(filename.charAt(i) == '.') {
         dotIndex = i;
         break;
      }
   }
      
   return filename.substring(dotIndex + 1, filename.length());
}
   
public String getTypeAction(String s) {
      
   int slashIndex = 0;
   for(int i = 0; i < s.length(); i++)
   {
      if(s.charAt(i) == '/') {
         slashIndex = i;
         break;
      }
   }
      
   return s.substring(0, slashIndex);
}
//////
//////

MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = getExt(file_to_action.getName());
ext = ext.toLowerCase();

String type = mime.getMimeTypeFromExtension(ext);

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file_to_action), getTypeAction(type) + "/*" );
startActivity(intent);

But the problem is when i want to open any different file for example: .mhtml, .bak. apk. When i do this my application is crash. I don't know where is the problem, i have application for .mhtml, .odt extenio but my application can't use this applications to open the file.
How i can open all file format or how i can check avaliable application for any file format ?

LUT texture for procedural terrain textring

06 February 2012 - 02:09 PM

Hi!

I create lut texture for precedural terrain texturing, that texture have the same size what my heightmap, because i want to store texture id in each pixel for one vertex, for example pixel[0, 1] store texture id for vertex[0, 1]. But i have problem when i try read texture id in pixel shader.

LUT texture is D3DFMT_A8R8G8B8.

That is code who save data to lut texture:
int getTextureID(D3DXVECTOR3 n)
{
    D3DXVECTOR3 nn;
    D3DXVec3Normalize(&nn, &n);
    if(nn.y <= 0.9f)
    {
        return 10;
    }
    return 0;
}

///
void generateTerrainVertex()
{
    D3DXVECTOR3 p(0.0f, 0.0f, 0.0f);
    int c = 0;
    for(int i = 0; i < cWidth; i++)
    {
        p.z = -(float)i * 2.0f);
   	 for(int j = 0; j < cHeight; j++)
        {
            p.x = (float)j * 2.0f;

            p.y = cHeightMap[getVertex(i, j)];
            v[c].pos    = p;
            v[c].normal = calcNormal(i, j);
            v[c].texcoord.x = (float)i / (float)cLUT->getWidth();
            v[c].texcoord.y = (float)j / (float)cLUT->getHeight();


	 	 // LUT Texture

            int id = getTextureID(v[c].normal);
       	 data[i + j * cLUT->getWidth()] = (id<<16) | (0<<8) | 0;

            c++;
   	 }
    }
}
The code is very simple because i want to lern this technique...

In my pixel shader i read texure id:
float3 Color = c0;

float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
int texID = int(B.r);
if(texID == 10)
{
    Color =  c1;
}
"texID == 10" is false, i don't know why, why texID isn't 10 ? When i generated vertex i saved to lut texture 10 or 0, in pixel shader i have unknown value... Why ?
When i change the code:
float3 Color = c0;
float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
if(B.r >= 0.01f)
{ Color =  c1;}
And i get this:
http://www.coubetech.republika.pl/p.jpg
The result is correctly but why b.r have unknown value ?

c0 - grass
c1 - stone

Shadow maping in deferred render

14 January 2012 - 12:26 PM

Hello!

I have problem with shadow maping in deferred render. For shading object, in pixel shader directional light i use this code:
	// Compute screen-space position
	float4 position;
	position.x = input.TexCoord.x * 2.0f - 1.0f;
	position.y = -(input.TexCoord.x * 2.0f - 1.0f);
	position.z = depthVal;
	position.w = 1.0f;
	// Transform to world space
	position = mul(position, InvertViewProjection);
	position /= position.w;

   // ----------------------- Shadow ---------------
   float4 lightScreenPos = mul(position, lightViewProjection);
   lightScreenPos /= lightScreenPos.w;

   // Find sample position in shadow map
   float2 lightSamplePos;
   lightSamplePos.x = lightScreenPos.x / 2.0f + 0.5f;
   lightSamplePos.y = -lightScreenPos.y / 2.0f + 0.5f;	


  float m = 0.2f;			  
  float depthInMap = tex2D(shadowTextureSampler, lightSamplePos);
  float distance = lightScreenPos.z;
  if((distance - 0.0001f) <= depthInMap)
  {
   	 m = 1.0f; // Is in light
  }
	diffuseLight.rgb *= m;
I want get m = 1.0f when is in light or 0.2f when is in shadow but when i using this code all my objects are in shadow or are illuminated this is the screen:
http://www.coubetech...blika.pl/11.jpg

When i turn and move my camera i getting somfing like this:
http://www.coubetech....pl/dserror.jpg

I thing the problem is in the pixel shader becouse this code working correctly for forward rendering (picture in left side). I don't know where is the problem, meybe in lightScreenPos calculations, but what could be wrong ? Directional light working correctly, i have problem only with shadow map.

PARTNERS