Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem Loading pixel Shader


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 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 06 December 2012 - 10:41 AM

Hey there,

recently wrote a function to read in my shader files and write them to the buffers. For some reason my pixel shader isn't been created and causing the entire class to return false during initialization. I've narrowed it down to a single line of code where it goes wrong as you can see from this screenshot here:

http://img833.imageshack.us/img833/1641/pixelshaderbroken.png

it then of course returns the value of 'r' as false and will not initialize the shader class.

Here is the function:

/* Initialize the Shader function to load in our HLSL files */
bool SkyboxShader::InitShader(ID3D11Device* device, HWND hwnd, CHAR* vsName, CHAR* psName)
{
HRESULT r;
unsigned int numEle;
ID3D10Blob* errorMsg;
ID3D10Blob* vertexSB;
ID3D10Blob* pixelSB;
D3D11_BUFFER_DESC matrixBD;
D3D11_BUFFER_DESC gradientBD;
D3D11_INPUT_ELEMENT_DESC pLayout[1];
errorMsg = 0;
vertexSB = 0;
pixelSB  = 0;
//Load the vertex shader
r = D3DX11CompileFromFile(vsName, NULL, NULL, "SkyboxVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexSB, &errorMsg, NULL);
if(FAILED(r))
{
  if(errorMsg)
  {OutputShaderErrorMessage(errorMsg, hwnd, vsName);}
  else
  {MessageBox(hwnd, vsName, "Skybox.vs missing", MB_OK);}
  return false;
}
//Load the pixel shader
r = D3DX11CompileFromFile(psName, NULL, NULL, "SkyboxPixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelSB, &errorMsg, NULL);
if(FAILED(r))
{
  if(errorMsg)
  {OutputShaderErrorMessage(errorMsg, hwnd, psName);}
  else
  {MessageBox(hwnd, psName, "Skybox.ps missing", MB_OK);}
  return false;
}
//Create vertex shader
r = device->CreateVertexShader(vertexSB->GetBufferPointer(), vertexSB->GetBufferSize(), NULL, &g_vertexShader);
if(FAILED(r))
{return false;}
//Create pixel shader
r = device->CreatePixelShader(pixelSB->GetBufferPointer(), pixelSB->GetBufferSize(), NULL, &g_pixelShader);
if(FAILED(r))
{return false;}
//Create shader description
pLayout[0].SemanticName   = "POSITION";
pLayout[0].SemanticIndex  = 0;
pLayout[0].Format    = DXGI_FORMAT_R32G32B32_FLOAT;
pLayout[0].InputSlot   = 0;
pLayout[0].AlignedByteOffset = 0;
pLayout[0].InputSlotClass  = D3D11_INPUT_PER_VERTEX_DATA;
pLayout[0].InstanceDataStepRate = 0;
numEle = sizeof(pLayout) / sizeof(pLayout[0]);
//Create vertex input
r = device->CreateInputLayout(pLayout, numEle, vertexSB->GetBufferPointer(), vertexSB->GetBufferSize(), &g_layout);
if(FAILED(r))
{return false;}
//Release vertex and pixel buffers
vertexSB->Release();
vertexSB = 0;
pixelSB->Release();
pixelSB = 0;
//Setup matrix constant buffers
matrixBD.Usage	 = D3D11_USAGE_DYNAMIC;
matrixBD.ByteWidth    = sizeof(MatrixBufferType);
matrixBD.BindFlags    = D3D11_BIND_CONSTANT_BUFFER;
matrixBD.CPUAccessFlags   = D3D11_CPU_ACCESS_WRITE;
matrixBD.MiscFlags    = 0;
matrixBD.StructureByteStride = 0;
//Create matrix constant buffer
r = device->CreateBuffer(&matrixBD, NULL, &g_matrixBuffer);
if(FAILED(r))
{return false;}
//Setup gradient constant buffer
gradientBD.Usage    = D3D11_USAGE_DYNAMIC;
gradientBD.ByteWidth   = sizeof(GradientBufferType);
gradientBD.BindFlags   = D3D11_BIND_CONSTANT_BUFFER;
gradientBD.CPUAccessFlags  = D3D11_CPU_ACCESS_WRITE;
gradientBD.MiscFlags   = 0;
gradientBD.StructureByteStride = 0;
//Create gradient constant buffer
r = device->CreateBuffer(&gradientBD, NULL, &g_gradientBuffer);
if(FAILED(r))
{return false;}
return true;
}

And the pixel shader it is trying to load

//Skybox.ps
//Skybox Pixel Shader File
//Globals
cbuffer GradientBuffer
{
float4 apexColour;
float4 centreColour;
};
//Typedefs
struct PixelInputType
{
float4 position : SV_POSITION;
float4 skyboxTexture : TEXCOORD0;
};
//Pixel Shader
float4 SkyboxPixelShader(PixelInputType input) : SV_TARGET
{
    float height;
    float4 outputColor;
    height = input.skyboxTexture.y;
    if(height < 0.0)
    {height = 0.0f;}
    outputColor = lerp(centreColour, apexColour, height);
    return outputColor;
}

I've had some problem with SV_TARGET coming back as an error aswell, I've tried changing it to SV_POSITION with no luck. Can anyone see whats wrong?

Thanks

Sponsor:

#2 DgekGD   Members   -  Reputation: 374

Like
0Likes
Like

Posted 06 December 2012 - 10:58 AM

I cannot see any problem right now, but you can check exact value of 'r' after executing this function. It contains value that can point you to an error. Take a look here.

Edited by DgekGD, 06 December 2012 - 11:00 AM.


#3 Zaoshi Kaba   Crossbones+   -  Reputation: 3882

Like
1Likes
Like

Posted 06 December 2012 - 11:02 AM

You're compiling Pixel Shader as Vertex Shader:

D3DX11CompileFromFile(psName, NULL, NULL, "SkyboxPixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelSB, &errorMsg, NULL);


Edited by Zaoshi Kaba, 06 December 2012 - 11:05 AM.


#4 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 06 December 2012 - 11:11 AM

You're compiling Pixel Shader as Vertex Shader:


D3DX11CompileFromFile(psName, NULL, NULL, "SkyboxPixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelSB, &errorMsg, NULL);


haha omg, what a screw up. Thanks for spotting it man




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