tex2Dlod

Started by
5 comments, last by ankhd 16 years, 2 months ago
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
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?
Sirob Yes.» - status: Work-O-Rama.
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.
Kind of urgent, folks. Any help will be greatly appreciated.
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 shaderOutput.Diffuse = (Pos.z == 0.0f) ? 0.5f : 1.0f;Output.Position = mul( float4(Pos,1),worldViewProj);Output.Tex = Tex;return Output;// Pixel shaderoColor = tex2D(MySampler, IN.Tex) * IN.Diffuse;
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 :)
Hi I had this error in the end it was my video card is only Shader 2 vertex and pixel have you checked..

This topic is closed to new replies.

Advertisement