utolsó, teljes változat
This commit is contained in:
parent
cc27d73ade
commit
acfffaac18
5
Cam.cpp
5
Cam.cpp
@ -118,6 +118,11 @@ void eg3d::Cam::pitch(float drho) {
|
|||||||
constructViewMatrix();
|
constructViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const XMFLOAT3& eg3d::Cam::getViewDirection() const
|
||||||
|
{
|
||||||
|
return mVViewDirection;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
eg3d::ProjParams::ProjParams() {
|
eg3d::ProjParams::ProjParams() {
|
||||||
|
2
Cam.h
2
Cam.h
@ -64,6 +64,8 @@ namespace eg3d {
|
|||||||
void strafe(float ds); // kamera mozgatása a nézetre merõlegesen
|
void strafe(float ds); // kamera mozgatása a nézetre merõlegesen
|
||||||
void yaw(float dphi); // kamera forgatása
|
void yaw(float dphi); // kamera forgatása
|
||||||
void pitch(float drho); // kamera billentése
|
void pitch(float drho); // kamera billentése
|
||||||
|
|
||||||
|
const XMFLOAT3& getViewDirection() const; // nézet irányának elkérése
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
16
DXWindow.cpp
16
DXWindow.cpp
@ -384,6 +384,22 @@ namespace eg3d {
|
|||||||
|
|
||||||
XMFLOAT3 camPos = pCam->getViewParams().position;
|
XMFLOAT3 camPos = pCam->getViewParams().position;
|
||||||
constantBuffer.camPosition = { camPos.x, camPos.y, camPos.z, 0.0 };
|
constantBuffer.camPosition = { camPos.x, camPos.y, camPos.z, 0.0 };
|
||||||
|
|
||||||
|
// megvilágítás iránya
|
||||||
|
//XMVECTOR lightDir = XMVectorSet(1.0, 1.0, 1.0, 0.0);
|
||||||
|
XMFLOAT3 viewDir = pCam->getViewDirection();
|
||||||
|
XMVECTOR lightDir;
|
||||||
|
lightDir = XMLoadFloat3(&viewDir);
|
||||||
|
lightDir = -XMVector4Normalize(lightDir);
|
||||||
|
//lightDir = XMVector4Transform(lightDir, XMMatrixRotationY(lightAngle));
|
||||||
|
lightDir = XMVector4Transform(lightDir, XMMatrixRotationY(0));
|
||||||
|
XMStoreFloat4(&constantBuffer.lightDir, lightDir);
|
||||||
|
|
||||||
|
// fény iránya
|
||||||
|
lightAngle += 0.01f;
|
||||||
|
if (lightAngle > XM_2PI) {
|
||||||
|
lightAngle -= XM_2PI;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferMapCopy(cbResource, static_cast<void *>(&constantBuffer), sizeof(constantBuffer));
|
bufferMapCopy(cbResource, static_cast<void *>(&constantBuffer), sizeof(constantBuffer));
|
||||||
|
@ -86,6 +86,9 @@ namespace eg3d {
|
|||||||
|
|
||||||
// virtuális kamera
|
// virtuális kamera
|
||||||
Cam * pCam;
|
Cam * pCam;
|
||||||
|
|
||||||
|
// egyebek
|
||||||
|
float lightAngle = 0.0f;
|
||||||
|
|
||||||
void initDrawObjects(); // kirajzolandó objektumok inicializálása
|
void initDrawObjects(); // kirajzolandó objektumok inicializálása
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ struct VSInput // vertex shader bemeneti strukt
|
|||||||
struct VSOutput // vertex shader kimeneti struktúra
|
struct VSOutput // vertex shader kimeneti struktúra
|
||||||
{
|
{
|
||||||
float4 position_H : SV_Position;
|
float4 position_H : SV_Position;
|
||||||
float3 color : COLOR;
|
float3 diffuse : DIFFUSE;
|
||||||
|
float3 ambient : AMBIENT;
|
||||||
float3 worldPosition : WORLDPOS;
|
float3 worldPosition : WORLDPOS;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,6 +18,8 @@ cbuffer CFrame : register(b0)
|
|||||||
float4x4 viewMatrix;
|
float4x4 viewMatrix;
|
||||||
float4x4 projMatrix;
|
float4x4 projMatrix;
|
||||||
float4 camPosition;
|
float4 camPosition;
|
||||||
|
|
||||||
|
float4 lightDir;
|
||||||
};
|
};
|
||||||
cbuffer CEntity : register(b1)
|
cbuffer CEntity : register(b1)
|
||||||
{
|
{
|
||||||
@ -32,12 +35,18 @@ VSOutput vs_main(VSInput input)
|
|||||||
output.position_H = mul(worldCoords, mul(viewMatrix, projMatrix));
|
output.position_H = mul(worldCoords, mul(viewMatrix, projMatrix));
|
||||||
|
|
||||||
// TODO fények
|
// TODO fények
|
||||||
float3 L = normalize(float3(1.0, 1.0, 0.5));
|
float3 L = lightDir;
|
||||||
float3 I = float3(1.0, 1.0, 0.8);
|
float3 I = float3(1.0, 1.0, 0.8);
|
||||||
float3 md = float3(1.0, 0.1, 0.1);
|
float3 md = color.xyz; //float3(1.0, 0.9, 0.9);
|
||||||
|
float3 Ia = float3(0.2, 0.2, 0.2);
|
||||||
|
|
||||||
//float3 p = float3(1440, 370, -1365);
|
//float3 p = float3(1440, 370, -1365);
|
||||||
output.color = (I * color.xyz) * max(dot(input.normal, L), 0);
|
output.diffuse = (I * md) * max(dot(input.normal, L), 0);
|
||||||
|
output.ambient = (Ia * md);
|
||||||
|
|
||||||
|
|
||||||
|
/* / length(worldCoords.xyz -
|
||||||
|
camPosition.xyz) * 200;*/
|
||||||
|
|
||||||
output.worldPosition = worldCoords;
|
output.worldPosition = worldCoords;
|
||||||
|
|
||||||
@ -54,8 +63,9 @@ PSOutput ps_main(VSOutput input)
|
|||||||
PSOutput output;
|
PSOutput output;
|
||||||
|
|
||||||
//output.color = float4(0.0f, 1.0f, 0.0f, 1.0f);
|
//output.color = float4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
output.color = float4(input.color, 1.0f) / length(input.worldPosition -
|
output.color = float4(input.diffuse, 1.0f) / length(input.worldPosition -
|
||||||
camPosition.xyz) * 200;
|
camPosition.xyz) * 200 + float4(input.ambient, 1.0);
|
||||||
|
//output.color = float4(input.color, 1.0);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ struct CB_Frame
|
|||||||
DirectX::XMFLOAT4X4 viewMatrix; // nézet-mátrix
|
DirectX::XMFLOAT4X4 viewMatrix; // nézet-mátrix
|
||||||
DirectX::XMFLOAT4X4 projMatrix; // vetítési mátrix
|
DirectX::XMFLOAT4X4 projMatrix; // vetítési mátrix
|
||||||
DirectX::XMFLOAT4 camPosition; // kamerapozíció
|
DirectX::XMFLOAT4 camPosition; // kamerapozíció
|
||||||
|
|
||||||
|
DirectX::XMFLOAT4 lightDir; // fény iránya
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CB_Entity {
|
struct CB_Entity {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user