🔒 Locked
Creating Textures
Advertisement
Original Post
Hi, I need to create a Texture from scratch using (the texture is viewport sized): Texture tex = new Texture(... ); Which I then fill with custom values using locks. tex.Lock(...); ... tex.Unlock(); When the texture is ready I would like to apply it using : device.SetTexture(... ); And using a Pixel Shader I read the values using VPOS coordinates. Ie. I create a screensized texture that is only sampled at position where an object is rendered. I´ve tried doing this but I dont get the expected results (for fun i tried saving my finished texture to file and creating a new texture from that file, this gives the expected visual result, but is naturally too slow). Can anyone help me with a working way of doing this ? Could there be some mipmap issues ? Or something ?
Could you elaborate a bit about what those unexpected results are? It's a bit hard to guess a solution, if we don't know what the problem is exactly :) Post a few screenshots of you can, that should clear things up.
The only guess I can offer from this is that somehow the texture size you specify (screen sized) might not be supported by the device, causing a different size to be used, which may lead to some minify/magnify filtering issues. Also post some more code if you can, so we get a better idea of what you're trying to accomplish.
The only guess I can offer from this is that somehow the texture size you specify (screen sized) might not be supported by the device, causing a different size to be used, which may lead to some minify/magnify filtering issues. Also post some more code if you can, so we get a better idea of what you're trying to accomplish.
Dont think I can put an image in here, but basically I´m working on caustics.
And I´m storing the screencoordinates of intersections (photonhits) in a texture which is the same size as the viewport.
The expected result is a high concentration of white dots in a specific area (happens because of the geometry in the scene).
If I save the texture as a Bitmap and load it into my texture using the TextureLoader it works perfectly ie. it renders the expected white dots, but that naturally is too slow. If I use the exact same texture directly, the rendered points seem random.
And I´m storing the screencoordinates of intersections (photonhits) in a texture which is the same size as the viewport.
The expected result is a high concentration of white dots in a specific area (happens because of the geometry in the scene).
If I save the texture as a Bitmap and load it into my texture using the TextureLoader it works perfectly ie. it renders the expected white dots, but that naturally is too slow. If I use the exact same texture directly, the rendered points seem random.
The points being random doesn't sound like an effect caused by mip/mapping or any other filtering, so I guess that's not the problem. Since it works when you save/load the texture, it may be an issue with your texture format, so that the values you specify get messed up in the original texture, but are correct in the loaded one. How it is possible then for DX to save the correct texture, I wouldn't know, but comparing the texture formats on the original and loaded texture might be worth a shot.
By the way, if you could post some results or code on this, that'd be great (provided you can share that information). It's always good to see more advanced things like caustics being done with MDX :)
By the way, if you could post some results or code on this, that'd be great (provided you can share that information). It's always good to see more advanced things like caustics being done with MDX :)
Quote:
Original post by sune
Dont think I can put an image in here
Not directly, but you can use HTML tags to point to one - <img src=".."> or <a href="...">click for image</a>.
Consider using Photo Bucket or Image Shack.
Quote:
Original post by sune
I´m storing the screencoordinates of intersections (photonhits) in a texture which is the same size as the viewport.
Okay, so your pixel shader outputs a particular value (say, white) if there is an intersection and a different value (say, black) if there is no intersection?
Are you writing in HLSL or Assembly? What dimensions are your texture? Some hardware has restrictions on what sort of sampling operations you can do on non-2N textures.
Quote:
Original post by sune
If I save the texture as a Bitmap and load it into my texture using the TextureLoader it works perfectly ie. it renders the expected white dots, but that naturally is too slow. If I use the exact same texture directly, the rendered points seem random.
That sounds very strange - possibly more of an application error than one specific to Direct3D. If the contents are correct when saved out then they should be correct when in memory.
Some relevant images and code-fragments (remember to use [ source ] tags [smile]) might help us help you.
Cheers,
Jack
An example of some photons could be as this:
photonmap
If they where shot through a sperical photon generator.
I´m fairly sure that the mistake is my ignorance and not a failure in DirectX.
I create my texture this way :
Texture photonmap = new Texture(device,w,h,1,Usage.None,Format.X8R8G8B8,Pool.Managed);
And apply it this way :
device.SetTexture(0,photonmap);
I do not setup any special TextureStates, do I need to ? It seems there 11 levels in the loaded Texture, whereas I only create it with 1.
I would agree that I´m probably not controlling the min/mag filter or mipmap levels properly. Any tips and help would be appreciated :D
Cheers,
Sune
[Edited by - sune on December 15, 2005 6:12:29 PM]
photonmap
If they where shot through a sperical photon generator.
I´m fairly sure that the mistake is my ignorance and not a failure in DirectX.
I create my texture this way :
Texture photonmap = new Texture(device,w,h,1,Usage.None,Format.X8R8G8B8,Pool.Managed);
And apply it this way :
device.SetTexture(0,photonmap);
I do not setup any special TextureStates, do I need to ? It seems there 11 levels in the loaded Texture, whereas I only create it with 1.
I would agree that I´m probably not controlling the min/mag filter or mipmap levels properly. Any tips and help would be appreciated :D
Cheers,
Sune
[Edited by - sune on December 15, 2005 6:12:29 PM]
It works correctly now, thank for the help.
I found out that it never saved correctly when I used the TextureLoaders save method (which I should´ve done from the beginning).
It was then a matter of writing to the texture, which troubled me (and still does) when I did it using a safe method. The array indices and uv-coordinates did´nt seem to be related in a straightforward manner, some strange wrapping seemed to occur when using a non-square texture. When I used the following unsafe code the texture was written correctly.
I found out that it never saved correctly when I used the TextureLoaders save method (which I should´ve done from the beginning).
It was then a matter of writing to the texture, which troubled me (and still does) when I did it using a safe method. The array indices and uv-coordinates did´nt seem to be related in a straightforward manner, some strange wrapping seemed to occur when using a non-square texture. When I used the following unsafe code the texture was written correctly.
SurfaceDescription s = photonmap.GetLevelDescription(0);uint* data = (uint*)photonmap.LockRectangle(0,LockFlags.None).InternalData.ToPointer(); data[(int)posS.Y*s.Width+(int)posS.X] = (uint)Color.White.ToArgb();photonmap.UnlockRectangle(0);Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement