Checking HLSL shaders.
This commit is contained in:
parent
a7878c109a
commit
f291278f2c
|
|
@ -15,6 +15,8 @@ add_executable(model_render model_render.cpp
|
||||||
)
|
)
|
||||||
add_shader(model_render shader/model.vert.glsl)
|
add_shader(model_render shader/model.vert.glsl)
|
||||||
add_shader(model_render shader/model.frag.glsl)
|
add_shader(model_render shader/model.frag.glsl)
|
||||||
|
add_shader(model_render shader/model.vs.hlsl)
|
||||||
|
add_shader(model_render shader/model.ps.hlsl)
|
||||||
|
|
||||||
target_link_libraries(model_render PRIVATE aster_core)
|
target_link_libraries(model_render PRIVATE aster_core)
|
||||||
target_link_libraries(model_render PRIVATE util_helper)
|
target_link_libraries(model_render PRIVATE util_helper)
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ struct RenderResourceManager;
|
||||||
struct Swapchain;
|
struct Swapchain;
|
||||||
struct Device;
|
struct Device;
|
||||||
|
|
||||||
constexpr auto VERTEX_SHADER_FILE = "shader/model.vert.glsl.spv";
|
constexpr auto VERTEX_SHADER_FILE = "shader/model.vs.hlsl.spv";
|
||||||
constexpr auto FRAGMENT_SHADER_FILE = "shader/model.frag.glsl.spv";
|
constexpr auto FRAGMENT_SHADER_FILE = "shader/model.ps.hlsl.spv";
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
typedef float4 PositionData;
|
||||||
|
typedef float2 UVData;
|
||||||
|
typedef float4 NormalData;
|
||||||
|
|
||||||
|
struct MaterialData
|
||||||
|
{
|
||||||
|
float4 m_AlbedoFactor;
|
||||||
|
float3 m_EmissionFactor;
|
||||||
|
float m_MetalFactor;
|
||||||
|
float m_RoughFactor;
|
||||||
|
uint m_AlbedoTex;
|
||||||
|
uint m_NormalTex;
|
||||||
|
uint m_MetalRoughTex;
|
||||||
|
uint m_OcclusionTex;
|
||||||
|
uint m_EmissionTex;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Block
|
||||||
|
{
|
||||||
|
uint vertexBufferHandle;
|
||||||
|
uint uvBufferHandle;
|
||||||
|
uint materialBufferHandle;
|
||||||
|
uint m_VertexOffset;
|
||||||
|
int m_NormalOffset;
|
||||||
|
int m_TexCoord0Offset;
|
||||||
|
uint m_FirstIndex;
|
||||||
|
uint m_IndexCount;
|
||||||
|
int m_MaterialIdx;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Camera
|
||||||
|
{
|
||||||
|
row_major float4x4 model;
|
||||||
|
row_major float4x4 view;
|
||||||
|
row_major float4x4 proj;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define INVALID_HANDLE 0xFFFFFFFF
|
||||||
|
|
||||||
|
[[vk::binding(0, 0)]] StructuredBuffer<PositionData> vertexBuffer[];
|
||||||
|
[[vk::binding(0, 0)]] StructuredBuffer<UVData> uvBuffer[];
|
||||||
|
[[vk::binding(0, 0)]] StructuredBuffer<NormalData> normalBuffer[];
|
||||||
|
[[vk::binding(0, 0)]] StructuredBuffer<MaterialData> materialsBuffer[];
|
||||||
|
|
||||||
|
[[vk::binding(1, 0)]] Texture2D<float4> textures[];
|
||||||
|
[[vk::binding(1, 0)]] SamplerState immutableSamplers[];
|
||||||
|
|
||||||
|
[[vk::binding(0, 1)]] ConstantBuffer<Camera> camera;
|
||||||
|
|
||||||
|
[[vk::push_constant]]
|
||||||
|
Block pcb;
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include "bindless_structs.hlsli"
|
||||||
|
|
||||||
|
struct FS_Input
|
||||||
|
{
|
||||||
|
float2 inUV : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FS_Output
|
||||||
|
{
|
||||||
|
float4 outColor : SV_Target0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Float4
|
||||||
|
{
|
||||||
|
float4 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4 GetAlbedo(uint materialBufferId, int materialId, float2 uv0)
|
||||||
|
{
|
||||||
|
if (materialId < 0)
|
||||||
|
{
|
||||||
|
return float4(1.0f, 0.0f, 1.0f, 1.0f); // Magenta
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float4 albedoFactor = materialsBuffer[materialBufferId][materialId].m_AlbedoFactor;
|
||||||
|
uint albedoTexId = materialsBuffer[materialBufferId][materialId].m_AlbedoTex;
|
||||||
|
if (albedoTexId == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
return albedoFactor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return textures[albedoTexId].Sample(immutableSamplers[albedoTexId], uv0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_Output main(FS_Input stage_input)
|
||||||
|
{
|
||||||
|
FS_Output stage_output;
|
||||||
|
stage_output.outColor = GetAlbedo(pcb.materialBufferHandle, pcb.m_MaterialIdx, stage_input.inUV);
|
||||||
|
return stage_output;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include "bindless_structs.hlsli"
|
||||||
|
|
||||||
|
struct VS_Input
|
||||||
|
{
|
||||||
|
uint vertexIndex : SV_VertexID;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VS_Output
|
||||||
|
{
|
||||||
|
UVData outUV : TEXCOORD0;
|
||||||
|
float4 position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
float2 GetUV(uint bufferId, uint vertexIdx)
|
||||||
|
{
|
||||||
|
if (bufferId == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
return 0.0f.xx;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return uvBuffer[bufferId][vertexIdx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 GetPosition(uint bufferId, uint vertexIdx)
|
||||||
|
{
|
||||||
|
return vertexBuffer[bufferId][vertexIdx].xyz;
|
||||||
|
}
|
||||||
|
|
||||||
|
VS_Output main(VS_Input stage_input)
|
||||||
|
{
|
||||||
|
VS_Output stage_output;
|
||||||
|
stage_output.outUV = GetUV(pcb.uvBufferHandle, stage_input.vertexIndex);
|
||||||
|
stage_output.position = mul(float4(GetPosition(pcb.vertexBufferHandle, stage_input.vertexIndex), 1.0f), mul(camera.model, mul(camera.view, camera.proj)));
|
||||||
|
return stage_output;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue