From d670a0ecbd9c3ebb5e8f0b8ae7645c492e405e67 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Wed, 5 Aug 2020 12:15:02 -0700 Subject: [PATCH] removed all references to effect processing etc --- Effects/EffectHelpers.cs | 14 -- Effects/Macros.fxh | 57 ------ Effects/PBREffect.cs | 374 --------------------------------------- Effects/PBREffect.fx | 313 -------------------------------- Effects/PBREffect.fxb | Bin 38008 -> 0 bytes Importer.cs | 148 +++++----------- Mesh.cs | 23 --- MeshData.cs | 12 ++ MeshPart.cs | 47 ----- MeshPartData.cs | 34 ++++ Model.cs | 24 --- ModelData.cs | 15 ++ Resources.cs | 33 ---- Smuggler.csproj | 6 - 14 files changed, 101 insertions(+), 999 deletions(-) delete mode 100644 Effects/EffectHelpers.cs delete mode 100644 Effects/Macros.fxh delete mode 100644 Effects/PBREffect.cs delete mode 100644 Effects/PBREffect.fx delete mode 100644 Effects/PBREffect.fxb delete mode 100644 Mesh.cs create mode 100644 MeshData.cs delete mode 100644 MeshPart.cs create mode 100644 MeshPartData.cs delete mode 100644 Model.cs create mode 100644 ModelData.cs delete mode 100644 Resources.cs diff --git a/Effects/EffectHelpers.cs b/Effects/EffectHelpers.cs deleted file mode 100644 index e2618cb..0000000 --- a/Effects/EffectHelpers.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Smuggler -{ - [Flags] - internal enum EffectDirtyFlags - { - WorldViewProj = 1, - World = 2, - EyePosition = 4, - ShaderIndex = 8, - All = -1 - } -} \ No newline at end of file diff --git a/Effects/Macros.fxh b/Effects/Macros.fxh deleted file mode 100644 index 91d1702..0000000 --- a/Effects/Macros.fxh +++ /dev/null @@ -1,57 +0,0 @@ -//----------------------------------------------------------------------------- -// Macros.fxh -// -// Microsoft XNA Community Game Platform -// Copyright (C) Microsoft Corporation. All rights reserved. -//----------------------------------------------------------------------------- - -#ifdef SM4 - - -// Macros for targetting shader model 4.0 (DX11) - -#define BEGIN_CONSTANTS cbuffer Parameters : register(b0) { -#define MATRIX_CONSTANTS }; cbuffer ProjectionMatrix : register(b1) { -#define END_CONSTANTS }; - -#define _vs(r) -#define _ps(r) -#define _cb(r) : packoffset(r) - -#define DECLARE_TEXTURE(Name, index) \ - Texture2D Name : register(t##index); \ - sampler Name##Sampler : register(s##index) - -#define DECLARE_CUBEMAP(Name, index) \ - TextureCube Name : register(t##index); \ - sampler Name##Sampler : register(s##index) - -#define SAMPLE_TEXTURE(Name, texCoord) Name.Sample(Name##Sampler, texCoord) -#define SAMPLE_CUBEMAP(Name, texCoord) Name.Sample(Name##Sampler, texCoord) -#define SAMPLE_CUBEMAP_LOD(Name, texCoord) Name.SampleLevel(Name##Sampler, texCoord.xyz, texCoord.w) - -#else - - -// Macros for targetting shader model 2.0 (DX9) - -#define BEGIN_CONSTANTS -#define MATRIX_CONSTANTS -#define END_CONSTANTS - -#define _vs(r) : register(vs, r) -#define _ps(r) : register(ps, r) -#define _cb(r) - -#define DECLARE_TEXTURE(Name, index) \ - texture2D Name; \ - sampler Name##Sampler : register(s##index) = sampler_state { Texture = (Name); }; - -#define DECLARE_CUBEMAP(Name, index) \ - textureCUBE Name; \ - sampler Name##Sampler : register(s##index) = sampler_state { Texture = (Name); }; - -#define SAMPLE_TEXTURE(Name, texCoord) tex2D(Name##Sampler, texCoord) -#define SAMPLE_CUBEMAP(Name, texCoord) texCUBE(Name##Sampler, texCoord) -#define SAMPLE_CUBEMAP_LOD(Name, texCoord) texCUBElod(Name##Sampler, texCoord) -#endif diff --git a/Effects/PBREffect.cs b/Effects/PBREffect.cs deleted file mode 100644 index eec2796..0000000 --- a/Effects/PBREffect.cs +++ /dev/null @@ -1,374 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace Smuggler -{ - public struct PBRLight - { - public Vector3 position; - public Vector3 color; - - public PBRLight(Vector3 position, Vector3 colour) - { - this.position = position; - this.color = colour; - } - } - - public class PBRLightCollection - { - private readonly Vector3[] positions = new Vector3[4]; - private readonly Vector3[] colors = new Vector3[4]; - - readonly EffectParameter lightPositionsParam; - readonly EffectParameter lightColorsParam; - - public PBRLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam) - { - this.lightPositionsParam = lightPositionsParam; - this.lightColorsParam = lightColorsParam; - } - - public PBRLight this[int i] - { - get { return new PBRLight(positions[i], colors[i]); } - set - { - positions[i] = value.position; - colors[i] = value.color; - lightPositionsParam.SetValue(positions); - lightColorsParam.SetValue(colors); - } - } - } - - public class PBREffect : Effect - { - EffectParameter worldParam; - EffectParameter worldViewProjectionParam; - EffectParameter worldInverseTransposeParam; - - EffectParameter albedoTextureParam; - EffectParameter normalTextureParam; - EffectParameter emissionTextureParam; - EffectParameter occlusionTextureParam; - EffectParameter metallicRoughnessTextureParam; - EffectParameter envDiffuseTextureParam; - EffectParameter brdfLutTextureParam; - EffectParameter envSpecularTextureParam; - - EffectParameter lightPositionsParam; - EffectParameter lightColorsParam; - - EffectParameter albedoParam; - EffectParameter metallicParam; - EffectParameter roughnessParam; - EffectParameter aoParam; - - EffectParameter eyePositionParam; - - EffectParameter shaderIndexParam; - - Matrix world = Matrix.Identity; - Matrix view = Matrix.Identity; - Matrix projection = Matrix.Identity; - PBRLightCollection pbrLightCollection; - - Vector3 albedo; - float metallic; - float roughness; - float ao; - - bool albedoTextureEnabled = false; - bool metallicRoughnessMapEnabled = false; - bool normalMapEnabled = false; - - EffectDirtyFlags dirtyFlags= EffectDirtyFlags.All; - - // FIXME: lazily set properties for performance - - public Matrix World - { - get { return world; } - set - { - world = value; - dirtyFlags |= EffectDirtyFlags.World | EffectDirtyFlags.WorldViewProj; - } - } - - public Matrix View - { - get { return view; } - set - { - view = value; - dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition; - } - } - - public Matrix Projection - { - get { return projection; } - set - { - projection = value; - dirtyFlags |= EffectDirtyFlags.WorldViewProj; - } - } - - public PBRLightCollection Lights - { - get { return pbrLightCollection; } - internal set { pbrLightCollection = value; } - } - - public Vector3 Albedo - { - get { return albedo; } - set - { - albedo = value; - albedoParam.SetValue(albedo); - } - } - - public float Metallic - { - get { return metallic; } - set - { - metallic = value; - metallicParam.SetValue(metallic); - } - } - - public float Roughness - { - get { return roughness; } - set - { - roughness = value; - roughnessParam.SetValue(roughness); - } - } - - public float AO - { - get { return ao; } - set - { - ao = value; - aoParam.SetValue(ao); - } - } - - public Texture2D AlbedoTexture - { - get { return albedoTextureParam.GetValueTexture2D(); } - set - { - albedoTextureParam.SetValue(value); - albedoTextureEnabled = value != null; - dirtyFlags |= EffectDirtyFlags.ShaderIndex; - } - } - - public Texture2D NormalTexture - { - get { return normalTextureParam.GetValueTexture2D(); } - set - { - normalTextureParam.SetValue(value); - normalMapEnabled = value != null; - dirtyFlags |= EffectDirtyFlags.ShaderIndex; - } - } - - public Texture2D EmissionTexture - { - get { return emissionTextureParam.GetValueTexture2D(); } - set { emissionTextureParam.SetValue(value); } - } - - public Texture2D OcclusionTexture - { - get { return occlusionTextureParam.GetValueTexture2D(); } - set { occlusionTextureParam.SetValue(value); } - } - - public Texture2D MetallicRoughnessTexture - { - get { return metallicRoughnessTextureParam.GetValueTexture2D(); } - set - { - metallicRoughnessTextureParam.SetValue(value); - metallicRoughnessMapEnabled = value != null; - dirtyFlags |= EffectDirtyFlags.ShaderIndex; - } - } - - public TextureCube EnvDiffuseTexture - { - get { return envDiffuseTextureParam.GetValueTextureCube(); } - set { envDiffuseTextureParam.SetValue(value); } - } - - public Texture2D BRDFLutTexture - { - get { return brdfLutTextureParam.GetValueTexture2D(); } - set { brdfLutTextureParam.SetValue(value); } - } - - public TextureCube EnvSpecularTexture - { - get { return envSpecularTextureParam.GetValueTextureCube(); } - set { envSpecularTextureParam.SetValue(value); } - } - - public PBREffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.PBREffect) - { - CacheEffectParameters(null); - - pbrLightCollection = new PBRLightCollection( - Parameters["LightPositions"], - Parameters["LightColors"] - ); - } - - protected PBREffect(PBREffect cloneSource) : base(cloneSource) - { - CacheEffectParameters(cloneSource); - - World = cloneSource.World; - View = cloneSource.View; - Projection = cloneSource.Projection; - - Lights = new PBRLightCollection( - Parameters["LightPositions"], - Parameters["LightColors"] - ); - - for (int i = 0; i < 4; i++) - { - Lights[i] = cloneSource.Lights[i]; - } - - AlbedoTexture = cloneSource.AlbedoTexture; - NormalTexture = cloneSource.NormalTexture; - EmissionTexture = cloneSource.EmissionTexture; - OcclusionTexture = cloneSource.OcclusionTexture; - MetallicRoughnessTexture = cloneSource.MetallicRoughnessTexture; - EnvDiffuseTexture = cloneSource.EnvDiffuseTexture; - BRDFLutTexture = cloneSource.BRDFLutTexture; - EnvSpecularTexture = cloneSource.EnvSpecularTexture; - - Albedo = cloneSource.Albedo; - Metallic = cloneSource.Metallic; - Roughness = cloneSource.Roughness; - AO = cloneSource.AO; - } - - public override Effect Clone() - { - return new PBREffect(this); - } - - protected override void OnApply() - { - if ((dirtyFlags & EffectDirtyFlags.World) != 0) - { - worldParam.SetValue(world); - - Matrix.Invert(ref world, out Matrix worldInverse); - Matrix.Transpose(ref worldInverse, out Matrix worldInverseTranspose); - worldInverseTransposeParam.SetValue(worldInverseTranspose); - - dirtyFlags &= ~EffectDirtyFlags.World; - } - - if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0) - { - Matrix.Multiply(ref world, ref view, out Matrix worldView); - Matrix.Multiply(ref worldView, ref projection, out Matrix worldViewProj); - worldViewProjectionParam.SetValue(worldViewProj); - - dirtyFlags &= ~EffectDirtyFlags.WorldViewProj; - } - - if ((dirtyFlags & EffectDirtyFlags.EyePosition) != 0) - { - Matrix.Invert(ref view, out Matrix inverseView); - eyePositionParam.SetValue(inverseView.Translation); - - dirtyFlags &= ~EffectDirtyFlags.EyePosition; - } - - if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0) - { - int shaderIndex = 0; - - if (albedoTextureEnabled && metallicRoughnessMapEnabled && normalMapEnabled) - { - shaderIndex = 7; - } - else if (metallicRoughnessMapEnabled && normalMapEnabled) - { - shaderIndex = 6; - } - else if (albedoTextureEnabled && normalMapEnabled) - { - shaderIndex = 5; - } - else if (albedoTextureEnabled && metallicRoughnessMapEnabled) - { - shaderIndex = 4; - } - else if (normalMapEnabled) - { - shaderIndex = 3; - } - else if (metallicRoughnessMapEnabled) - { - shaderIndex = 2; - } - else if (albedoTextureEnabled) - { - shaderIndex = 1; - } - - shaderIndexParam.SetValue(shaderIndex); - - dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; - } - } - - void CacheEffectParameters(PBREffect cloneSource) - { - worldParam = Parameters["World"]; - worldViewProjectionParam = Parameters["WorldViewProjection"]; - worldInverseTransposeParam = Parameters["WorldInverseTranspose"]; - - albedoTextureParam = Parameters["AlbedoTexture"]; - normalTextureParam = Parameters["NormalTexture"]; - emissionTextureParam = Parameters["EmissionTexture"]; - occlusionTextureParam = Parameters["OcclusionTexture"]; - metallicRoughnessTextureParam = Parameters["MetallicRoughnessTexture"]; - envDiffuseTextureParam = Parameters["EnvDiffuseTexture"]; - brdfLutTextureParam = Parameters["BrdfLutTexture"]; - envSpecularTextureParam = Parameters["EnvSpecularTexture"]; - - lightPositionsParam = Parameters["LightPositions"]; - lightColorsParam = Parameters["LightColors"]; - - albedoParam = Parameters["AlbedoValue"]; - metallicParam = Parameters["MetallicValue"]; - roughnessParam = Parameters["RoughnessValue"]; - aoParam = Parameters["AO"]; - - eyePositionParam = Parameters["EyePosition"]; - - shaderIndexParam = Parameters["ShaderIndex"]; - } - } -} diff --git a/Effects/PBREffect.fx b/Effects/PBREffect.fx deleted file mode 100644 index ee5ecb7..0000000 --- a/Effects/PBREffect.fx +++ /dev/null @@ -1,313 +0,0 @@ -#include "Macros.fxh" //from FNA - -static const float PI = 3.141592653589793; - -// Samplers - -DECLARE_TEXTURE(AlbedoTexture, 0); -DECLARE_TEXTURE(NormalTexture, 1); -DECLARE_TEXTURE(EmissionTexture, 2); -DECLARE_TEXTURE(OcclusionTexture, 3); -DECLARE_TEXTURE(MetallicRoughnessTexture, 4); -DECLARE_CUBEMAP(EnvDiffuseTexture, 8); -DECLARE_TEXTURE(BrdfLutTexture, 9); -DECLARE_CUBEMAP(EnvSpecularTexture, 10); - -BEGIN_CONSTANTS - - // PBR Values - float3 AlbedoValue _ps(c0) _cb(c0); - float MetallicValue _ps(c1) _cb(c1); - float RoughnessValue _ps(c2) _cb(c2); - float AO _ps(c3) _cb(c3); - - // Light Info - float3 LightPositions[4] _ps(c4) _cb(c4); - float3 LightColors[4] _ps(c8) _cb(c8); - - float3 EyePosition _ps(c12) _cb(c12); - - float4x4 World _vs(c0) _cb(c16); - float4x4 WorldInverseTranspose _vs(c4) _cb(c20); - -MATRIX_CONSTANTS - - float4x4 WorldViewProjection _vs(c8) _cb(c0); - -END_CONSTANTS - -struct VertexShaderInput -{ - float4 Position : POSITION; - float3 Normal : NORMAL; - float2 TexCoord : TEXCOORD0; -}; - -struct PixelShaderInput -{ - float4 Position : SV_Position; - float2 TexCoord : TEXCOORD0; - float3 PositionWS : TEXCOORD1; - float3 NormalWS : TEXCOORD2; -}; - -PixelShaderInput main_vs(VertexShaderInput input) -{ - PixelShaderInput output; - - output.TexCoord = input.TexCoord; - output.PositionWS = mul(input.Position, World).xyz; - output.NormalWS = mul(input.Normal, (float3x3)WorldInverseTranspose).xyz; - output.Position = mul(input.Position, WorldViewProjection); - - return output; -} - -float3 FresnelSchlick(float cosTheta, float3 F0) -{ - return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); -} - -float DistributionGGX(float3 N, float3 H, float roughness) -{ - float a = roughness * roughness; - float a2 = a * a; - float NdotH = max(dot(N, H), 0.0); - float NdotH2 = NdotH * NdotH; - - float num = a2; - float denom = (NdotH2 * (a2 - 1.0) + 1.0); - denom = PI * denom * denom; - - return num / denom; -} - -float GeometrySchlickGGX(float NdotV, float roughness) -{ - float r = (roughness + 1.0); - float k = (r * r) / 8.0; - - float num = NdotV; - float denom = NdotV * (1.0 - k) + k; - - return num / denom; -} - -float GeometrySmith(float3 N, float3 V, float3 L, float roughness) -{ - float NdotV = max(dot(N, V), 0.0); - float NdotL = max(dot(N, L), 0.0); - float ggx2 = GeometrySchlickGGX(NdotV, roughness); - float ggx1 = GeometrySchlickGGX(NdotL, roughness); - - return ggx1 * ggx2; -} - -// Easy trick to get tangent-normals to world-space to keep PBR code simplified. -float3 GetNormalFromMap(float3 worldPos, float2 texCoords, float3 normal) -{ - float3 tangentNormal = SAMPLE_TEXTURE(NormalTexture, texCoords).xyz * 2.0 - 1.0; - - float3 Q1 = ddx(worldPos); - float3 Q2 = ddy(worldPos); - float2 st1 = ddx(texCoords); - float2 st2 = ddy(texCoords); - - float3 N = normalize(normal); - float3 T = normalize(Q1*st2.y - Q2*st1.y); - float3 B = -normalize(cross(N, T)); - float3x3 TBN = float3x3(T, B, N); - - return normalize(mul(tangentNormal, TBN)); -} - -float4 ComputeColor( - float3 worldPosition, - float3 worldNormal, - float3 albedo, - float metallic, - float roughness -) { - float3 V = normalize(EyePosition - worldPosition); - float3 N = worldNormal; - - float3 F0 = float3(0.04, 0.04, 0.04); - F0 = lerp(F0, albedo, metallic); - - float3 Lo = float3(0.0, 0.0, 0.0); - - for (int i = 0; i < 4; i++) - { - float3 lightDir = LightPositions[i] - worldPosition; - float3 L = normalize(lightDir); - float3 H = normalize(V + L); - - float distance = length(lightDir); - float attenuation = 1.0 / (distance * distance); - float3 radiance = LightColors[i] * attenuation; - - float NDF = DistributionGGX(N, H, roughness); - float G = GeometrySmith(N, V, L, roughness); - float3 F = FresnelSchlick(max(dot(H, V), 0.0), F0); - - float3 numerator = NDF * G * F; - float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0); - float3 specular = numerator / max(denominator, 0.001); - - float3 kS = F; - float3 kD = float3(1.0, 1.0, 1.0) - kS; - - kD *= 1.0 - metallic; - - float NdotL = max(dot(N, L), 0.0); - Lo += (kD * albedo / PI + specular) * radiance * NdotL; - } - - float3 ambient = float3(0.03, 0.03, 0.03) * albedo * AO; - float3 color = ambient + Lo; - - color = color / (color + float3(1.0, 1.0, 1.0)); - float exposureConstant = 1.0 / 2.2; - color = pow(color, float3(exposureConstant, exposureConstant, exposureConstant)); - - return float4(color, 1.0); -} - -// The case where we have no texture maps for any PBR data -float4 None(PixelShaderInput input) : SV_TARGET0 -{ - return ComputeColor( - input.PositionWS, - input.NormalWS, - AlbedoValue, - MetallicValue, - RoughnessValue - ); -} - -float4 AlbedoMapPS(PixelShaderInput input) : SV_TARGET -{ - float3 albedo = pow(SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord), 2.2).rgb; - - return ComputeColor( - input.PositionWS, - input.NormalWS, - albedo, - MetallicValue, - RoughnessValue - ); -} - -float4 MetallicRoughnessPS(PixelShaderInput input) : SV_TARGET -{ - float2 metallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord).rg; - - return ComputeColor( - input.PositionWS, - input.NormalWS, - AlbedoValue, - metallicRoughness.r, - metallicRoughness.g - ); -} - -float4 NormalPS(PixelShaderInput input) : SV_TARGET -{ - float3 normal = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS); - - return ComputeColor( - input.PositionWS, - normal, - AlbedoValue, - MetallicValue, - RoughnessValue - ); -} - -float4 AlbedoMetallicRoughnessMapPS(PixelShaderInput input) : SV_TARGET -{ - float3 albedo = pow(SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord), 2.2).rgb; - float2 metallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord).rg; - - return ComputeColor( - input.PositionWS, - input.NormalWS, - albedo, - metallicRoughness.r, - metallicRoughness.g - ); -} - -float4 AlbedoNormalPS(PixelShaderInput input) : SV_TARGET -{ - float3 albedo = pow(SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord), 2.2).rgb; - float3 normal = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS); - - return ComputeColor( - input.PositionWS, - normal, - albedo, - MetallicValue, - RoughnessValue - ); -} - -float4 MetallicRoughnessNormalPS(PixelShaderInput input) : SV_TARGET -{ - float2 metallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord).rg; - float3 normal = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS); - - return ComputeColor( - input.PositionWS, - normal, - AlbedoValue, - metallicRoughness.r, - metallicRoughness.g - ); -} - -float4 AlbedoMetallicRoughnessNormalMapPS(PixelShaderInput input) : SV_TARGET -{ - float3 albedo = pow(SAMPLE_TEXTURE(AlbedoTexture, input.TexCoord), 2.2).rgb; - float2 metallicRoughness = SAMPLE_TEXTURE(MetallicRoughnessTexture, input.TexCoord).rg; - float3 normal = GetNormalFromMap(input.PositionWS, input.TexCoord, input.NormalWS); - - return ComputeColor( - input.PositionWS, - normal, - albedo, - metallicRoughness.r, - metallicRoughness.g - ); -} - -PixelShader PSArray[8] = -{ - compile ps_3_0 None(), - - compile ps_3_0 AlbedoMapPS(), - compile ps_3_0 MetallicRoughnessPS(), - compile ps_3_0 NormalPS(), - - compile ps_3_0 AlbedoMetallicRoughnessMapPS(), - compile ps_3_0 AlbedoNormalPS(), - compile ps_3_0 MetallicRoughnessNormalPS(), - - compile ps_3_0 AlbedoMetallicRoughnessNormalMapPS() -}; - -int PSIndices[8] = -{ - 0, 1, 2, 3, 4, 5, 6, 7 -}; - -int ShaderIndex = 0; - -Technique PBR -{ - Pass - { - VertexShader = compile vs_3_0 main_vs(); - PixelShader = (PSArray[PSIndices[ShaderIndex]]); - } -} diff --git a/Effects/PBREffect.fxb b/Effects/PBREffect.fxb deleted file mode 100644 index 97637627ab81ffc08b726b0604530721a4ea9bec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38008 zcmeI5Ux?h-b;s|{jx=jqmYg(goz^9y-3JFkYA1QfgPX{*9b%Ac#quVG1Z+hbMH|*y zu`4+;gmy$i>4QtRi627A!%rm-u4Ga_e3x|mSmjrgpkoZ@6goac$NIBN-?u3} z@Z{p^>f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Lx+{}EqCJ0PpXAR?^>?rS7SHoX49TB5u!E$)m^nE26J|E(LAS zKJ9bnTzY8n*vj(i@`*G1?|kHg`#*i?$f5nlu>Zd0Cr>Xf^;h=aeb-Ue= z=|5>y9c!M~DW(1YuDqU?<}qgV?-RSk9oM?e z3bL#Jp#6G$GTsMIJ=I@X?LWG5^wjF<<<-7N`|M)>D~DH>zuZ4|W^wscdTRCYk3N3a z<~e`q(g!@r}`qYvZ1U+JO#nWIZfi^tmW zNC4>*`inAs2rWN+?AX%TRmnnwKErCwMjv2rQ+nXZ#nloNoMP(); + var meshes = new List(); foreach (var mesh in sharpModel.LogicalMeshes) { - var meshParts = new List(); + var meshParts = new List(); foreach (var primitive in mesh.Primitives) { @@ -27,10 +27,10 @@ namespace Smuggler ); } - meshes.Add(new Mesh(meshParts.ToArray())); + meshes.Add(new MeshData(meshParts.ToArray())); } - var model = new Model(meshes.ToArray()); + var model = new ModelData(meshes.ToArray()); return model; } @@ -98,7 +98,7 @@ namespace Smuggler return null; } - private static MeshPart ImportMeshPart(GraphicsDevice graphicsDevice, System.Type vertexType, SharpGLTF.Schema2.MeshPrimitive primitive) + private static MeshPartData ImportMeshPart(GraphicsDevice graphicsDevice, System.Type vertexType, SharpGLTF.Schema2.MeshPrimitive primitive) { var indices = Indices(primitive); var positions = Positions(primitive); @@ -137,70 +137,41 @@ namespace Smuggler ImportVertexPositionTexture(primitive, vertexBuffer, indices, positions); } - var effect = new PBREffect(graphicsDevice); + var meshPartData = new MeshPartData( + vertexBuffer, + indexBuffer, + positions, + triangles + ); if (primitive.Material != null) { var normalChannel = primitive.Material.FindChannel("Normal"); if (normalChannel.HasValue) { - if (normalChannel.Value.Texture != null) - { - effect.NormalTexture = Texture2D.FromStream( - graphicsDevice, - normalChannel.Value.Texture.PrimaryImage.Content.Open() - ); - } + if (normalChannel.Value.Texture != null) + { + meshPartData.NormalTexture = Texture2D.FromStream( + graphicsDevice, + normalChannel.Value.Texture.PrimaryImage.Content.Open() + ); + } } - //var occlusionChannel = primitive.Material.FindChannel("Occlusion"); - //if (occlusionChannel.HasValue) - //{ - // if (occlusionChannel.Value.Texture != null) - // { - // effect.OcclusionTexture = Texture2D.FromStream( - // graphicsDevice, - // occlusionChannel.Value.Texture.PrimaryImage.Content.Open() - // ); - // } - - // effect.OcclusionStrength = occlusionChannel.Value.Parameter.X; - //} - - //var emissiveChannel = primitive.Material.FindChannel("Emissive"); - //if (emissiveChannel.HasValue) - //{ - // if (emissiveChannel.Value.Texture != null) - // { - // effect.EmissionTexture = Texture2D.FromStream( - // graphicsDevice, - // emissiveChannel.Value.Texture.PrimaryImage.Content.Open() - // ); - // } - - // var parameter = emissiveChannel.Value.Parameter; - - // effect.EmissiveFactor = new Vector3( - // parameter.X, - // parameter.Y, - // parameter.Z - // ); - //} - var albedoChannel = primitive.Material.FindChannel("BaseColor"); if (albedoChannel.HasValue) { if (albedoChannel.Value.Texture != null) { - effect.AlbedoTexture = Texture2D.FromStream( - graphicsDevice, - albedoChannel.Value.Texture.PrimaryImage.Content.Open() - ); + meshPartData.AlbedoTexture = Texture2D.FromStream( + graphicsDevice, + albedoChannel.Value.Texture.PrimaryImage.Content.Open() + ); } var parameter = albedoChannel.Value.Parameter; - effect.Albedo = new Vector3( + meshPartData.Albedo = new Vector3( parameter.X, parameter.Y, parameter.Z @@ -212,63 +183,20 @@ namespace Smuggler { if (metallicRoughnessChannel.Value.Texture != null) { - effect.MetallicRoughnessTexture = Texture2D.FromStream( - graphicsDevice, - metallicRoughnessChannel.Value.Texture.PrimaryImage.Content.Open() - ); + meshPartData.MetallicRoughnessTexture = Texture2D.FromStream( + graphicsDevice, + metallicRoughnessChannel.Value.Texture.PrimaryImage.Content.Open() + ); } var parameter = metallicRoughnessChannel.Value.Parameter; - effect.Metallic = parameter.X; - effect.Roughness = parameter.Y; + meshPartData.Metallic = parameter.X; + meshPartData.Roughness = parameter.Y; } } - effect.Albedo = new Vector3(0.5f, 0, 0); - effect.AO = 1f; - - effect.Lights[0] = new PBRLight( - new Vector3(-10f, 10f, -5f), - new Vector3(300f, 300f, 300f) - ); - - effect.Lights[1] = new PBRLight( - new Vector3(10f, 10f, 5f), - new Vector3(300f, 300f, 300f) - ); - - effect.Lights[2] = new PBRLight( - new Vector3(-10f, -10f, 5f), - new Vector3(300f, 300f, 300f) - ); - - effect.Lights[3] = new PBRLight( - new Vector3(10f, -10f, 5f), - new Vector3(300f, 300f, 300f) - ); - - /* FIXME: how to load cube maps from GLTF? */ - /* - var diffuseChannel = primitive.Material.FindChannel("Diffuse"); - if (diffuseChannel.HasValue) - { - } - - var specularChannel = primitive.Material.FindChannel("SpecularGlossiness"); - if (specularChannel.HasValue) - { - } - */ - - - return new MeshPart( - vertexBuffer, - indexBuffer, - positions, - triangles, - effect - ); + return meshPartData; } /* Attribute Getters */ @@ -332,7 +260,7 @@ namespace Smuggler private static Triangle[] Triangles(SharpGLTF.Schema2.MeshPrimitive primitive) { var triangles = new List(); - + foreach (var (a, b, c) in primitive.GetTriangleIndices()) { triangles.Add(new Triangle(a, b, c)); @@ -361,7 +289,8 @@ namespace Smuggler VertexBuffer vertexBuffer, uint[] indices, Vector3[] positions - ) { + ) + { var colors = Colors(primitive); var vertices = new VertexPositionColor[positions.Length]; @@ -385,7 +314,8 @@ namespace Smuggler VertexBuffer vertexBuffer, uint[] indices, Vector3[] positions - ) { + ) + { var colors = Colors(primitive); var texcoords = TexCoords(primitive); @@ -412,7 +342,8 @@ namespace Smuggler VertexBuffer vertexBuffer, uint[] indices, Vector3[] positions - ) { + ) + { var normals = Normals(primitive); var texcoords = TexCoords(primitive); @@ -439,7 +370,8 @@ namespace Smuggler VertexBuffer vertexBuffer, uint[] indices, Vector3[] positions - ) { + ) + { var texcoords = TexCoords(primitive); var vertices = new VertexPositionTexture[positions.Length]; diff --git a/Mesh.cs b/Mesh.cs deleted file mode 100644 index f8bd217..0000000 --- a/Mesh.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace Smuggler -{ - public class Mesh - { - public MeshPart[] MeshParts { get; } - - public Mesh(MeshPart[] meshParts) - { - MeshParts = meshParts; - } - - public void Draw(GraphicsDevice graphicsDevice, Matrix world, Matrix view, Matrix projection) - { - foreach (var meshPart in MeshParts) - { - meshPart.Draw(graphicsDevice, world, view, projection); - } - } - } -} diff --git a/MeshData.cs b/MeshData.cs new file mode 100644 index 0000000..3c80670 --- /dev/null +++ b/MeshData.cs @@ -0,0 +1,12 @@ +namespace Smuggler +{ + public class MeshData + { + public MeshPartData[] MeshParts { get; } + + public MeshData(MeshPartData[] meshParts) + { + MeshParts = meshParts; + } + } +} diff --git a/MeshPart.cs b/MeshPart.cs deleted file mode 100644 index bc019ea..0000000 --- a/MeshPart.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace Smuggler -{ - public class MeshPart - { - public IndexBuffer IndexBuffer { get; } - public VertexBuffer VertexBuffer { get; } - public Triangle[] Triangles { get; } - public PBREffect Effect { get; } - public Vector3[] Positions { get; } - - public MeshPart(VertexBuffer vertexBuffer, IndexBuffer indexBuffer, Vector3[] positions, Triangle[] triangles, PBREffect effect) - { - VertexBuffer = vertexBuffer; - IndexBuffer = indexBuffer; - Positions = positions; - Triangles = triangles; - Effect = effect; - } - - public void Draw(GraphicsDevice graphicsDevice, Matrix world, Matrix view, Matrix projection) - { - graphicsDevice.SetVertexBuffer(VertexBuffer); - graphicsDevice.Indices = IndexBuffer; - - Effect.World = world; - Effect.View = view; - Effect.Projection = projection; - - foreach (var pass in Effect.CurrentTechnique.Passes) - { - pass.Apply(); - - graphicsDevice.DrawIndexedPrimitives( - PrimitiveType.TriangleList, - 0, - 0, - VertexBuffer.VertexCount, - 0, - Triangles.Length - ); - } - } - } -} diff --git a/MeshPartData.cs b/MeshPartData.cs new file mode 100644 index 0000000..2f935d3 --- /dev/null +++ b/MeshPartData.cs @@ -0,0 +1,34 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Smuggler +{ + public class MeshPartData + { + public IndexBuffer IndexBuffer { get; } + public VertexBuffer VertexBuffer { get; } + public Triangle[] Triangles { get; } + public Vector3[] Positions { get; } + + public Texture2D AlbedoTexture { get; set; } = null; + public Texture2D NormalTexture { get; set; } = null; + public Texture2D MetallicRoughnessTexture { get; set; } = null; + + public Vector3 Albedo { get; set; } = Vector3.One; + public float Metallic { get; set; } = 0.5f; + public float Roughness { get; set; } = 0.5f; + + public MeshPartData( + VertexBuffer vertexBuffer, + IndexBuffer indexBuffer, + Vector3[] positions, + Triangle[] triangles + ) + { + VertexBuffer = vertexBuffer; + IndexBuffer = indexBuffer; + Positions = positions; + Triangles = triangles; + } + } +} diff --git a/Model.cs b/Model.cs deleted file mode 100644 index eeba250..0000000 --- a/Model.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace Smuggler -{ - public class Model - { - public Mesh[] Meshes { get; } - public Texture2D[] Textures { get; } - - public Model(Mesh[] meshes) - { - Meshes = meshes; - } - - public void Draw(GraphicsDevice graphicsDevice, Matrix world, Matrix view, Matrix projection) - { - foreach (var mesh in Meshes) - { - mesh.Draw(graphicsDevice, world, view, projection); - } - } - } -} diff --git a/ModelData.cs b/ModelData.cs new file mode 100644 index 0000000..3d1a03a --- /dev/null +++ b/ModelData.cs @@ -0,0 +1,15 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Smuggler +{ + public class ModelData + { + public MeshData[] Meshes { get; } + + public ModelData(MeshData[] meshes) + { + Meshes = meshes; + } + } +} diff --git a/Resources.cs b/Resources.cs deleted file mode 100644 index 53fc5ea..0000000 --- a/Resources.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.IO; - -namespace Smuggler -{ - internal class Resources - { - public static byte[] PBREffect - { - get - { - if (pbrEffect == null) - { - pbrEffect = GetResource("PBREffect"); - } - return pbrEffect; - } - } - - private static byte[] pbrEffect; - - private static byte[] GetResource(string name) - { - Stream stream = typeof(Resources).Assembly.GetManifestResourceStream( - "Smuggler.Resources." + name + ".fxb" - ); - using (MemoryStream ms = new MemoryStream()) - { - stream.CopyTo(ms); - return ms.ToArray(); - } - } - } -} diff --git a/Smuggler.csproj b/Smuggler.csproj index e5628ef..c9385e5 100644 --- a/Smuggler.csproj +++ b/Smuggler.csproj @@ -19,10 +19,4 @@ - - - Smuggler.Resources.PBREffect.fxb - - -