내가 Directx11 .I 새로운 오전에 녹색을 출력하고 내 지점으로 가벼운 동작을 만들고 싶었 program.So 그래서알파 채널 역할을하고 directx11와 C++
struct PointLights
{
XMFLOAT3 Pos; //Light Position in (X,Y,Z)
float Range; //the range after which objects will not be affected by this light
XMFLOAT4 Color; //Light Color
XMFLOAT3 att; // Attenuation Parameters
float Intensity;
};
같은 구조체를 정의 그리고 일정에 추가 i는 POI를 업데이트 할 때
struct ConstantBuffer
{
XMMATRIX World;
XMMATRIX WorldInv;
XMMATRIX View;
XMMATRIX Project;
XMFLOAT3 LighDirs[2];
XMFLOAT4 LightColor[2];
float SpecualrIntensity;
XMFLOAT3 CameraPos;
PointLights pointLight;
};
같이이 함수는 현재의 버퍼를
void InitConstantBuffer(void)
{
D3D11_BUFFER_DESC desc;
SecureZeroMemory(&desc,sizeof(desc));
desc.BindFlags= D3D11_BIND_CONSTANT_BUFFER;
desc.ByteWidth = sizeof(ConstantBuffer);
desc.CPUAccessFlags = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
SecureZeroMemory(&g_ConstantBuffer,sizeof(ID3D11Buffer));
HRESULT HR= dev->CreateBuffer(&desc,0,&g_ConstantBuffer);
if(FAILED(HR))
MessageBox(_hwnd,L"Couldnt Create constant buffer",L"ERROR",0);
}
를 만드는 데 사용 된 버퍼 NT에 검은 색을 조명하되 알파 세트 1 (0,0,0,1) 넣어 아웃 녹색과 알파 0 (0,0,0,0)
PointLights pointLight;
SecureZeroMemory(&pointLight,sizeof(PointLights));
pointLight.att = XMFLOAT3(0,0,1);
pointLight.Intensity = 5;
pointLight.Pos = XMFLOAT3(Lppos[0],Lppos[1],Lppos[2]);
pointLight.Range = 200;
pointLight.Color = XMFLOAT4(0,0,0,1); // black
ConstantBuffer cb;
cb.World = XMMatrixTranspose(g_World);
cb.View = XMMatrixTranspose(g_View);
cb.Project = XMMatrixTranspose(g_Projection);
cb.WorldInv = InverseTranspose(g_World);
cb.LighDirs[1] = lights[1].Dir;
cb.LightColor[1] = lights[1].Color;
cb.LightColor[0] = lights[0].Color;cb.LighDirs[0] = lights[0].Dir;
cb.LightColor[0] = lights[0].Color;
cb.SpecualrIntensity = 10;
cb.CameraPos = XMFLOAT3(0,0,-10);
cb.pointLight = pointLight;
devcon->UpdateSubresource(g_ConstantBuffer,0,0,&cb,0,0);
경우 출력 흑색 ! 유래 늘 나를 보자으로 ... 내가 여기
는 했나 픽셀 쉐이더
struct PointLights{
float3 Position;
float Range;
float4 Color;
float3 Atten;
float Intensity;
};
cbuffer ConstantBuffer:register(b0)
{
matrix world;
matrix worldInv;
matrix view;
matrix project;
float3 LightDir[2];
float4 LightColor[2];
float SpecualrIntensity;
float3 CameraPos;
PointLights pointLight;
};
float4 Ps(Vout vo):SV_TARGET
{
float4 col = (float4)0;
col = pointLight.Color;
return col;}
입니다 싫어 [1]
가캔트 업로드 이미지 [출력은 녹색]주세요 그것은 C++ 상수 버퍼 구조와 HLSL의 cbuffer 선언 사이의 데이터 정렬이 꽤 일치를 수행하는 것이 매우 가능성이 높습니다 .... 내가 구조체의 멤버하지만 여전히 헛된
감사에 정리 시도 ..
구조체 ConstantBuffer에서''XMMATRIX''를 사용하고 있습니다. 이것은 작동 방식에 따라 _ 작동 할 수도 _ 불가능할 수도 있습니다. ''ConstantBuffer''는 메모리에서 16 바이트 정렬을 필요로합니다. –