mirror of
https://github.com/4sval/FModel.git
synced 2026-04-23 01:57:48 -05:00
improved shader light reflection
This commit is contained in:
parent
b6872dda6e
commit
8ad48736f0
|
|
@ -1 +1 @@
|
|||
Subproject commit 1cec00df148a2cdc2f4dbf73316b9b1ea6da33f7
|
||||
Subproject commit 8576fc4ebbab4b34f3041dcaec7a5ce769964575
|
||||
|
|
@ -95,10 +95,11 @@ vec3 ComputeNormals(int layer)
|
|||
return normalize(tbn * normal);
|
||||
}
|
||||
|
||||
vec3 schlickFresnel(int layer, float vDotH)
|
||||
vec3 schlickFresnel(vec3 fLambert, float metallic, float hDotv)
|
||||
{
|
||||
vec3 f0 = vec3(0.04);
|
||||
return f0 + (1.0 - f0) * pow(clamp(1.0 - vDotH, 0.0, 1.0), 5);
|
||||
f0 = mix(f0, fLambert, metallic);
|
||||
return f0 + (1.0 - f0) * pow(clamp(1.0 - hDotv, 0.0, 1.0), 5);
|
||||
}
|
||||
|
||||
float ggxDistribution(float roughness, float nDoth)
|
||||
|
|
@ -117,8 +118,9 @@ float geomSmith(float roughness, float dp)
|
|||
|
||||
vec3 CalcCameraLight(int layer, vec3 normals)
|
||||
{
|
||||
vec3 fLambert = SamplerToVector(uParameters.Diffuse[layer].Sampler).rgb * uParameters.Diffuse[layer].Color.rgb;
|
||||
vec3 specular_masks = SamplerToVector(uParameters.SpecularMasks[layer].Sampler).rgb;
|
||||
float roughness = max(0.0f, mix(specular_masks.r, specular_masks.b, uParameters.Roughness));
|
||||
float roughness = max(0.0f, specular_masks.b * uParameters.Roughness);
|
||||
|
||||
vec3 intensity = vec3(1.0f) * 1.0;
|
||||
vec3 l = -uViewDir;
|
||||
|
|
@ -128,21 +130,19 @@ vec3 CalcCameraLight(int layer, vec3 normals)
|
|||
vec3 h = normalize(v + l);
|
||||
|
||||
float nDotH = max(dot(n, h), 0.0);
|
||||
float vDotH = max(dot(v, h), 0.0);
|
||||
float hDotv = max(dot(h, v), 0.0);
|
||||
float nDotL = max(dot(n, l), 0.0);
|
||||
float nDotV = max(dot(n, v), 0.0);
|
||||
|
||||
vec3 f = schlickFresnel(layer, vDotH);
|
||||
vec3 f = schlickFresnel(fLambert, specular_masks.g, hDotv);
|
||||
|
||||
vec3 kS = f;
|
||||
vec3 kD = 1.0 - kS;
|
||||
kD *= max(0.0, dot(v, reflect(-v, normals)) * specular_masks.g);
|
||||
kD *= 1.0 - specular_masks.g;
|
||||
|
||||
vec3 specBrdfNom = ggxDistribution(roughness, nDotH) * f * geomSmith(roughness, nDotL) * geomSmith(roughness, nDotV);
|
||||
vec3 specBrdfNom = ggxDistribution(roughness, nDotH) * geomSmith(roughness, nDotL) * geomSmith(roughness, nDotV) * f;
|
||||
float specBrdfDenom = 4.0 * nDotV * nDotL + 0.0001;
|
||||
vec3 specBrdf = specBrdfNom / specBrdfDenom;
|
||||
|
||||
vec3 fLambert = SamplerToVector(uParameters.Diffuse[layer].Sampler).rgb * uParameters.Diffuse[layer].Color.rgb;
|
||||
vec3 specBrdf = specular_masks.r * specBrdfNom / specBrdfDenom;
|
||||
|
||||
vec3 diffuseBrdf = kD * fLambert / PI;
|
||||
return (diffuseBrdf + specBrdf) * intensity * nDotL;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class Material : IDisposable
|
|||
}
|
||||
|
||||
{ // scalars
|
||||
if (Parameters.TryGetTexture2d(out var original, "M", "PackedTexture", "AEM") &&
|
||||
if (Parameters.TryGetTexture2d(out var original, "M", "AEM", "AO") &&
|
||||
!original.Name.Equals("T_BlackMask") && options.TryGetTexture(original, false, out var transformed))
|
||||
{
|
||||
HasAo = true;
|
||||
|
|
@ -109,7 +109,7 @@ public class Material : IDisposable
|
|||
|
||||
if (Parameters.TryGetScalar(out var emissiveMultScalar, "emissive mult", "Emissive_Mult"))
|
||||
EmissiveMult = emissiveMultScalar;
|
||||
else if (Parameters.TryGetLinearColor(out var emissiveMultColor, "Emissive Multiplier"))
|
||||
else if (Parameters.TryGetLinearColor(out var emissiveMultColor, "Emissive Multiplier", "EmissiveMultiplier"))
|
||||
EmissiveMult = emissiveMultColor.R;
|
||||
|
||||
if (Parameters.TryGetScalar(out var uvScale, "UV Scale"))
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ public class Options
|
|||
switch (_game)
|
||||
{
|
||||
case "hk_project":
|
||||
case "gameface":
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,25 +30,43 @@ public class Skeleton : IDisposable
|
|||
continue;
|
||||
|
||||
var transform = Transform.Identity;
|
||||
var matrix = Matrix4x4.Identity;
|
||||
while (boneIndex > -1)
|
||||
{
|
||||
var t = RefSkel.ReferenceSkeleton.FinalRefBonePose[boneIndex];
|
||||
transform.Position += t.Rotation.RotateVector(t.Translation.ToMapVector()) * Constants.SCALE_DOWN_RATIO;
|
||||
|
||||
var bone = RefSkel.ReferenceSkeleton.FinalRefBonePose[boneIndex];
|
||||
boneIndex = RefSkel.ReferenceSkeleton.FinalRefBoneInfo[boneIndex].ParentIndex;
|
||||
var parentBone = RefSkel.ReferenceSkeleton.FinalRefBonePose[boneIndex < 0 ? 0 : boneIndex];
|
||||
|
||||
var orig_loc = bone.Translation;
|
||||
parentBone.Rotation.Conjugate();
|
||||
orig_loc = parentBone.Rotation.RotateVector(orig_loc);
|
||||
|
||||
var orig_quat = bone.Rotation;
|
||||
orig_quat *= parentBone.Rotation;
|
||||
orig_quat.Conjugate();
|
||||
|
||||
var p_rotated = orig_quat * orig_loc;
|
||||
orig_quat.Conjugate();
|
||||
p_rotated *= orig_quat;
|
||||
|
||||
matrix *=
|
||||
Matrix4x4.CreateFromQuaternion(orig_quat) *
|
||||
Matrix4x4.CreateTranslation(p_rotated);
|
||||
|
||||
// Console.WriteLine(matrix.Translation);
|
||||
}
|
||||
// for (int j = 0; j <= 3; j++)
|
||||
// for (int j = 0; j <= boneIndex; j++)
|
||||
// {
|
||||
// var t = RefSkel.ReferenceSkeleton.FinalRefBonePose[j];
|
||||
// // var matrix = Matrix4x4.CreateScale(t.Scale3D.ToMapVector());
|
||||
// // matrix *= Matrix4x4.CreateFromQuaternion(t.Rotation);
|
||||
// transform.Position += t.Rotation.UnrotateVector(t.Translation.ToMapVector()) * Constants.SCALE_DOWN_RATIO;
|
||||
// var r = RefSkel.ReferenceSkeleton.FinalRefBonePose[j - (j == 0 ? 0 : 1)].Rotation;
|
||||
// r.Conjugate();
|
||||
// matrix *= Matrix4x4.CreateFromQuaternion(r) * Matrix4x4.CreateTranslation(t.Translation);
|
||||
//
|
||||
// // Console.WriteLine($@"{t.Translation}");
|
||||
// // transform.Relation *= matrix;
|
||||
// Console.WriteLine($@"{t.Translation}");
|
||||
// transform.Relation *= matrix;
|
||||
// }
|
||||
|
||||
Sockets[i] = new Socket(socket, transform);
|
||||
Sockets[i] = new Socket(socket, matrix.Translation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using CUE4Parse.UE4.Assets.Exports.SkeletalMesh;
|
||||
using CUE4Parse.UE4.Objects.Core.Math;
|
||||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
||||
|
|
@ -19,6 +21,15 @@ public class Socket : IDisposable
|
|||
// Transform.Scale = socket.RelativeScale.ToMapVector();
|
||||
}
|
||||
|
||||
public Socket(USkeletalMeshSocket socket, Vector3 position)
|
||||
{
|
||||
Name = socket.SocketName.Text;
|
||||
Bone = socket.BoneName.Text;
|
||||
Transform = Transform.Identity;
|
||||
var pos = position /*+ socket.RelativeRotation.RotateVector(socket.RelativeLocation)*/;
|
||||
Transform.Position = new FVector(pos.X, pos.Z, pos.Y) * Constants.SCALE_DOWN_RATIO;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user