Skip to content
Open
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions TGC.MonoGame.Samples/Content/3D/sponza/Sponza.fbm/lion.tga
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions TGC.MonoGame.Samples/Content/3D/sponza/Sponza.fbx
Git LFS file not shown
31 changes: 31 additions & 0 deletions TGC.MonoGame.Samples/Content/Content.mgcb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@
/processorParam:TextureFormat=Compressed
/build:3D/skybox/cube.fbx

#begin 3D/sponza/Sponza.fbx
/importer:FbxImporter
/processor:ModelProcessor
/processorParam:ColorKeyColor=0,0,0,0
/processorParam:ColorKeyEnabled=True
/processorParam:DefaultEffect=BasicEffect
/processorParam:GenerateMipmaps=True
/processorParam:GenerateTangentFrames=False
/processorParam:PremultiplyTextureAlpha=True
/processorParam:PremultiplyVertexColors=True
/processorParam:ResizeTexturesToPowerOfTwo=False
/processorParam:RotationX=0
/processorParam:RotationY=0
/processorParam:RotationZ=0
/processorParam:Scale=1
/processorParam:SwapWindingOrder=False
/processorParam:TextureFormat=Compressed
/build:3D/sponza/Sponza.fbx

#begin 3D/tank/tank.fbx
/importer:FbxImporter
/processor:ModelProcessor
Expand Down Expand Up @@ -213,6 +232,18 @@
/processorParam:DebugMode=Auto
/build:Effects/BasicShader.fx

#begin Effects/BasicTexture.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:Effects/BasicTexture.fx

#begin Effects/BasicTexture.fx
/importer:EffectImporter
/processor:EffectProcessor
/processorParam:DebugMode=Auto
/build:Effects/BasicTexture.fx

#begin Effects/BlinnPhong.fx
/importer:EffectImporter
/processor:EffectProcessor
Expand Down
65 changes: 65 additions & 0 deletions TGC.MonoGame.Samples/Content/Effects/BasicTexture.fx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

float4x4 World;
float4x4 View;
float4x4 Projection;

struct VertexShaderInput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
};

struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float2 TextureCoordinate : TEXCOORD1;
};

texture ModelTexture;
sampler2D textureSampler = sampler_state
{
Texture = (ModelTexture);
MagFilter = Linear;
MinFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;

float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);

// Project position
output.Position = mul(viewPosition, Projection);

// Propagate texture coordinates
output.TextureCoordinate = input.TextureCoordinate;

return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
// Get the texture texel textureSampler is the sampler, Texcoord is the interpolated coordinates
return tex2D(textureSampler, input.TextureCoordinate);
}

technique BasicDrawing
{
pass P0
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
81 changes: 81 additions & 0 deletions TGC.MonoGame.Samples/Models/Geometry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using Microsoft.Xna.Framework.Graphics;

namespace TGC.MonoGame.Samples.Models;

public class Geometry : IDisposable
{
internal VertexBuffer VertexBuffer;

internal IndexBuffer IndexBuffer;

internal int VertexOffset;

internal int StartIndex;

internal int PrimitiveCount;

internal bool OwnsVertexBuffer;

internal bool OwnsIndexBuffer;


internal static Geometry FromMeshPart(ModelMeshPart part)
{
return new Geometry(part);
}

internal Geometry()
{ }

internal Geometry(VertexBuffer vertexBuffer, IndexBuffer indexBuffer)
{
VertexBuffer = vertexBuffer;
IndexBuffer = indexBuffer;
VertexOffset = 0;
StartIndex = 0;
PrimitiveCount = indexBuffer.IndexCount / 3;
OwnsVertexBuffer = true;
OwnsIndexBuffer = true;
}

private Geometry(ModelMeshPart part)
{
VertexBuffer = part.VertexBuffer;
IndexBuffer = part.IndexBuffer;
VertexOffset = part.VertexOffset;
StartIndex = part.StartIndex;
PrimitiveCount = part.PrimitiveCount;
OwnsVertexBuffer = false;
OwnsIndexBuffer = false;
}

public void Draw(Effect effect)
{
var graphicsDevice = effect.GraphicsDevice;

graphicsDevice.SetVertexBuffer(VertexBuffer);
graphicsDevice.Indices = IndexBuffer;

foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
VertexOffset, StartIndex, PrimitiveCount);
}
}


public void Dispose()
{
if (OwnsVertexBuffer)
{
VertexBuffer.Dispose();
}

if (OwnsIndexBuffer)
{
IndexBuffer.Dispose();
}
}
}
13 changes: 13 additions & 0 deletions TGC.MonoGame.Samples/Models/GeometryData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TGC.MonoGame.Samples.Models;

public struct GeometryData(Geometry geometry, Matrix relativeMatrix, Texture[] textures)
{
public Geometry Geometry { get; private set; } = geometry;

public Matrix RelativeMatrix { get; private set; } = relativeMatrix;

public Texture[] Textures { get; private set; } = textures;
}
Loading
Loading