i think the lighting works now

PBR
Evan Hemsley 2020-08-01 13:43:04 -07:00
parent 4b36860b62
commit 0ea3484ec3
4 changed files with 38 additions and 24 deletions

View File

@ -88,8 +88,14 @@ namespace Smuggler
{ {
world = value; world = value;
worldParam.SetValue(world); worldParam.SetValue(world);
worldViewProjectionParam.SetValue(world * view * projection);
worldInverseTransposeParam.SetValue(Matrix.Transpose(Matrix.Invert(world))); Matrix.Multiply(ref world, ref view, out Matrix worldView);
Matrix.Multiply(ref worldView, ref projection, out Matrix worldViewProj);
worldViewProjectionParam.SetValue(worldViewProj);
Matrix.Invert(ref world, out Matrix worldInverse);
Matrix.Transpose(ref worldInverse, out Matrix worldInverseTranspose);
worldInverseTransposeParam.SetValue(worldInverseTranspose);
} }
} }
@ -100,8 +106,13 @@ namespace Smuggler
{ {
view = value; view = value;
viewParam.SetValue(view); viewParam.SetValue(view);
worldViewProjectionParam.SetValue(world * view * projection);
eyePositionParam.SetValue(Matrix.Invert(view).Translation); Matrix.Multiply(ref world, ref view, out Matrix worldView);
Matrix.Multiply(ref worldView, ref projection, out Matrix worldViewProj);
worldViewProjectionParam.SetValue(worldViewProj);
Matrix.Invert(ref view, out Matrix inverseView);
eyePositionParam.SetValue(inverseView.Translation);
} }
} }
@ -112,7 +123,10 @@ namespace Smuggler
{ {
projection = value; projection = value;
projectionParam.SetValue(projection); projectionParam.SetValue(projection);
worldViewProjectionParam.SetValue(world * view * projection);
Matrix.Multiply(ref world, ref view, out Matrix worldView);
Matrix.Multiply(ref worldView, ref projection, out Matrix worldViewProj);
worldViewProjectionParam.SetValue(worldViewProj);
} }
} }

View File

@ -52,10 +52,10 @@ struct PixelShaderInput
PixelShaderInput main_vs(VertexShaderInput input) PixelShaderInput main_vs(VertexShaderInput input)
{ {
PixelShaderInput output; PixelShaderInput output;
output.PositionWS = mul(input.Position, World).xyz; output.PositionWS = mul(input.Position, World).xyz;
output.TexCoord = input.TexCoord; output.TexCoord = input.TexCoord;
output.NormalWS = normalize(mul(WorldInverseTranspose, input.Normal)); output.NormalWS = normalize(mul(input.Normal, (float3x3)WorldInverseTranspose));
output.Position = mul(input.Position, WorldViewProjection); output.Position = mul(input.Position, WorldViewProjection);
return output; return output;
@ -107,6 +107,9 @@ float4 None(PixelShaderInput input) : SV_TARGET
float3 N = normalize(input.NormalWS); float3 N = normalize(input.NormalWS);
float3 V = normalize(EyePosition - input.PositionWS); float3 V = normalize(EyePosition - input.PositionWS);
float3 F0 = float3(0.04, 0.04, 0.04);
F0 = lerp(F0, Albedo, Metallic);
float3 Lo = float3(0.0, 0.0, 0.0); float3 Lo = float3(0.0, 0.0, 0.0);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -119,12 +122,9 @@ float4 None(PixelShaderInput input) : SV_TARGET
float attenuation = 1.0 / (distance * distance); float attenuation = 1.0 / (distance * distance);
float3 radiance = LightColors[i] * attenuation; float3 radiance = LightColors[i] * attenuation;
float3 F0 = float3(0.04, 0.04, 0.04);
F0 = lerp(F0, Albedo, Metallic);
float3 F = FresnelSchlick(max(dot(H, V), 0.0), F0);
float NDF = DistributionGGX(N, H, Roughness); float NDF = DistributionGGX(N, H, Roughness);
float G = GeometrySmith(N, V, L, Roughness); float G = GeometrySmith(N, V, L, Roughness);
float3 F = FresnelSchlick(max(dot(H, V), 0.0), F0);
float3 numerator = NDF * G * F; float3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0); float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0);

Binary file not shown.

View File

@ -231,24 +231,24 @@ namespace Smuggler
effect.AO = 1f; effect.AO = 1f;
effect.Lights[0] = new PBRLight( effect.Lights[0] = new PBRLight(
new Vector3(-10f, 10f, 10f), new Vector3(-10f, 10f, -10f),
new Vector3(300f, 300f, 300f) new Vector3(300f, 300f, 300f)
); );
effect.Lights[1] = new PBRLight( // effect.Lights[1] = new PBRLight(
new Vector3(10f, 10f, 10f), // new Vector3(10f, 10f, 10f),
new Vector3(300f, 300f, 300f) // new Vector3(300f, 300f, 300f)
); // );
effect.Lights[2] = new PBRLight( // effect.Lights[2] = new PBRLight(
new Vector3(-10f, -10f, 10f), // new Vector3(-10f, -10f, 10f),
new Vector3(300f, 300f, 300f) // new Vector3(300f, 300f, 300f)
); // );
effect.Lights[3] = new PBRLight( // effect.Lights[3] = new PBRLight(
new Vector3(10f, -10f, 10f), // new Vector3(10f, -10f, 10f),
new Vector3(300f, 300f, 300f) // new Vector3(300f, 300f, 300f)
); // );
/* FIXME: how to load cube maps from GLTF? */ /* FIXME: how to load cube maps from GLTF? */
/* /*