fixed normal rotations
This commit is contained in:
parent
742c8149f3
commit
4b259648a1
|
|
@ -44,6 +44,28 @@ cbuffer Uniforms : register(b0, space1)
|
|||
float time;
|
||||
};
|
||||
|
||||
float4x4 ExtractRotation(float4x4 m)
|
||||
{
|
||||
// Extract basis vectors
|
||||
float3 x = float3(m._11, m._12, m._13);
|
||||
float3 y = float3(m._21, m._22, m._23);
|
||||
float3 z = float3(m._31, m._32, m._33);
|
||||
|
||||
// Remove scale by normalizing each axis
|
||||
x = normalize(x);
|
||||
y = normalize(y);
|
||||
z = normalize(z);
|
||||
|
||||
// Reconstruct rotation matrix
|
||||
float3x3 m2 = float3x3(x, y, z);
|
||||
|
||||
return float4x4(
|
||||
float4(m2[0][0], m2[0][1], m2[0][2], 0.0),
|
||||
float4(m2[1][0], m2[1][1], m2[1][2], 0.0),
|
||||
float4(m2[2][0], m2[2][1], m2[2][2], 0.0),
|
||||
float4(0.0, 0.0, 0.0, 1.0)
|
||||
);}
|
||||
|
||||
Output main(Input input)
|
||||
{
|
||||
Output output;
|
||||
|
|
@ -57,8 +79,10 @@ Output main(Input input)
|
|||
float4 WorldPos = mul(scene[input.Instance].Model, pos);
|
||||
output.Position = mul(ViewProjection, mul(scene[input.Instance].Model, pos));
|
||||
output.WorldPos = WorldPos.xyz;
|
||||
|
||||
float4x4 noTranslate = ExtractRotation(scene[input.Instance].Model);
|
||||
// output.Normal = mul(scene[input.Instance].Model, float4(input.Normal, 1.0)).xyz;
|
||||
output.Normal = input.Normal;
|
||||
output.Normal = mul(noTranslate, input.Normal);
|
||||
output.DirectionalShadowFragPos = mul(ShadowMapProjection, WorldPos);
|
||||
output.Instance = input.Instance;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
}
|
||||
],
|
||||
"types" : {
|
||||
"_13" : {
|
||||
"_14" : {
|
||||
"name" : "Scene",
|
||||
"members" : [
|
||||
{
|
||||
|
|
@ -38,12 +38,12 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_12" : {
|
||||
"_13" : {
|
||||
"name" : "type.StructuredBuffer.Scene",
|
||||
"members" : [
|
||||
{
|
||||
"name" : "_m0",
|
||||
"type" : "_13",
|
||||
"type" : "_14",
|
||||
"array" : [
|
||||
0
|
||||
],
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_15" : {
|
||||
"_16" : {
|
||||
"name" : "type.Uniforms",
|
||||
"members" : [
|
||||
{
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
],
|
||||
"ssbos" : [
|
||||
{
|
||||
"type" : "_12",
|
||||
"type" : "_13",
|
||||
"name" : "scene",
|
||||
"readonly" : true,
|
||||
"block_size" : 0,
|
||||
|
|
@ -136,7 +136,7 @@
|
|||
],
|
||||
"ubos" : [
|
||||
{
|
||||
"type" : "_15",
|
||||
"type" : "_16",
|
||||
"name" : "type.Uniforms",
|
||||
"block_size" : 132,
|
||||
"set" : 1,
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ float4 main(float2 UV : TEXCOORD0) : SV_Target0
|
|||
float exposure = 1.0;
|
||||
c *= exposure;//= exposure(c, 1.0, 0.3);
|
||||
|
||||
// c = c * c ;
|
||||
|
||||
// c = e;
|
||||
|
||||
// c = float3(uv.x, uv.y, 0.0);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -44,14 +44,14 @@ struct main0_in
|
|||
vertex main0_out main0(main0_in in [[stage_in]], constant type_Uniforms& Uniforms [[buffer(0)]], const device type_StructuredBuffer_Scene& scene [[buffer(1)]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float4 _48 = float4(in.in_var_TEXCOORD0, 1.0);
|
||||
float4 _51 = scene._m0[gl_InstanceIndex].Model * _48;
|
||||
float4 _52 = float4(in.in_var_TEXCOORD0, 1.0);
|
||||
float4 _55 = scene._m0[gl_InstanceIndex].Model * _52;
|
||||
out.out_var_TEXCOORD0 = in.in_var_TEXCOORD3;
|
||||
out.out_var_TEXCOORD1 = _51.xyz;
|
||||
out.out_var_TEXCOORD2 = in.in_var_TEXCOORD1;
|
||||
out.out_var_TEXCOORD3 = Uniforms.ShadowMapProjection * _51;
|
||||
out.out_var_TEXCOORD1 = _55.xyz;
|
||||
out.out_var_TEXCOORD2 = float3((in.in_var_TEXCOORD1 * float4x3(float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][0], scene._m0[gl_InstanceIndex].Model[1][0], scene._m0[gl_InstanceIndex].Model[2][0])), 0.0).xyz, float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][1], scene._m0[gl_InstanceIndex].Model[1][1], scene._m0[gl_InstanceIndex].Model[2][1])), 0.0).xyz, float4(fast::normalize(float3(scene._m0[gl_InstanceIndex].Model[0][2], scene._m0[gl_InstanceIndex].Model[1][2], scene._m0[gl_InstanceIndex].Model[2][2])), 0.0).xyz, float3(0.0))).xyz);
|
||||
out.out_var_TEXCOORD3 = Uniforms.ShadowMapProjection * _55;
|
||||
out.out_var_TEXCOORD4 = gl_InstanceIndex;
|
||||
out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _48);
|
||||
out.gl_Position = Uniforms.ViewProjection * (scene._m0[gl_InstanceIndex].Model * _52);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue