2013-01-19 2 views
0

저는 HLSL의 초보자이며 편평한 삼각형을 그리는 샘플 코드를 가지고 있습니다. 아래의 전역 변수 (mycol)를 참조하는 명시 적 색상을 반환하는 PShader 함수를 대체하려고하면 더 이상 삼각형이 컬러가 아니라 검정색으로 렌더링됩니다.간단한 HLSL 파일이 작동하지 않습니까?

float4 mycol = float4(1.0f, 1.0f, 0.0f, 1.0f); 

float4 VShader(float4 position : POSITION) : SV_POSITION 
{ 
     return position; 
} 

float4 PShader(float4 position : SV_POSITION) : SV_Target 
{ 
    return mycol; // float4(1.0f, 0.0f, 1.0f, 1.0f); 
} 

HLSL 사양을 읽으려고 시도했지만 분명히 뭔가 빠져있는 것 같습니까?

어떤 도움이 감사, G 맨

답변

0

을 나는 당신이 할 수있는 생각 directx에서 상수 버퍼를 사용하는 글로벌 값만 전달합니다. 귀하의 렌더링 코드에서 다음

D3D11_BUFFER_DESC constDesc; 
ZeroMemory(&constDesc, sizeof(constDesc)); 
constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 
constDesc.ByteWidth = sizeof(XMFLOAT4); 
constDesc.Usage = D3D11_USAGE_DEFAULT; 

d3dResult = d3dDevice_->CreateBuffer(&constDesc, 0, &shaderCB_); 

if(FAILED(d3dResult)) 
{ 
    return false; 
} 

:

XMFLOAT4 mycol = XMFLOAT4(1,1,0,1); 
d3dContext_->UpdateSubresource(shaderCB_, 0, 0, &mycol, 0, 0); 

과 쉐이더에서 : 당신은 C++ 코드에서 일정한 버퍼를 시작해야 할

cbuffer colorbuf : register(b0) 
{ 
    float4 mycol; 
}; 
0

그것은 당신이 앞으로 변수 passaing 시도 ... 분리 된 쉐이더를 사용하는 경우 전역 변수 값을 변경 한 것일 수 있습니다

float4 mycol = float4(1.0f, 1.0f, 0.0f, 1.0f); 

struct VS_OUT 
{ 
    float4 pos : SV_Position; 
    float4 color : COLOR0; 
} 

VS_OUT VShader(float4 position : POSITION) 
{ 
    VS_OUT ret; 
    ret.pos = position; 
    ret.color = mycol; // forward variable 
    return ret; 
} 

float4 PShader(VS_OUT input) : SV_Target 
{ 
    return input.color; 
} 
관련 문제