//source code
IDirect3DTexture9* mRandomMap;
HR(D3DXCreateTexture(gd3dDevice, 256, 0, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_DEFAULT, &mRandomMap));
D3DLOCKED_RECT r;
HR(mRandomMap->LockRect(0, &r, NULL, 0));
for(int i = 0; i < 256; ++i)
((char*)r.pBits) = 128;
HR(mRandomMap->UnlockRect(0));
//shader code
uniform extern texture gTexRandomMap;
sampler RandoMapS = sampler_state
{
Texture = <gTexRandomMap>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = WRAP;
AddressV = WRAP;
};
struct OutputVS
{
float4 posH : POSITION0;
float2 tex : TEXCOORD0;
};
OutputVS TransformVS(float3 posL : POSITION0)
{
OutputVS outVS = (OutputVS)0;
outVS.posH = mul(float4(posL, 1.0f), gWVP);
outVS.tex = float2(0.5f, 0.5f);
return outVS;
}
float4 TransformPS(OutputVS inP) : COLOR
{
float r = tex1D(RandoMapS, inP.tex);
return float4(r, r, r, 1);
}
Trying to create 1d texture
Hi,
Im having problems creating a 1d texture, to use in a shader. I just get black returned to me in the pixel shader. The Texture needs to be 256x1, and only i channel, and at the moment im just filling with grey to test it.
Here is my code.
I read on MSDN that you have to have the texture coordinates for a 1d texture as float2, as tex1d also uses float2, so this is what i did. As if i dont i get error warning messages.
One quick additional thing, check the support for D3DFMT_A8 - ISTR cardcaps.xls reported only one major vendor supporting that format and D3DXCreateTexture() is at liberty to alter your parameters if it wants, thus you may not be writing the data in the correct format!
That said, I'd imagine it'll cast it down and use the 'x' value so may not be too big a deal.
Also, you may want to try explicitly stating which channel you want returned. If the aforementioned problem is non-existant then your 'a' channel will contain the 0.5f value. However you're implictly casting a float4 to a float which, iirc, will take the 1st component - red, which would be zero and thus match your results. Try adding a ".a" qualifier to your tex1D call.
hth
Jack
Quote:I read on MSDN that you have to have the texture coordinates for a 1d texture as float2Where did you read that? My offline docs from the March '09 SDK and MSDN equivalent say it's a single element scalar for the 2nd parameter!
That said, I'd imagine it'll cast it down and use the 'x' value so may not be too big a deal.
Also, you may want to try explicitly stating which channel you want returned. If the aforementioned problem is non-existant then your 'a' channel will contain the 0.5f value. However you're implictly casting a float4 to a float which, iirc, will take the 1st component - red, which would be zero and thus match your results. Try adding a ".a" qualifier to your tex1D call.
hth
Jack
Hey JollyJeffers,
Well i cant find that page anymore, but i believe i have it bookmarked on my other comp, so i'll paste it here if i do.
But why do you say that the 'a' channel will have the value though? I know that the format is called D3DFMT_A8, with the a specifying alpha, but wouldnt the value get put into the first component of the returned float4? thus being x? I couldnt find any infomation that explicity states where the value gets stored.
Say you have other formats, such as
How exactly do you know, where the result in the float4 returned from a call to a tex() will be?
Do i just assume from the name, in that D3DFMT_G16R16 - G = y and R = x?
Also, when declaring samplers in effect files, ive noticed that a lot of people, even when using cube maps or other none 2d textures, still have the samplers set as
and dont seem to use any of the others, such as
What exactly are sampler, sampler_state and SamplerState used for?
if im using a 1d texture, should i be setting sampler1D in the sampler?
such as
...sorry for all the questions :P
Thanks
Well i cant find that page anymore, but i believe i have it bookmarked on my other comp, so i'll paste it here if i do.
But why do you say that the 'a' channel will have the value though? I know that the format is called D3DFMT_A8, with the a specifying alpha, but wouldnt the value get put into the first component of the returned float4? thus being x? I couldnt find any infomation that explicity states where the value gets stored.
Say you have other formats, such as
D3DFMT_A8L8D3DFMT_G16R16
How exactly do you know, where the result in the float4 returned from a call to a tex() will be?
Do i just assume from the name, in that D3DFMT_G16R16 - G = y and R = x?
Also, when declaring samplers in effect files, ive noticed that a lot of people, even when using cube maps or other none 2d textures, still have the samplers set as
sampler MeshTextureSampler = sampler_state
and dont seem to use any of the others, such as
sampler,sampler1D, sampler2D, sampler3D, samplerCUBE, sampler_state, SamplerState
What exactly are sampler, sampler_state and SamplerState used for?
if im using a 1d texture, should i be setting sampler1D in the sampler?
such as
sampler MeshTextureSampler = sampler1D { Texture = <g_MeshTexture>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR;};
...sorry for all the questions :P
Thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement