robustpotato

Member
  • Content count

    52
  • Joined

  • Last visited

Community Reputation

124 Neutral

About robustpotato

  • Rank
    Member
  1. VTF Pixel Coordinate problem

    Thank you very much, I tried that and it has solved the problem.
  2. VTF Pixel Coordinate problem

    I read something about that before. Does that mean I should aim for the centre of the pixel? So for example 234,591, I'd attempt to get 234.5, 591.5. What happens when it comes for pixel 1024? 1024.5? the texture coordinate would be higher than 1? or are we assuming the 1st pixel is 0 and the 1024th pixel is 1023 or is 1 the right bounds of the right most pixel. If that is so then calculating the correct pixel may be awkward. I may have to draw some diagrams. Again thanks for the help
  3. VTF Pixel Coordinate problem

    Hey thanks for the reply. I have actually seen your large terrain already. Kinda what inspired what I'm doing. Im taking a mesh and moving around with the camera and snapping to the grid and then just pulling the heights from a texture. [quote]I think that DX9 VTF only supports POINT filtering[/quote] I can specify LINEAR in the sampler and get different results when specifying POINT. with point there are clear "Steps" but linear produces a smooth slope. [source lang="plain"]Texture HeightMap_LowRes; sampler TextureSampler = sampler_state { texture = <HeightMap_LowRes> ; magfilter = linear; minfilter = linear; mipfilter= linear; AddressU = clamp; AddressV = clamp; }; [/source] from the vertex shader... [source lang="plain"] float4 VTFCoords = float4((worldPosition.x)/TerrainSize,(worldPosition.z)/TerrainSize,0,0); float height =(float)tex2Dlod(TextureSampler, VTFCoords);[/source] When the worldPosition.x is 0 or 1. the same height occurs (when the z is constant of course). In your method you pull the 4 nearest pixels and do your own interpolation. You must work out those 4 points as texture coordinates. You said your heightmap is over 8k in one dimension. do you not get a problem with calculating the precise pixel coordinates? My issue is at the edge. So if I were to interpolate from 4 points at the edge, they would be 2 matching pairs as the coordinates seem to be the same. (I need to recheck in PIX after changing the decimal places). Thank you for the links. Kinda got my heart set on VTF as I have tried other LOD methods before, but am yet to try VTF. Your "pizza" method seems quite elegant. For now Im just using a square mesh, I want to try and make it quite low res, My application doesnt require showing a terrain right to the horizon, just the immediate area around it, but it needs to support larger terrains, so when you move it will show a new area instantly (from 1 heightmap). What I have so far looks great. I just need to sort out the interpolation. But even if I do I think my samples will pick the same heights. Feel like I am missing something obvious? Thanks for the help, much appreciated!
  4. Hi. I am trying to use VTF, to create a terrain. I have a heightmap of 1024x1024. I have sampled this for vertex heights on a grid that is 2048x2048, stretching the heightmap so there are 2 vertices for every pixel. I want to be able to stretch it further. For the vertices that have no pixel, they will interpolate (If I'm not mistaken, HLSL handles that when you sample a texture). To work out my texture coordinates I am taking the vertex position and dividing by the grid size. My problem is the 1st 2 rows of vertices along 1 axis are giving me the same heights. In theory the texture coordinates should be: for the 1st row 0/2048 = 0. for the 2nd 1/2048 = 0.00048828125. I have used PIX to try and debug it but on both rows the coordinates both are calculated as 0.000 It seems to be rounding after 3 decimal places. therefore both rows sample the same pixels and the heights are identical. Can I use better precision or is there another way to sample using exact coordinates? rather than 0.0-1.0 I'm guessing this would occur elsewhere on the terrain also, but its harder to find. at a glance it looks like its all used correct pixel samples and interpolated the ones that are in between. Cheers
  5. Perlin noise question

    Ah thanks, I made the changes but the results are : [attachment=6178:img.jpg] Is it meant to be as stretched? I was expecting purely random noise. I wasn't sure about converting the int x/y to unsigned. i just cast them. thanks for the help
  6. Perlin noise question

    This is a better example, same everything but double width and height. its a lot easier to see the patterns [attachment=6156:img.jpg]
  7. Perlin noise question

    Hey. Im looking into perlin noise at the moment, wanting to generate height maps and textures etc. i looked around on the internet and got a few things going (im only at the 1st stage of generating "pure" noise) I found the following example [code] int bmp_dim = 256; Bitmap bmp = new Bitmap(bmp_dim, bmp_dim); Random r = new Random(); //to create a new image every time int thisr = r.Next(0, 5000); for(int i=0; i<bmp_dim; i++) { for(int j=0; j<bmp_dim; j++) { float t = Noise2d(j+thisr, i+thisr); //offset creates //a different image every time if(t<0) t = -t; if(t>1) t = 1.0f; int fin = (int)(t*255.0f); //get in color range Color col = Color.FromArgb(fin, fin, fin); bmp.SetPixel(j, i, col); } } [attachment=6154:img.jpg] [/code] Heres the noise function [code] float Noise2d(int x, int y) { int n; n = x + y * 57; n = (n<<13) ^ n; float res = (float)( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff ) / 1073741824.0); return res; } [/code] I took out the random offset (the variable named thisr) used to make a different noise with each compilation, and just used the x/y of the current place in the loop. Problem is my noise seems to have patterns in it, it seems to loop. see image below (horizontal pattern) [attachment=6155:img.jpg] I had a look into the values and they are not the same, they dont repeat exactly from what i can see, i suspect its just the differences and intervals between them It may look small but surely it could have adverse effects if it keeps looping, I thought the idea was that its supposed to be random and totally without patterns. the site i got the example from has a button to generate new noise and this does not occur on the website [url="http://web.archive.org/web/20060825023346/http://www.animeimaging.com/asp/PerlinNoise.aspx"]Link here[/url] is this meant to happen, can i fix it cheers
  8. Ok I had this working before but disabled it to work on some other features. I have also since got a new graphics card. I dont know whats caused it but i think it maybe the new card. the card is : [url="http://www.gigabyte.com/products/product-page.aspx?pid=3746#ov"]http://www.gigabyte....spx?pid=3746#ov[/url] Im setting up a clipping plane to do a water reflection map. I've looked around and i understand that this is the correct way of doing it: [code] D3DXPlaneFromPointNormal(&plane, &D3DXVECTOR3(0,45,0),&D3DXVECTOR3(0,1,0)); D3DXMATRIXA16 matrix = currentCamera->GetViewMatrix()* matProjection ; D3DXMatrixInverse(&matrix, NULL, &matrix); // second parameter is an out parameter for the determinant D3DXMatrixTranspose(&matrix, &matrix); D3DXPlaneTransform(&viewSpacePlane, &plane, &matrix); planearray[0] = viewSpacePlane.a; planearray[1] = viewSpacePlane.b; planearray[2] = viewSpacePlane.c; planearray[3] = viewSpacePlane.d; device->SetClipPlane(0, planearray); device->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 ); [/code] When I move the camera the plane does not stay at 45 (as specified. The plane seems to get bigger as my camera's height increases. This results in a gap where the terrain meets the water. Is it my new card? is there a solution
  9. Framerate issues.

    Ok. cleaned out most of my project and eventually got to 0 memory leaks. but i get the following in the console after exiting. Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 1269791 bytes No idea where that is coming from. Anyway my real problem is framerate, and cleaning up at the end cant possibly have any effect on my in game frame rate. I switched to using less verticess and its fine. EDIT: I cleaned out nearly everything. and slowly added stuff back. its the shader it loads at the beginning then in clean does this: landShader->OnLostDevice(); landShader->Release() and i get. Direct3D9: (ERROR) :Memory still allocated! Alloc count = 276 without the load/clean functions I get no errors on shutting down the program.
  10. Framerate issues.

    It says Max Primitives = 65, 535 Max Vertex Index = 65, 534 256 x 256 verts is 65, 536. and its rendering twice... once to a texture for reflections and once to the scene. the render to texture is clipped though. I want to have a huge terrain, I need some more optimization. as for the memory leaks. I found something D3DX: MEMORY LEAKS DETECTED: 188 allocations unfreed (98839 bytes). I removed all rendering code and then tried again D3DX: MEMORY LEAKS DETECTED: 186 allocations unfreed (98375 bytes) Then i removed the following line in the load function: [code] HRESULT hr; hr = D3DXCreateEffectFromFile(device,"WaterShader.fx",NULL,NULL,0,NULL,&anEffect,NULL); [/code] and now i get: D3DX: MEMORY LEAKS DETECTED: 127 allocations unfreed (80316 bytes) how can loading in a .fx file create memory leaks. I am calling this line in my clean function [code] anEffect->release(); [/code]
  11. Framerate issues.

    What sort of thinks an fail with HRESULT. Everything looks as it should. Im getting D3DX: MEMORY LEAKS DETECTED: 188 allocations unfreed (98839 bytes). Is that something to do with it. i used the DX control panel and applied debug. now nothing draws except my skybox. Thats the only thing thts drawn with the fixed functin pipeline. my terrain and the water are both done with shaders. Console Output: First-chance exception at 0x769442eb in RenderEngine.exe: Microsoft C++ exception: long at memory location 0x0032ede4.. Direct3D9: (ERROR) :DrawPrimitive failed. Direct3D9: (ERROR) :Primitive count or vertex count is too big. Check device caps. I am quite new to DirectX and C++. Im not to experience at debugging. I find it strange how it wont draw using debug version but will with retail.
  12. Framerate issues.

    recently implemented a water effect using a shader, and rendering a reflection map to a texture. my frame rate is fine when first running, but then dips after a while. I removed the water but kept in the part where it renders to a texture and the problem persists so I'm thinking its to do with that. Heres my method [code] D3DXVECTOR3 oldCamPos= currentCamera->GetPosition(); float oldCamXRotation = currentCamera->GetRotation().x; currentCamera->SetRotation(D3DXVECTOR3( - oldCamXRotation, currentCamera->GetRotation().y,currentCamera->GetRotation().x)); float newCamHeight = oldCamPos.y -((oldCamPos.y-(8.9*5))*2); currentCamera->SetPosition(D3DXVECTOR3(oldCamPos.x,newCamHeight,oldCamPos.z)); //################################## RENDERING TO TEXTURE //set render target device->SetRenderTarget(0,pRenderSurface); //############################ CLEAR device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); //################//now draw scene device->BeginScene(); device->SetTransform( D3DTS_VIEW, &currentCamera->GetViewMatrix() ); device->SetTransform( D3DTS_PROJECTION, &matProjection ); //render skydome with no zbuffer device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); skydome->Render(device); //re enable z buffer to draw everything else. //device->SetRenderState(D3DRS_ZWRITEENABLE , D3DZB_TRUE); device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); //##########CLIPPING D3DXMATRIXA16 matrix = myTerrain->GetWorldMatrix() * currentCamera->GetViewMatrix()* matProjection ; D3DXMatrixInverse(&matrix, NULL, &matrix); // second parameter is an out parameter for the determinant D3DXMatrixTranspose(&matrix, &matrix); D3DXPLANE viewSpacePlane; D3DXPlaneTransform(&viewSpacePlane, &plane, &matrix); planearray[0] = viewSpacePlane.a; planearray[1] = viewSpacePlane.b; planearray[2] = viewSpacePlane.c; planearray[3] = viewSpacePlane.d; device->SetClipPlane(0, planearray); device->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 ); //draw terrain myTerrain->Render(device); device->EndScene(); currentCamera->SetPosition(oldCamPos); currentCamera->SetRotation(D3DXVECTOR3(oldCamXRotation,currentCamera->GetRotation().y,currentCamera->GetRotation().x)); [/code] The texture im rendering to is 256x256. I am rendering a fairly big scene, a terrain 256x256 verts, but the framerate is absolutely fine without running the above method. and even when it is running the method it starts off fine. I dunno what im doing wrong. can anyone help? cheers
  13. Newbie to HLSL

    edit: ########################ISSUE RESOLVED######################### I been messing around in XNA with shaders. like the name suggests im a newbie, using an XNA example I've been able to get a bump map working and some texture blending and confident I could just fiddle around and experiment to learn more about it. Anyway I want to get one running in DirectX, I took this shader and loaded to directX, by looking at some tutorials and examples. I made a vertex buffer and tried to render a simple quad with the shader. Nothing appears. I am probably missing something very basic here, but I dunno. Im gonna post the code. Id be glad if someone can help me out. Here is the .fx file. [code] float4x4 world; float4x4 view; float4x4 projection; Texture xTexture; sampler TextureSampler = sampler_state { texture = <xTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;}; struct VertexToPixel { float4 Position : POSITION0; float2 TexCoords : TEXCOORD0; }; struct PixelToFrame { float4 Color : COLOR0; }; VertexToPixel SimplestVertexShader( float4 inPos : POSITION0, float2 inTexCoords : TEXCOORD0) { VertexToPixel Output = (VertexToPixel)0; //transform the vertices float4x4 preViewProjection = mul (view, projection); float4x4 preWorldViewProjection = mul (world, preViewProjection); Output.Position =mul(inPos, preWorldViewProjection); Output.TexCoords = inTexCoords; return Output; } PixelToFrame OurFirstPixelShader(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; //Output.Color = tex2D(TextureSampler, PSIn.TexCoords) ; Output.Color = float4(1,0,0,1); return Output; } technique Simplest { pass Pass0 { VertexShader = compile vs_2_0 SimplestVertexShader(); PixelShader = compile ps_2_0 OurFirstPixelShader(); } } [/code] Heres the loading code: [code] HRESULT hr; hr = D3DXCreateEffectFromFile(device,"my1stEFFECT.fx",NULL,NULL,0,NULL,&anEffect,NULL); [/code] Here is my code for setting up the geometry [code] struct TVertex { D3DXVECTOR3 Position; D3DXVECTOR2 Tex; TVertex() { } TVertex(D3DXVECTOR3 position, D3DXVECTOR2 texCoord) { Position = position; Tex = texCoord; } }; const D3DVERTEXELEMENT9 dec[3] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0}, {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0}, D3DDECL_END() }; device->CreateVertexDeclaration(dec,&m_vertexDeclaration); TVertex verts[6] ; verts[0] = TVertex(D3DXVECTOR3(-1,1,0),D3DXVECTOR2(0,0)); verts[1] = TVertex(D3DXVECTOR3(1,1,0),D3DXVECTOR2(1,0)); verts[2] = TVertex(D3DXVECTOR3(-1,-1,0),D3DXVECTOR2(0,1)); verts[3] = TVertex(D3DXVECTOR3(-1,-1,0),D3DXVECTOR2(0,1)); verts[4] = TVertex(D3DXVECTOR3(1,1,0),D3DXVECTOR2(1,0)); verts[5] = TVertex(D3DXVECTOR3(1,-1,0),D3DXVECTOR2(1,1)); device->CreateVertexBuffer(sizeof(TVertex) * 6, D3DUSAGE_WRITEONLY, D3DFVF_TERRAINVERTEX, D3DPOOL_DEFAULT, &vBuffer, NULL); void* vertexData = NULL; vBuffer->Lock(0,6*sizeof(TVertex),(void**)&vertexData,0); memcpy(vertexData, verts, 6*sizeof(TVertex)); vBuffer->Unlock(); [/code] And finally the rending code: [code] if (SUCCEEDED(anEffect->SetTechnique("Simplest"))) { anEffect->SetMatrix( "world", &worldMat); anEffect->SetMatrix( "view", &view); anEffect->SetMatrix( "world", &proj); anEffect->SetTexture( "xTexture", te2); UINT numPasses; anEffect->Begin(&numPasses,0); for (UINT i=0;i<numPasses;i++) { anEffect->BeginPass(i); // Set the pass device->SetStreamSource( 0, vBuffer, 0, sizeof(TVertex) ); device->SetVertexDeclaration(m_vertexDeclaration); device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 ); anEffect->EndPass(); } anEffect->End(); } [/code] One final note. all the variables you see that are not declared are declared elsewhere, the matrices are fine. as I did i tried drawing it without the shader and it was fine. Thanks.
  14. HLSL question for texture blending

    Ah interesting. Ill have a look at it. cheers. I have only messed with shaders in XNA, still havent been able to get one working in directX, Im gonna start a new thread for help with that.
  15. HLSL question for texture blending

    Ah i see. but i was wanting a way of specifying the amount of each texture at each vertex. Then the interpolator would do the rest. Im new to HLSL so forgive me if I dont know what im talking about at the moment im doing this [code] VertexToPixel MultiTextureVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal :NORMAL0, float2 inTexWeights: TEXCOORD1 ) { VertexToPixel Output = (VertexToPixel)0; //transform the vertex float4x4 preViewProjection = mul (view, projection); float4x4 preWorldViewProjection = mul (world, preViewProjection); Output.Position =mul(inPos, preWorldViewProjection); Output.Normal = mul(inNormal, (float3x3)world); Output.TexCoords = inTexCoords; Output.weights = inTexWeights; return Output; } PixelToFrame MultiTexturePixelShader(VertexToPixel PSIn) { PixelToFrame Output = (PixelToFrame)0; Output.Color = tex2D(TextureSampler, PSIn.TexCoords) * PSIn.weights.x; Output.Color += tex2D(TextureSampler2, PSIn.TexCoords) * PSIn.weights.y; return Output; } [/code]