collada: pass light node position to shader
This commit is contained in:
parent
2b0b29aeb9
commit
c395b3e7bb
@ -143,6 +143,7 @@ namespace collada::scene {
|
||||
|
||||
void transfer_transforms(XMMATRIX const & projection,
|
||||
XMMATRIX const & view,
|
||||
XMVECTOR const & light_position_world,
|
||||
int nodes_count,
|
||||
instance_types::node const * const node_instances);
|
||||
|
||||
|
||||
@ -70,6 +70,8 @@ float4 PSMain(VSOutput input) : SV_TARGET
|
||||
{
|
||||
//float3 color = texture.Sample(samplers[0], input.Texture).bgr;
|
||||
float4 diffuseColor = MaterialColors[constants.MaterialIndex].Diffuse;
|
||||
float4 specularColor = MaterialColors[constants.MaterialIndex].Specular;
|
||||
float4 emissionColor = MaterialColors[constants.MaterialIndex].Emission;
|
||||
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightDirection);
|
||||
@ -81,5 +83,5 @@ float4 PSMain(VSOutput input) : SV_TARGET
|
||||
float3 specular = pow(max(dot(R, V), 0), a) * specularIntensity;
|
||||
float3 diffuse = max(dot(N, L), 0.001);
|
||||
|
||||
return float4(diffuse * diffuseColor.xyz + specular, 1.0);
|
||||
return float4(diffuse * diffuseColor.xyz + specular * specularColor.xyz + emissionColor.xyz, 1.0);
|
||||
}
|
||||
|
||||
@ -685,13 +685,14 @@ namespace collada::scene {
|
||||
|
||||
void vulkan::transfer_transforms(XMMATRIX const & projection,
|
||||
XMMATRIX const & view,
|
||||
XMVECTOR const & light_position_world,
|
||||
int nodes_count,
|
||||
instance_types::node const * const node_instances)
|
||||
{
|
||||
// store
|
||||
XMStoreFloat4x4(&shaderData.scene.projection, projection);
|
||||
XMVECTOR lightPosition = XMVector3Transform(XMVectorSet(-42, -40, 156, 0), view);
|
||||
XMStoreFloat4(&shaderData.scene.lightPosition, lightPosition);
|
||||
XMVECTOR lightPositionView = XMVector3Transform(light_position_world, view);
|
||||
XMStoreFloat4(&shaderData.scene.lightPosition, lightPositionView);
|
||||
|
||||
for (int i = 0; i < nodes_count; i++) {
|
||||
XMMATRIX model_view = node_instances[i].world * view;
|
||||
|
||||
@ -1206,6 +1206,7 @@ int main()
|
||||
|
||||
int cameraIndex = collada_state.find_node_index_by_name("Camera001");
|
||||
int cameraTargetIndex = collada_state.find_node_index_by_name("Camera001.Target");
|
||||
int lightIndex = collada_state.find_node_index_by_name("DirectLight");
|
||||
|
||||
while (quit == false) {
|
||||
SDL_Event event;
|
||||
@ -1387,8 +1388,12 @@ int main()
|
||||
XMMATRIX view = currentView(collada_state.node_state.node_instances[cameraIndex],
|
||||
collada_state.node_state.node_instances[cameraTargetIndex]);
|
||||
|
||||
collada::instance_types::node const & lightNode = collada_state.node_state.node_instances[lightIndex];
|
||||
XMVECTOR lightPositionWorld = XMVector3Transform(XMVectorZero(), lightNode.world);
|
||||
|
||||
collada_state.vulkan.transfer_transforms(projection,
|
||||
view,
|
||||
lightPositionWorld,
|
||||
collada_state.descriptor->nodes_count,
|
||||
collada_state.node_state.node_instances);
|
||||
collada_state.draw();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user