mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
UnbindTexture, PBR changes, Test scene
This commit is contained in:
@@ -12,8 +12,8 @@ namespace GlitchyEngine.Content
|
||||
{
|
||||
static readonly Matrix RightToLeftHand = .Scaling(1, 1, -1);
|
||||
|
||||
public static void LoadModel(String filename, Effect validationEffect, Material material, EcsWorld world,
|
||||
List<AnimationClip> outClips)
|
||||
public static EcsEntity LoadModel(String filename, Effect validationEffect, Material material, EcsWorld world,
|
||||
List<AnimationClip> outClips, StringView entityName = StringView())
|
||||
{
|
||||
CGLTF.Options options = .();
|
||||
CGLTF.Data* data;
|
||||
@@ -24,39 +24,48 @@ namespace GlitchyEngine.Content
|
||||
result = CGLTF.LoadBuffers(options, data, filename);
|
||||
|
||||
Log.EngineLogger.Assert(result == .Success, "Failed to load buffers");
|
||||
|
||||
(EcsEntity entity, ?) = CreateEntity(world, entityName, .InvalidEntity);
|
||||
|
||||
for(var node in data.Scenes[0].Nodes)
|
||||
{
|
||||
NodesToEntities(data, node, null, world, validationEffect, material, outClips);
|
||||
NodesToEntities(data, node, entity, world, validationEffect, material, outClips);
|
||||
}
|
||||
|
||||
CGLTF.Free(data);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, EcsEntity? parentEntity, EcsWorld world, Effect validationEffect, Material material, List<AnimationClip> clips)
|
||||
private static (EcsEntity Entity, TransformComponent* Transform) CreateEntity(EcsWorld world, StringView? name, EcsEntity parent)
|
||||
{
|
||||
EcsEntity entity = world.NewEntity();
|
||||
|
||||
//#if DEBUG
|
||||
var nameComponent = world.AssignComponent<DebugNameComponent>(entity);
|
||||
|
||||
if (node.Name != null)
|
||||
if (name != null && name.Value.Ptr != null)
|
||||
{
|
||||
nameComponent.SetName(StringView(node.Name));
|
||||
nameComponent.SetName(name.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
nameComponent.SetName("Unnamed Node");
|
||||
}
|
||||
//#endif
|
||||
|
||||
if(parentEntity.HasValue)
|
||||
{
|
||||
var childParent = world.AssignComponent<ParentComponent>(entity);
|
||||
childParent.Entity = parentEntity.Value;
|
||||
}
|
||||
/////TODO: !!!!!!!!REPORT!!!!!!!!!!!!!
|
||||
// This works
|
||||
TransformComponent cmp = .();
|
||||
var childTransform = world.AssignComponent<TransformComponent>(entity, cmp);
|
||||
// This trashes the stack
|
||||
//var childTransform = world.AssignComponent<TransformComponent>(entity);
|
||||
childTransform.Parent = parent;
|
||||
|
||||
var childTransform = world.AssignComponent<TransformComponent>(entity);
|
||||
return (entity, childTransform);
|
||||
}
|
||||
|
||||
private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, EcsEntity parentEntity, EcsWorld world, Effect validationEffect, Material material, List<AnimationClip> clips)
|
||||
{
|
||||
(EcsEntity entity, TransformComponent* childTransform) = CreateEntity(world, node.Name == null ? null : StringView(node.Name), parentEntity);
|
||||
|
||||
if(node.HasMatrix)
|
||||
{
|
||||
|
||||
@@ -185,6 +185,11 @@ namespace GlitchyEngine.Renderer
|
||||
NativeContext.InputAssembler.SetPrimitiveTopology((DirectX.Common.PrimitiveTopology)primitiveTopology);
|
||||
}
|
||||
|
||||
private uint32 _ps_FirstTexture;
|
||||
private uint32 _ps_BoundTextures;
|
||||
private uint32 _vs_FirstTexture;
|
||||
private uint32 _vs_BoundTextures;
|
||||
|
||||
/**
|
||||
* Binds the given shader to the corresponding shader stage.
|
||||
* @param shader The shader that will be bound to the graphics context.
|
||||
@@ -219,9 +224,15 @@ namespace GlitchyEngine.Renderer
|
||||
// TODO: bind uavs
|
||||
NativeContext.PixelShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
||||
NativeContext.PixelShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
||||
|
||||
_ps_FirstTexture = _firstTexture;
|
||||
_ps_BoundTextures = _textureCount;
|
||||
case typeof(VertexShader):
|
||||
NativeContext.VertexShader.SetShaderResources(_firstTexture, _textureCount, &_textures[_firstTexture]);
|
||||
NativeContext.VertexShader.SetSamplers(_firstTexture, _textureCount, &_samplers[_firstTexture]);
|
||||
|
||||
_vs_FirstTexture = _firstTexture;
|
||||
_vs_BoundTextures = _textureCount;
|
||||
default:
|
||||
Runtime.FatalError(scope $"Shader stage \"{typeof(TShader)}\" not implemented.");
|
||||
}
|
||||
@@ -243,6 +254,14 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public override void UnbindTextures()
|
||||
{
|
||||
void** voidArray = scope void*[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]*;
|
||||
|
||||
NativeContext.PixelShader.SetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, (.)voidArray);
|
||||
NativeContext.VertexShader.SetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, (.)voidArray);
|
||||
}
|
||||
|
||||
public override void SetVertexShader(VertexShader vertexShader)
|
||||
{
|
||||
BindShaderToStage(vertexShader);
|
||||
|
||||
@@ -142,6 +142,11 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
_context.SetViewport(viewport);
|
||||
}
|
||||
|
||||
public override void UnbindTextures()
|
||||
{
|
||||
_context.UnbindTextures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,5 +117,7 @@ namespace GlitchyEngine.Renderer
|
||||
public extern void SetVertexShader(VertexShader vertexShader);
|
||||
|
||||
public extern void SetPixelShader(PixelShader pixelShader);
|
||||
|
||||
public extern void UnbindTextures();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,5 +109,10 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
SetViewport(.(left, top, width, height, minDepth, maxDepth));
|
||||
}
|
||||
|
||||
public static void UnbindTextures()
|
||||
{
|
||||
_rendererAPI.UnbindTextures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ namespace GlitchyEngine.Renderer
|
||||
RenderTarget2DDescription albedoDesc = .(.R8G8B8A8_UNorm, width, height, 1, 1, .D24_UNorm_S8_UInt);
|
||||
Albedo = new RenderTarget2D(albedoDesc);
|
||||
|
||||
RenderTarget2DDescription normalDesc = .(.R8G8B8A8_SNorm, width, height);
|
||||
RenderTarget2DDescription normalDesc = .(.R16G16B16A16_SNorm, width, height);
|
||||
Normal = new RenderTarget2D(normalDesc);
|
||||
|
||||
RenderTarget2DDescription tangentDesc = .(.R8G8B8A8_SNorm, width, height);
|
||||
RenderTarget2DDescription tangentDesc = .(.R16G16B16A16_SNorm, width, height);
|
||||
Tangent = new RenderTarget2D(tangentDesc);
|
||||
|
||||
RenderTarget2DDescription positionDesc = .(.R32G32B32A32_Float, width, height);
|
||||
@@ -289,6 +289,7 @@ namespace GlitchyEngine.Renderer
|
||||
// {
|
||||
_gBuffer.EnsureSize(_sceneConstants.CameraTarget.Width, _sceneConstants.CameraTarget.Height);
|
||||
_gBuffer.Clear();
|
||||
RenderCommand.UnbindRenderTargets();
|
||||
_gBuffer.Bind();
|
||||
|
||||
RenderCommand.SetViewport(0, 0, _sceneConstants.CameraTarget.Width, _sceneConstants.CameraTarget.Height);
|
||||
@@ -334,6 +335,8 @@ namespace GlitchyEngine.Renderer
|
||||
s_quadGeometry.Bind();
|
||||
RenderCommand.DrawIndexed(s_quadGeometry);
|
||||
|
||||
RenderCommand.UnbindTextures();
|
||||
|
||||
// TODO: Draw lights to camera target
|
||||
// }
|
||||
|
||||
|
||||
@@ -55,5 +55,7 @@ namespace GlitchyEngine.Renderer
|
||||
public extern void DrawIndexedInstanced(GeometryBinding geometry);
|
||||
|
||||
public extern void SetViewport(Viewport viewport);
|
||||
|
||||
public extern void UnbindTextures();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user