Cannot find texture in my effect file

Started by
2 comments, last by NightCreature83 12 years, 2 months ago
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

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;
}


Now my setter function
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;
}


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

I can't understand where is problem.
Advertisement
Have you tried just using the GetSamplerIndex with the constant name?

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


Have you tried just using the GetSamplerIndex with the constant name?

thanks a lot.
I add this unpleasant code
handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (strcmp(var_name, "xBillboardTexture") == 0)
{
HRESULT res = localDevice->SetTexture(0, baseTexture);
return res;
}

[quote name='NightCreature83' timestamp='1329161779' post='4912698']
Have you tried just using the GetSamplerIndex with the constant name?

thanks a lot.
I add this unpleasant code
handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (strcmp(var_name, "xBillboardTexture") == 0)
{
HRESULT res = localDevice->SetTexture(0, baseTexture);
return res;
}

[/quote]
Thats an extremely hardcoded version of setting sampler 0, why?

D3DXHANDLE handle;
handle = pdxVertexConstants->GetConstantByName(NULL, var_name);
if (localDevice && pdxPixelConstants && (handle = pdxPixelConstants->GetConstantByName(NULL, var_name)))

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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement