Skip to content

Commit

Permalink
Finish Slang shader support
Browse files Browse the repository at this point in the history
  • Loading branch information
xezno committed Dec 19, 2024
1 parent 830696b commit 721a2fa
Show file tree
Hide file tree
Showing 27 changed files with 411 additions and 337 deletions.
22 changes: 14 additions & 8 deletions Content/core/shaders/pbr.mshdr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Common

struct FS_IN
{
float4 vPosition : SV_POSITION;

float3 vColor : COLOR;
float3 vPositionWS : TEXCOORD0;
float3 vCameraWS : TEXCOORD1;
Expand All @@ -32,7 +34,7 @@ Common
};

// Push constants block
cbuffer PushConstants
[[vk::push_constant]] cbuffer PushConstants
{
float4 data;

Expand All @@ -59,6 +61,7 @@ Vertex
float3 vBitangent : BINORMAL;
};

[shader("vertex")]
FS_IN main(VS_IN input)
{
FS_IN output;
Expand All @@ -67,7 +70,7 @@ Vertex
output.vPositionWS = mul(float4(input.vPosition, 1.0f), model_matrix).xyz;
output.vCameraWS = vCameraPosWS;
output.vColor = input.vColor;
output.vTexCoord = input.vTexCoord;
output.vTexCoord = input.vTexCoord * float2( -1, 1 );
output.vNormalWS = input.vNormal;

// Calculate TBN matrix for lighting
Expand Down Expand Up @@ -95,6 +98,8 @@ Vertex

// Finish - transform into clip space
float4 position = mul(float4(input.vPosition, 1.0f), render_matrix);
output.vPosition = position;

return output;
}
}
Expand All @@ -103,13 +108,13 @@ Fragment
{
#define PI 3.14159265359

Texture2D diffuseTexture : register(t0);
Texture2D normalTexture : register(t1);
Texture2D ambientOcclusionTexture : register(t2);
Texture2D metalnessTexture : register(t3);
Texture2D roughnessTexture : register(t4);
[[vk::binding(0, 0)]] Texture2D diffuseTexture;
[[vk::binding(1, 0)]] Texture2D normalTexture;
[[vk::binding(2, 0)]] Texture2D ambientOcclusionTexture;
[[vk::binding(3, 0)]] Texture2D metalnessTexture;
[[vk::binding(4, 0)]] Texture2D roughnessTexture;

SamplerState samplerState : register(s0);
[[vk::binding(6, 0)]] SamplerState samplerState;

float3 fresnelSchlick(float cosTheta, float3 F0)
{
Expand Down Expand Up @@ -207,6 +212,7 @@ Fragment
return lerp(v / (1.0f + l), tv, tv);
}

[shader("fragment")]
float4 main(FS_IN input) : SV_TARGET
{
// Collect material properties
Expand Down
53 changes: 0 additions & 53 deletions Content/core/shaders/tonemap/agx.mshdr

This file was deleted.

223 changes: 0 additions & 223 deletions Content/core/shaders/ui/ui.mshdr

This file was deleted.

2 changes: 0 additions & 2 deletions Samples/mocha-minimal/code/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ public override void OnStartup()
// Spawn a player
var player = new Player();
player.Position = new Vector3( 0, 5, 10 );

_ = new PostProcess( "shaders/tonemap/agx.mshdr" );
}
}
7 changes: 7 additions & 0 deletions Source/Mocha.Common/ShaderType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Mocha;

public enum ShaderType
{
Vertex,
Fragment
}
4 changes: 3 additions & 1 deletion Source/Mocha.Host/Managed/hostmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ inline void HostManager::Invoke( std::string _method, void* params, const char_t

if (fnPtr == nullptr)
{
spdlog::error( "Failed to load managed method {}", _method );
spdlog::error( "Failed to load managed method {}, {}", _method, rc );
__debugbreak();
return;
}

// Invoke method
Expand Down
5 changes: 5 additions & 0 deletions Source/Mocha.Host/Rendering/Assets/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ void Material::CreateResources()
descriptorInfo.bindings.push_back( bindingInfo );
}

DescriptorBindingInfo_t samplerBindingInfo = {};
samplerBindingInfo.type = DESCRIPTOR_BINDING_TYPE_SAMPLER;
samplerBindingInfo.sampler = m_samplerType;
descriptorInfo.bindings.push_back( samplerBindingInfo );

m_descriptor = Descriptor( descriptorInfo );
pipelineInfo.descriptors.push_back( &m_descriptor );

Expand Down
Loading

0 comments on commit 721a2fa

Please sign in to comment.