Nicholas Vaughn
Nicholas Vaughn

Reputation: 245

shader.hlsl file causes error?

I'm working on trying to get this DirectX11 proj to load a triangle on the screen that uses a shader.hlsl file to color the triangle based on the positions within the triangle (it is a multi colored triangle that blends together). I am not getting a normal output error either this time. Not sure how to approach/handle this one.

//function that invokes the shaders.hlsl file

void InitPipeline()

{

// load and compile the two shaders

ID3D10Blob *VS, *PS;
D3DX11CompileFromFile("shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0);
D3DX11CompileFromFile("shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, 0, 0);

// encapsulate both shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

// set the shader objects
devcon->VSSetShader(pVS, 0, 0);
devcon->PSSetShader(pPS, 0, 0);

// create the input layout object
D3D11_INPUT_ELEMENT_DESC ied[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
};

dev->CreateInputLayout(ied, 2, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout);
devcon->IASetInputLayout(pLayout);

}

struct VOut { 
    float4 position : SV_POSITION; 
    float4 color : COLOR; 
}; 

VOut VShader(float4 position : POSITION, float4 color : COLOR) { 
    VOut output; 
    output.position = position; 
    output.color = color; 
    return output; 
} 

float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET {
    return color; 
} 

Upvotes: 0

Views: 1491

Answers (1)

Dis
Dis

Reputation: 11

Are you using Visual Studio? Right click shaders.hlsl, find the complete path, and replace shaders.hlsl in your D3DX11CompileFromFile functions with the absolute path. Make sure to replace \ characters with \\ for it to be escaped properly.

Visual Studio leaves the shaders.hlsl in the same location as the source code which means that your program can't find it. Is the blue window still displaying? That's the issue I was having.

Upvotes: 1

Related Questions