• Advertisement
Sign in to follow this  

Cannot find texture in my effect file

This topic is 2166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello All.
I have some problem with my shader. I have function which sets variables in my pixel shader. It works fine for all my shaders, but not for this

[code]float4x4 xView;
float4x4 xProjection;
float4x4 xWorld;
float3 xCamPos;
float3 xAllowedRotDir;
Texture xBillboardTexture : TEXTURE0;
sampler textureSamplerTree = sampler_state
{
texture = <xBillboardTexture>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
struct BBVertexToPixel
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};
struct BBPixelToFrame
{
float4 Color : COLOR0;
};
BBPixelToFrame BillboardPS(BBVertexToPixel PSIn)
{
BBPixelToFrame Output = (BBPixelToFrame)0;
Output.Color = tex2D(textureSamplerTree, PSIn.TexCoord);
return Output;
}
/*Vertex shader not important*/
BBVertexToPixel CylBillboardVS(float3 inPos: POSITION0, float2 inTexCoord: TEXCOORD0)
{
BBVertexToPixel Output = (BBVertexToPixel)0;
float4 inPosTmp = float4(inPos, 1);
float4 center = mul(inPosTmp, xWorld);
float3 eyeVector = center.xyz - xCamPos;
float3 upVector = xAllowedRotDir;
upVector = normalize(upVector);
float3 sideVector = cross(eyeVector,upVector);
sideVector = normalize(sideVector);
float3 finalPosition = center.xyz;
finalPosition += (inTexCoord.x-0.5f)*sideVector * 5.0f;
finalPosition += (1.5f-inTexCoord.y*1.5f)*upVector * 5.0f;
float4 finalPosition4 = float4(finalPosition, 1);
float4x4 preViewProjection = mul (xView, xProjection);
Output.Position = mul(finalPosition4, preViewProjection);
Output.TexCoord = inTexCoord;
return Output;
}[/code]

Now my setter function
[code]HRESULT Shader::SetTexture(IDirect3DTexture9 * baseTexture, char * var_name)
{
D3DXHANDLE handle;
handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (localDevice && pdxPixelConstants && (handle = pdxPixelConstants->GetConstantByName(NULL, var_name)))
{
DWORD shaderSamplerIndex = pdxPixelConstants->GetSamplerIndex(handle);
localDevice->SetTexture(shaderSamplerIndex, baseTexture);
return S_OK;
}
return E_FAIL;
}[/code]

and always GetConstantByName(NULL, "xBillboardTexture") returns me NULL.

I can't understand where is problem.

Share this post


Link to post
Share on other sites
Advertisement
[quote name='NightCreature83' timestamp='1329161779' post='4912698']
Have you tried just using the GetSamplerIndex with the constant name?
[/quote]
thanks a lot.
I add this unpleasant code
[code] handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (strcmp(var_name, "xBillboardTexture") == 0)
{
HRESULT res = localDevice->SetTexture(0, baseTexture);
return res;
}[/code]

Share this post


Link to post
Share on other sites
[quote name='sas_x86' timestamp='1329197395' post='4912895']
[quote name='NightCreature83' timestamp='1329161779' post='4912698']
Have you tried just using the GetSamplerIndex with the constant name?
[/quote]
thanks a lot.
I add this unpleasant code
[code] handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (strcmp(var_name, "xBillboardTexture") == 0)
{
HRESULT res = localDevice->SetTexture(0, baseTexture);
return res;
}[/code]
[/quote]
Thats an extremely hardcoded version of setting sampler 0, why?
[code]
D3DXHANDLE handle;
handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (localDevice && pdxPixelConstants && (handle = pdxPixelConstants->GetConstantByName(NULL, var_name)))
[/code]
That line doesn't make sense in your original code anyway as you are overwriting handle of a vertex texure with that of a pixel texture. Assignments in an if aren't nice anyway especially when there are more arguments in the condition.
But I have a feeling that just using GetSamplerIndex with your constant name will work as D3DXHANDLES are just strings anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement