Jump to content
  • Advertisement
Sign in to follow this  
sainsaw

[HLSL] Shader doesn't create

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

--PROBLEM FIXED

Hi

I'm trying to write a reflection from cubemap shader:
Here is the shader code:

//SHADER CODE-------------------------------------------

float3 LightDirection = normalize(float3(1, 1, 1));
float3 LightColor = float3(0.6, 0.5, 0.4);
float3 AmbientColor = float3(0.1, 0.15, 0.25);

SamplerState samLinear
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
AddressW = Wrap;
};
TextureCube gCubeMap;
Texture2D gDiffuseMap;

cbuffer cbPerObject
{
float4x4 gViewProj;
float4x4 gWorld;
}

struct VS_IN
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD;
};

struct VS_OUT
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD;
float3 Reflection : TEXCOORD1;
float3 Fresnel : COLOR0;
float3 Lighting : COLOR1;
};

//-----------------------------------------------------
// Vertex Shader
//-----------------------------------------------------

VS_OUT VS(VS_IN vIn)
{
VS_OUT vOut;

// Transform the input values.
float4 worldPosition = mul(vIn.Position, gWorld);
float3 worldNormal = mul(vIn.Normal, gWorld);

vOut.Position = mul(vIn.Position, gViewProj);

vOut.TexCoord = vIn.TexCoord;

// Compute a reflection vector for the environment map.
float3 eyePosition = mul(-gViewProj._m30_m31_m32, transpose(gViewProj));

float3 viewVector = worldPosition - eyePosition;

vOut.Reflection = reflect(viewVector, worldNormal);

// Approximate a Fresnel coefficient for the environment map.
// This makes the surface less reflective when you are looking
// straight at it, and more reflective when it is viewed edge-on.
vOut.Fresnel = saturate(1 + dot(normalize(viewVector), worldNormal));

// Compute lighting.
float lightAmount = max(dot(worldNormal, LightDirection), 0);

vOut.Lighting = AmbientColor + lightAmount * LightColor;

return vOut;
}

//-----------------------------------------------------
// Pixel Shader
//-----------------------------------------------------

float4 PS(VS_OUT pIn): COLOR0
{
// Sample the texture and environment map.
float3 color = gDiffuseMap.Sample(samLinear, pIn.TexCoord).rgb;

float3 envmap = gCubeMap.Sample(samLinear, pIn.Reflection);

// Use the Fresnel coefficient to interpolate between texture and environment map.
color = lerp(color, envmap, pIn.Fresnel);

// Apply lighting.
color *= pIn.Lighting * 2;

return float4(color, 1);
}


technique10 Reflection
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader( CompileShader( ps_4_0, PS()));
}
}

//END OF SHADER CODE----------------





I Don't see what's wrong with it. I'm not even sure the problem lies there.

When trying to filling in the D3D10_PASS_DESC I get an error. The PassDesc doesn't fill in. It works with other shaders though.


//DX10 CODE---------------------------------------------------

D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
UINT numElements = sizeof(layout)/sizeof(layout[0]);

D3D10_PASS_DESC PassDesc;
// Get the pass decriptor from the effect technique
hr = m_pReflectionTech->GetPassByIndex(0)->GetDesc(&PassDesc);
if(FAILED(hr))
MessageBox(0, _T("Technique Creation failed."), _T("ERROR"), 0);

HR(GETD3D10DEVICE->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout ));
m_VertexBufferStride = sizeof(VertexPNT);

//END OF DX10 CODE------------------------------------------



When testing with IsValid() the effect returns 0. But it isn't a NULL-Pointer. It does get created.

Could someone find out what's going wrong???

Thanks in advance

[Edited by - sainsaw on August 23, 2010 2:51:28 AM]

Share this post


Link to post
Share on other sites
Advertisement
EDIT: Readin your posting again: Sorry [smile]

You don't show how the shader is created. I mean the call to D3Dx10CreateShaderFromFile() or something similar.

I'll show you a neat trick to get the errors in the shader: [smile]


ID3D10Blob* Blob_Errors=NULL;

//This is direct3d11, but only the parameter before the last one is important for you. And this is the same in D3D10.
//Short: Set the parameter before the last one to &Blob_Errors in your function!
HRESULT hr=D3DX11CompileFromFile(L"TempShader__.fx", NULL, NULL,NULL, "fx_5_0",D3D10_SHADER_OPTIMIZATION_LEVEL3 | D3D10_SHADER_ENABLE_STRICTNESS, NULL, NULL, &ShaderBlob,&Blob_Errors,NULL);


if(Blob_Errors)
{
MessageBoxA(NULL,(char *)Blob_Errors->GetBufferPointer(),"Error in shader!",MB_OK|MB_ICONERROR);
if(ShaderBlob)
{
ShaderBlob->Release();
}
if(Blob_Errors)
{
Blob_Errors->Release();
}
}




just drop this in there and see what happens!

Share this post


Link to post
Share on other sites
Sorry, forget that code, but I was already checking the shaders for error using this code:


//Shader creation code----------------------------------------------------


// Create the effect
ID3D10Blob * ErrorBlob;

DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3D10_SHADER_DEBUG;
dwShaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

ID3D10Effect* pEffect;
D3DX10CreateEffectFromFile( key.c_str(), NULL, NULL, "fx_4_0", dwShaderFlags, 0,
GETD3D10DEVICE, NULL, NULL, &pEffect, &ErrorBlob,&hr );
if( FAILED( hr ) )
{
if(ErrorBlob){
SIZE_T size = ErrorBlob->GetBufferSize();
LPVOID p_Data = ErrorBlob->GetBufferPointer();
OutputDebugStringA((LPCSTR)p_Data);
MessageBoxA( NULL, (LPCSTR)p_Data, "D3DX10CreateEffectFromFile Error", MB_OK );
ErrorBlob->Release();
}
else
MessageBox( NULL, _T("Unknown D3DX10CreateEffectFromFile Error"), _T("Error"), MB_OK );
return 0;
}

END OF CODE----------------------------------------------


When debugging this code the ID3D10Blob stays NULL, does this mean there aren't any errors in the shader?

thx in advance.

Share this post


Link to post
Share on other sites
Problem Fixed...

In my shader I wrote technique instead of technique10. Stupid mistake by converting older shaders in new versions.

Thx for your help.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!