mirror of
https://github.com/4sval/FModel.git
synced 2026-03-26 19:55:18 -05:00
really bad shader
This commit is contained in:
parent
4edfdabcd0
commit
dde7688f2e
|
|
@ -1 +1 @@
|
|||
Subproject commit c3db95ebc3800207eb3fc7dc66470178c037ff51
|
||||
Subproject commit 5725d3c30ec311870e5832e6869af73ea40aab79
|
||||
|
|
@ -444,24 +444,8 @@ public class ModelViewerViewModel : ViewModel
|
|||
if (parameters.Specular is UTexture2D specular)
|
||||
{
|
||||
var mip = specular.GetFirstMip();
|
||||
byte[] data;
|
||||
SKColorType colorType;
|
||||
switch (UserSettings.Default.OverridedPlatform)
|
||||
{
|
||||
case ETexturePlatform.Playstation:
|
||||
PlaystationDecoder.DecodeTexturePlaystation(mip, specular.Format, specular.isNormalMap,
|
||||
out data, out colorType);
|
||||
break;
|
||||
case ETexturePlatform.NintendoSwitch:
|
||||
NintendoSwitchDecoder.DecodeTextureNSW(mip, specular.Format, specular.isNormalMap,
|
||||
out data, out colorType);
|
||||
break;
|
||||
default:
|
||||
TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap,
|
||||
out data, out colorType);
|
||||
break;
|
||||
}
|
||||
|
||||
var platform = UserSettings.Default.OverridedPlatform;
|
||||
TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out var data, out var colorType);
|
||||
|
||||
switch (_game)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class Model : IDisposable
|
|||
private BufferObject<float> _vbo;
|
||||
private VertexArrayObject<float, uint> _vao;
|
||||
|
||||
private const int _vertexSize = 8; // Position + Normals + UV
|
||||
private const int _vertexSize = 8; // Position + Normal + UV
|
||||
private const uint _faceSize = 3; // just so we don't have to do .Length
|
||||
private readonly uint[] _facesIndex = { 1, 0, 2 };
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ public class Model : IDisposable
|
|||
_vao = new VertexArrayObject<float, uint>(_gl, _vbo, _ebo);
|
||||
|
||||
_vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, _vertexSize, 0); // position
|
||||
_vao.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, _vertexSize, 3); // normals
|
||||
_vao.VertexAttributePointer(1, 3, VertexAttribPointerType.Float, _vertexSize, 3); // normal
|
||||
_vao.VertexAttributePointer(2, 2, VertexAttribPointerType.Float, _vertexSize, 6); // uv
|
||||
|
||||
for (int section = 0; section < Sections.Length; section++)
|
||||
|
|
@ -91,11 +91,27 @@ public class Model : IDisposable
|
|||
_shader.SetUniform("uModel", Matrix4x4.Identity);
|
||||
_shader.SetUniform("uView", camera.GetViewMatrix());
|
||||
_shader.SetUniform("uProjection", camera.GetProjectionMatrix());
|
||||
// _shader.SetUniform("viewPos", camera.Position);
|
||||
_shader.SetUniform("viewPos", camera.Position);
|
||||
|
||||
_shader.SetUniform("material.diffuse", 0);
|
||||
_shader.SetUniform("material.normal", 1);
|
||||
_shader.SetUniform("material.specular", 2);
|
||||
// _shader.SetUniform("material.metallic", 3);
|
||||
// _shader.SetUniform("material.emission", 4);
|
||||
_shader.SetUniform("material.shininess", 32f);
|
||||
|
||||
var lightColor = Vector3.One;
|
||||
var diffuseColor = lightColor * new Vector3(0.5f);
|
||||
var ambientColor = diffuseColor * new Vector3(0.2f);
|
||||
|
||||
_shader.SetUniform("light.ambient", ambientColor);
|
||||
_shader.SetUniform("light.diffuse", diffuseColor); // darkened
|
||||
_shader.SetUniform("light.specular", Vector3.One);
|
||||
_shader.SetUniform("light.position", camera.Position);
|
||||
|
||||
for (int section = 0; section < Sections.Length; section++)
|
||||
{
|
||||
Sections[section].Bind(_shader);
|
||||
Sections[section].Bind();
|
||||
|
||||
_gl.DrawArrays(PrimitiveType.Triangles, Sections[section].FirstFaceIndex, Sections[section].FacesCount);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using CUE4Parse.UE4.Assets.Exports.Material;
|
|||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||
using CUE4Parse_Conversion.Meshes.PSK;
|
||||
using CUE4Parse_Conversion.Textures;
|
||||
using FModel.Settings;
|
||||
using Silk.NET.OpenGL;
|
||||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
|
@ -12,8 +13,11 @@ public class Section : IDisposable
|
|||
private uint _handle;
|
||||
private GL _gl;
|
||||
|
||||
private Texture _albedoMap;
|
||||
// private Texture _normalMap;
|
||||
private Texture _diffuseMap;
|
||||
private Texture _normalMap;
|
||||
private Texture _specularMap;
|
||||
// private Texture _metallicMap;
|
||||
private Texture _emissionMap;
|
||||
|
||||
public uint FacesCount;
|
||||
public int FirstFaceIndex;
|
||||
|
|
@ -36,25 +40,55 @@ public class Section : IDisposable
|
|||
|
||||
_handle = _gl.CreateProgram();
|
||||
|
||||
if (Parameters.Diffuse is UTexture2D { IsVirtual: false } diffuse && diffuse.GetFirstMip() is { } mip)
|
||||
var platform = UserSettings.Default.OverridedPlatform;
|
||||
if (Parameters.Diffuse is UTexture2D { IsVirtual: false } diffuse)
|
||||
{
|
||||
TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, out var data, out _);
|
||||
_albedoMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
|
||||
var mip = diffuse.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, platform, out var data, out _);
|
||||
_diffuseMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
|
||||
}
|
||||
|
||||
if (Parameters.Normal is UTexture2D { IsVirtual: false } normal)
|
||||
{
|
||||
var mip = normal.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, normal.Format, normal.isNormalMap, platform, out var data, out _);
|
||||
_normalMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
|
||||
}
|
||||
|
||||
if (Parameters.Specular is UTexture2D { IsVirtual: false } specular)
|
||||
{
|
||||
var mip = specular.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out var data, out _);
|
||||
_specularMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
|
||||
}
|
||||
|
||||
if (Parameters.HasTopEmissiveTexture &&
|
||||
Parameters.EmissiveColor is { A: > 0 } emissiveColor &&
|
||||
Parameters.Emissive is UTexture2D { IsVirtual: false } emissive)
|
||||
{
|
||||
var mip = emissive.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, emissive.Format, emissive.isNormalMap, platform, out var data, out _);
|
||||
_emissionMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Shader shader)
|
||||
public void Bind()
|
||||
{
|
||||
if (Parameters.IsNull)
|
||||
return;
|
||||
|
||||
shader.SetUniform("material.albedo", 0);
|
||||
_albedoMap?.Bind(TextureUnit.Texture0);
|
||||
_diffuseMap?.Bind(TextureUnit.Texture0);
|
||||
_normalMap?.Bind(TextureUnit.Texture1);
|
||||
_specularMap?.Bind(TextureUnit.Texture2);
|
||||
_emissionMap?.Bind(TextureUnit.Texture4);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_albedoMap?.Dispose();
|
||||
_diffuseMap?.Dispose();
|
||||
_normalMap?.Dispose();
|
||||
_specularMap?.Dispose();
|
||||
_emissionMap?.Dispose();
|
||||
_gl.DeleteProgram(_handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ uniform mat4 uModel;
|
|||
uniform mat4 uView;
|
||||
uniform mat4 uProjection;
|
||||
|
||||
out vec3 fNormal;
|
||||
out vec3 fPos;
|
||||
out vec3 fNormal;
|
||||
out vec2 fTexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
|
||||
|
||||
fPos = vec3(uModel * vec4(vPos, 1.0));
|
||||
fNormal = mat3(transpose(inverse(uModel))) * vNormal;
|
||||
fTexCoords = vTexCoords;
|
||||
|
|
@ -35,25 +36,55 @@ void main()
|
|||
private readonly string FragmentShaderSource = @"
|
||||
#version 330 core
|
||||
|
||||
in vec3 fNormal;
|
||||
in vec3 fPos;
|
||||
in vec3 fNormal;
|
||||
in vec2 fTexCoords;
|
||||
|
||||
struct Material {
|
||||
sampler2D albedo;
|
||||
sampler2D diffuse;
|
||||
sampler2D normal;
|
||||
sampler2D specular;
|
||||
sampler2D metallic;
|
||||
sampler2D emissive;
|
||||
sampler2D emission;
|
||||
|
||||
float shininess;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
uniform Material material;
|
||||
uniform Light light;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(material.albedo, fTexCoords);
|
||||
// ambient
|
||||
vec3 ambient = light.ambient * vec3(texture(material.diffuse, fTexCoords));
|
||||
|
||||
// diffuse
|
||||
vec3 norm = texture(material.normal, fTexCoords).rgb;
|
||||
norm = normalize(norm * 2.0 - 1.0);
|
||||
vec3 lightDir = normalize(light.position - fPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0f);
|
||||
vec3 diffuseMap = vec3(texture(material.diffuse, fTexCoords));
|
||||
vec3 diffuse = light.diffuse * diff * diffuseMap;
|
||||
|
||||
// specular
|
||||
vec3 viewDir = normalize(viewPos - fPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0f), material.shininess);
|
||||
vec3 specularMap = vec3(texture(material.specular, fTexCoords));
|
||||
vec3 specular = light.specular * spec * specularMap;
|
||||
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user