Compare commits
13 Commits
7857833620
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cdfcde5a3 | |||
| ef12ba03d8 | |||
| a425166018 | |||
| f253b6f683 | |||
| 2fb5eb1dd7 | |||
| 09239c0cda | |||
| 44a34ed0a2 | |||
| e8a40e04a9 | |||
| 26ab321641 | |||
| 19e7382ff7 | |||
| 49b9f5778a | |||
| 2b1ba018ab | |||
| c87a0fa78a |
@@ -2,3 +2,4 @@
|
||||
main
|
||||
compile_commands.json
|
||||
vendor
|
||||
ktx/build
|
||||
|
||||
+37
-37
@@ -5,57 +5,57 @@
|
||||
*/
|
||||
|
||||
struct VSInput {
|
||||
float3 Pos;
|
||||
float3 Normal;
|
||||
float3 Pos;
|
||||
float3 Normal;
|
||||
float2 UV;
|
||||
};
|
||||
|
||||
Sampler2D textures[];
|
||||
|
||||
struct ShaderData {
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4x4 model[3];
|
||||
float4 lightPos;
|
||||
uint32_t selected;
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4x4 model[3];
|
||||
float4 lightPos;
|
||||
uint32_t selected;
|
||||
};
|
||||
|
||||
struct VSOutput {
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Normal;
|
||||
float2 UV;
|
||||
float3 Factor;
|
||||
float3 LightVec;
|
||||
float3 ViewVec;
|
||||
uint32_t InstanceIndex;
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Normal;
|
||||
float2 UV;
|
||||
float3 Factor;
|
||||
float3 LightVec;
|
||||
float3 ViewVec;
|
||||
uint32_t InstanceIndex;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VSOutput main(VSInput input, uniform ShaderData *shaderData, uint instanceIndex : SV_VulkanInstanceID) {
|
||||
VSOutput output;
|
||||
float4x4 modelMat = shaderData->model[instanceIndex];
|
||||
output.Normal = mul((float3x3)mul(shaderData->view, modelMat), input.Normal);
|
||||
output.UV = input.UV;
|
||||
output.Pos = mul(shaderData->projection, mul(shaderData->view, mul(modelMat, float4(input.Pos.xyz, 1.0))));
|
||||
output.Factor = (shaderData->selected == instanceIndex ? 3.0f : 1.0f);
|
||||
output.InstanceIndex = instanceIndex;
|
||||
// Calculate view vectors required for lighting
|
||||
float4 fragPos = mul(mul(shaderData->view, modelMat), float4(input.Pos.xyz, 1.0));
|
||||
output.LightVec = shaderData->lightPos.xyz - fragPos.xyz;
|
||||
output.ViewVec = -fragPos.xyz;
|
||||
return output;
|
||||
VSOutput output;
|
||||
float4x4 modelMat = shaderData->model[instanceIndex];
|
||||
output.Normal = mul((float3x3)mul(shaderData->view, modelMat), input.Normal);
|
||||
output.UV = input.UV;
|
||||
output.Pos = mul(shaderData->projection, mul(shaderData->view, mul(modelMat, float4(input.Pos.xyz, 1.0))));
|
||||
output.Factor = (shaderData->selected == instanceIndex ? 3.0f : 1.0f);
|
||||
output.InstanceIndex = instanceIndex;
|
||||
// Calculate view vectors required for lighting
|
||||
float4 fragPos = mul(mul(shaderData->view, modelMat), float4(input.Pos.xyz, 1.0));
|
||||
output.LightVec = shaderData->lightPos.xyz - fragPos.xyz;
|
||||
output.ViewVec = -fragPos.xyz;
|
||||
return output;
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 main(VSOutput input) {
|
||||
// Phong lighting
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 V = normalize(input.ViewVec);
|
||||
float3 R = reflect(-L, N);
|
||||
float3 diffuse = max(dot(N, L), 0.0025);
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * 0.75;
|
||||
// Sample from texture
|
||||
float3 color = textures[NonUniformResourceIndex(input.InstanceIndex)].Sample(input.UV).rgb * input.Factor;
|
||||
return float4(diffuse * color.rgb + specular, 1.0);
|
||||
}
|
||||
// Phong lighting
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 V = normalize(input.ViewVec);
|
||||
float3 R = reflect(-L, N);
|
||||
float3 diffuse = max(dot(N, L), 0.0025);
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * 0.75;
|
||||
// Sample from texture
|
||||
float3 color = textures[NonUniformResourceIndex(input.InstanceIndex)].Sample(input.UV).rgb * input.Factor;
|
||||
return float4(diffuse * color.rgb + specular, 1.0);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ build_ktx () {
|
||||
-D CMAKE_INSTALL_PREFIX=$(realpath vendor) \
|
||||
-D CMAKE_CXX_STANDARD=17 \
|
||||
-D CMAKE_BUILD_TYPE=Release \
|
||||
-D CMAKE_CXX_FLAGS="-msse4.1"
|
||||
-D CMAKE_CXX_FLAGS="-msse4.1" \
|
||||
-G Ninja
|
||||
cmake --build ktx/build --config Release
|
||||
cmake --install ktx/build
|
||||
}
|
||||
@@ -17,7 +18,7 @@ build_ktx () {
|
||||
build_app () {
|
||||
bear -- clang++ -g -c -Wno-nullability-completeness -DVK_NO_PROTOTYPES -I$VULKAN_SDK/include -Ivendor/include vulkan_profiles/vulkan_profiles.cpp main.cpp
|
||||
bear -a -- clang -g -c -DVK_NO_PROTOTYPES -Ivulkan_profiles -I$VULKAN_SDK/include $VULKAN_SDK/include/volk/volk.c wapp/wapp.c
|
||||
bear -a -- clang++ -g -DVK_NO_PROTOTYPES -Lvendor/lib -lSDL3 -lglm -ltinyobjloader -lktx -o main *.o
|
||||
bear -a -- clang++ -g -DVK_NO_PROTOTYPES -L$VULKAN_SDK/lib -Lvendor/lib -lSDL3 -lglm -ltinyobjloader -lktx -lslang -Wl,-rpath,./vendor/lib -Wl,-rpath,$VULKAN_SDK/lib -o main *.o
|
||||
}
|
||||
|
||||
clean_obj () {
|
||||
|
||||
Reference in New Issue
Block a user