# robustpotato

Members

52

124 Neutral

• 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

4. ## VTF Pixel Coordinate problem

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. ## D3D clip plane problem

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