• Advertisement
Sign in to follow this  

tex2Dlod

This topic is 3729 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

Hi, I have generated a terrain, some of whose vertices z coord is != 0. I wish to make the color dark only at those points. I use vs, ps 3.0 to do this. So my code is something like this :

sampler MySampler
{
Texture = (tex0);
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
};

struct VS_OUTPUT
{
  float4 Position : POSITION;
  float2 Tex      : TEXCOORD0;
  float4 Diffuse  : COLOR0;
 };

//Vertex shader
VS_OUTPUT VS (float3 Pos : POSITION,float3 norm : NORMAL,float2 Tex : TEXCOORD0)
{

  VS_OUTPUT Output = (VS_OUTPUT)0;

  float4 diff = tex2Dlod (MySampler, float4(Tex.x,Tex.y,0,0));
  if (Pos.z != 0.0f)
  {
    diff = diff * 0.5f;
  }
   
  Output.Diffuse = diff;
   
  Output.Position = mul( float4(Pos,1),worldViewProj);
 
  Output.Tex   =    Tex;
  return Output;
}

[/Source]
My pixel shader code is :
[Source]
void PS (VS_OUTPUT IN, out float4 oColor:COLOR0)
{
  oColor = IN.Diffuse;
}

[/Source]
EACH time I use tex2Dlod, everything disappears. It does not show any error. I have not modified the vertices anywhere in the vertex shader. Please tell me what's wrong. Or can u think of a different approach which doesn't use tex2Dlod? Thanks, Saranya

Share this post


Link to post
Share on other sites
Advertisement
Have you made sure no calls are failing? Specifically, is the DrawPrimitive call succeeding? Are the Begin and BeginPass calls on the effect succeeding?

Have you enabled the Debug Runtimes, and is there any debug output appearing?

Share this post


Link to post
Share on other sites
DrawPrimitive works fine. If I give something like diff = (1.0f,1.0f,1.0f,1.0f). Only when I use tex2Dlod, I get this problem.
When I use PIX, I get this :

Frame 000001 ............POST: <D3DXERR_INVALIDDATA> D3DXCreateEffectFromFileExA(0x028E9090, 0x0041991C, NULL, NULL, NULL, 0x00000000, NULL, 0x0012FC74, 0x0012FDDC)
Frame 000001 ........POST: <D3DXERR_INVALIDDATA> D3DXCreateEffectFromFileA(0x028E9090, 0x0041991C, NULL, NULL, 0x00000000, NULL, 0x0041C26C, 0x0012FDDC)
An unhandled exception occurred.

Share this post


Link to post
Share on other sites
The error message tells you that vertex shader is failing to compile. Since you only just added the tex2Dlod you can be fairly sure that it caused the failure ;)

If I'm guessing right about the effect you're after I think you want to read it in the pixel shader instead. You can just store the diffuse multiplier in the vertex shader, and do the actual texture read and multiply in the pixel shader. It would look something like:


// Vertex shader
Output.Diffuse = (Pos.z == 0.0f) ? 0.5f : 1.0f;
Output.Position = mul( float4(Pos,1),worldViewProj);
Output.Tex = Tex;
return Output;

// Pixel shader
oColor = tex2D(MySampler, IN.Tex) * IN.Diffuse;

Share this post


Link to post
Share on other sites
Hi,
I managed to get a change in color using what Adam_42 said. But I get INVALIDDATA even if I don't use tex2Dlod.

Thanks Adam :)

Share this post


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

  • Advertisement