Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


sas_x86

Member Since 17 Nov 2010
Offline Last Active May 18 2012 10:24 PM

Topics I've Started

HLSL Pixel Shader returns (0,0,0,0)

08 May 2012 - 09:13 AM

Hello.
There is a shader which implements shadow map technique
struct VS_INPUT { float4 Pos : POSITION0; float4 Normal: NORMAL; float4 Color : COLOR; float2 TexCoords : TEXCOORD0; float4 TexWeights : TEXCOORD1; };

float4x4 xLightWorld;
float4x4 xLightView;
float4x4 xLightProjection;

struct SMapVertexToPixel { float4 Position : POSITION0; float4 Position2D : POSITION1; };

SMapVertexToPixel ShadowMapVertexShader(VS_INPUT In)
{ SMapVertexToPixel Output = (SMapVertexToPixel)0;
Output.Position = mul(In.Pos, xLightWorld);
Output.Position = mul(Output.Position, xLightView);
Output.Position = mul(Output.Position, xLightProjection);
Output.Position2D = Output.Position; return Output; }

float4 ShadowMapPixelShader(SMapVertexToPixel PSIn) : COLOR
{
	 return float4(PSIn.Position2D.z/PSIn.Position2D.w, 0, 0, 1);
}

I run this code in PIX in Debugger window and for some pixel i have
ShadowMapPixelShader | ( 0.161, 0.000, 0.000, 1.000 ) | float4
but in Render window all pixels are black.
If i change code
float4 ShadowMapPixelShader(SMapVertexToPixel PSIn) : COLOR
{
	 return float4(0.5f, 0, 0, 1);
}
all pixels will be little bit red.
Why?

Cannot find texture in my effect file

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.

SetFVF or compiler do this

02 December 2010 - 08:32 PM

Hello.
I write this

#define FVF_COLOR (D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_NORMAL)
SetFVF(FVF_COLOR)

but see in PIX this

IDirect3DDevice::SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)

Why?

Cannot render scene with scale

17 November 2010 - 01:07 AM

Hello anybody. My first shader renders a mesh so well in this state

void DrawModel (MyMesh Model, LPDIRECT3DTEXTURE9 * meshTextures) {
Effect->SetTechnique("Simplest");
D3DXMATRIX mTranslation;
D3DXMatrixTranslation(&mTranslation, 0, 0, 0);
Effect->SetMatrix("xWorldViewProjection", &(matView * matProj * mTranslation));

UINT Passes;
Effect->Begin(&Passes, 0);
for (UINT Pass = 0; Pass < Passes; Pass++)
{
Effect->BeginPass(Pass);
for (DWORD i=0; i<Model.numMaterials; i++)
{
Effect->SetTexture("xTexture", meshTextures[i]);
Effect->CommitChanges();
DXOutDevice->SetMaterial(&(Model.meshMaterials[i]));
Model.Mesh->DrawSubset(i);
}
Effect->EndPass();
}
Effect->End();
}





I see a small model
but if i want translate model to (1,1,1)

void DrawModel (MyMesh Model, LPDIRECT3DTEXTURE9 * meshTextures) {
Effect->SetTechnique("Simplest");
D3DXMATRIX mTranslation;
D3DXMatrixTranslation(&mTranslation, 1, 1, 1);
Effect->SetMatrix("xWorldViewProjection", &(matView * matProj * mTranslation));

UINT Passes;
Effect->Begin(&Passes, 0);
for (UINT Pass = 0; Pass < Passes; Pass++)
{
Effect->BeginPass(Pass);
for (DWORD i=0; i<Model.numMaterials; i++)
{
Effect->SetTexture("xTexture", meshTextures[i]);
Effect->CommitChanges();
DXOutDevice->SetMaterial(&(Model.meshMaterials[i]));
Model.Mesh->DrawSubset(i);
}
Effect->EndPass();
}
Effect->End();
}





I see only black screen
What is the problem?

PARTNERS