Slightly reworked glTF samples

Parent matrices are now applied (where available)
Now more in line with the base code glTF loader
Refs #964
This commit is contained in:
Sascha Willems 2022-08-06 10:16:54 +02:00
parent 465c18862c
commit f084d6093c
11 changed files with 71 additions and 50 deletions

View file

@ -17,7 +17,7 @@ void main()
vec3 N = normalize(inNormal);
vec3 L = normalize(inLightVec);
vec3 V = normalize(inViewVec);
vec3 R = reflect(-L, N);
vec3 R = reflect(L, N);
vec3 diffuse = max(dot(N, L), 0.15) * inColor;
vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.75);
outFragColor = vec4(diffuse * color.rgb + specular, 1.0);

View file

@ -10,6 +10,7 @@ layout (set = 0, binding = 0) uniform UBOScene
mat4 projection;
mat4 view;
vec4 lightPos;
vec4 viewPos;
} uboScene;
layout(push_constant) uniform PushConsts {
@ -32,6 +33,6 @@ void main()
vec4 pos = uboScene.view * vec4(inPos, 1.0);
outNormal = mat3(uboScene.view) * inNormal;
vec3 lPos = mat3(uboScene.view) * uboScene.lightPos.xyz;
outLightVec = lPos - pos.xyz;
outViewVec = -pos.xyz;
outLightVec = uboScene.lightPos.xyz - pos.xyz;
outViewVec = uboScene.viewPos.xyz - pos.xyz;
}

View file

@ -24,7 +24,7 @@ float4 main(VSOutput input) : SV_TARGET
float3 N = normalize(input.Normal);
float3 L = normalize(input.LightVec);
float3 V = normalize(input.ViewVec);
float3 R = reflect(-L, N);
float3 R = reflect(L, N);
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75);
return float4(diffuse * color.rgb + specular, 1.0);

View file

@ -13,6 +13,7 @@ struct UBO
float4x4 projection;
float4x4 view;
float4 lightPos;
float4 viewPos;
};
cbuffer ubo : register(b0) { UBO ubo; }
@ -42,8 +43,7 @@ VSOutput main(VSInput input)
float4 pos = mul(ubo.view, float4(input.Pos, 1.0));
output.Normal = mul((float3x3)ubo.view, input.Normal);
float3 lPos = mul((float3x3)ubo.view, ubo.lightPos.xyz);
output.LightVec = lPos - pos.xyz;
output.ViewVec = -pos.xyz;
output.LightVec = ubo.lightPos.xyz - pos.xyz;
output.ViewVec = ubo.viewPos.xyz - pos.xyz;
return output;
}