Jump to content

  • Log In with Google      Sign In   
  • Create Account

Cannot find texture in my effect file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 sas_x86   Members   -  Reputation: 102

Like
0Likes
Like

Posted 13 February 2012 - 06:47 AM

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.

Sponsor:

#2 NightCreature83   Crossbones+   -  Reputation: 3032

Like
1Likes
Like

Posted 13 February 2012 - 01:36 PM

Have you tried just using the GetSamplerIndex with the constant name?
Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#3 sas_x86   Members   -  Reputation: 102

Like
0Likes
Like

Posted 13 February 2012 - 11:29 PM

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


#4 NightCreature83   Crossbones+   -  Reputation: 3032

Like
0Likes
Like

Posted 14 February 2012 - 02:23 AM


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

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, Mad Max




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS