Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
42596c9
Initial render context implementation (fixed resolution)
Williscool13 Jun 20, 2025
171d2e4
Initial render context implementation (fixed resolution)
Williscool13 Jun 20, 2025
e968ad0
Merge remote-tracking branch 'origin/render-context' into render-context
Williscool13 Jun 21, 2025
6cf79a6
Render context WIP2.
Williscool13 Jun 23, 2025
2ed5e11
Render context WIP3.
Williscool13 Jun 24, 2025
a7c1188
Dynamically resizeable window, recreates all intermediate and render …
Williscool13 Jun 25, 2025
d96aae7
Fix release build compile issue.
Williscool13 Jun 25, 2025
4b3ea8d
Minor filesystem update.
Williscool13 Jun 26, 2025
a1c629b
Visibility pass rework WIP1.
Williscool13 Jun 26, 2025
c97a659
Visibility pass rework WIP2.
Williscool13 Jun 27, 2025
00776fc
Fix rendering and alignment issues with bounding spheres in the visib…
Williscool13 Jun 27, 2025
28ecb32
Re-enable shadow pass with the new visibility pass.
Williscool13 Jun 27, 2025
6438c38
Fix gltf buffer view textures failing to load if not a ktx texture.
Williscool13 Jun 27, 2025
70a3897
Cache staging buffer to reduce buffer re-allocation in render objects.
Williscool13 Jun 28, 2025
face25c
Updated visibility debug with a new "freeze visibility scene data tog…
Williscool13 Jun 28, 2025
8d32cc3
Optimize frustum testing by unrolling loops and simplifying dot product.
Williscool13 Jun 28, 2025
40abcca
Fix debug highlighter not highlighting all renderables of a gameobject.
Williscool13 Jun 28, 2025
b7c062c
Improve object selection in editor-mode. Allow rigidbodies to specify…
Williscool13 Jun 28, 2025
0858fce
Minor improvements. Added sun programatically to the environment map.
Williscool13 Jun 30, 2025
a6ea288
some willmodel files.
Williscool13 Jul 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ set(TEMP_SOURCES
src/engine/renderer/assets/render_object/render_object_fwd.h
src/engine/core/events/event_dispatcher.cpp
src/engine/core/events/event_dispatcher.h
src/engine/renderer/render_context.cpp
src/engine/renderer/render_context.h
src/engine/renderer/resources/render_target.cpp
src/engine/renderer/resources/render_target.h
)

add_executable(WillEngine main.cpp
Expand Down
12 changes: 12 additions & 0 deletions assets/models/AlphaBlendModeTest.willmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"renderObject": {
"id": 6331695,
"name": "AlphaBlendModeTest",
"sourcePath": "assets\\models\\AlphaBlendModeTest.glb"
},
"version": {
"major": 0,
"minor": 1,
"patch": 0
}
}
12 changes: 12 additions & 0 deletions assets/models/mySphere.willmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"renderObject": {
"id": 3725271840,
"name": "mySphere",
"sourcePath": "assets\\models\\mySphere.glb"
},
"version": {
"major": 0,
"minor": 1,
"patch": 0
}
}
12 changes: 12 additions & 0 deletions assets/models/primitives/primitives.willmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"renderObject": {
"id": 3129368917,
"name": "primitives",
"sourcePath": "assets\\models\\primitives\\primitives.gltf"
},
"version": {
"major": 0,
"minor": 1,
"patch": 0
}
}
26 changes: 13 additions & 13 deletions assets/settings.willengine
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
},
"cameraSettings": {
"position": [
-0.12309487164020538,
9.832075119018555,
-0.149642214179039
23.16223907470703,
24.40260124206543,
-1.7917613983154297
],
"rotation": [
-0.4356941878795624,
-0.5376664400100708,
-0.3827509880065918,
0.6120350956916809
0.19685576856136322,
-0.782544732093811,
-0.30430784821510315,
-0.5062295794487
],
"fov": 1.3089969158172607,
"aspectRatio": 1.7777777910232544,
Expand All @@ -27,14 +27,14 @@
"lightSettings": {
"mainLight": {
"direction": [
0.3107273280620575,
-0.9343101978302002,
-0.17467966675758362
-0.6146882772445679,
-0.7376258969306946,
-0.2794037461280823
],
"color": [
1.0,
1.0,
1.0
0.5773502588272095,
0.5773502588272095,
0.5773502588272095
],
"intensity": 1.5
}
Expand Down
42 changes: 18 additions & 24 deletions shaders/deferredMrt.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,43 @@ layout (location = 3) out vec2 velocityTarget;

layout (set = 1, binding = 0) uniform Addresses
{
MaterialData materialBufferDeviceAddress;
ModelData modelBufferDeviceAddress;
Instances instances;
Models models;
PrimitiveData primitives;
Materials materials;

} bufferAddresses;

layout (set = 2, binding = 0) uniform sampler samplers[];
layout (set = 2, binding = 1) uniform texture2D textures[];

void main() {
Material m = bufferAddresses.materialBufferDeviceAddress.materials[inMaterialIndex];
Material material = bufferAddresses.materials.materialArray[inMaterialIndex];
vec4 albedo = vec4(1.0f);

int colorSamplerIndex = m.textureSamplerIndices.x;
int colorImageIndex = m.textureImageIndices.x;
int colorSamplerIndex = material.textureSamplerIndices.x;
int colorImageIndex = material.textureImageIndices.x;
if (colorSamplerIndex > -1 && colorImageIndex > -1) {
vec2 colorUv = inUV * m.colorUvTransform.xy + m.colorUvTransform.zw;
vec2 colorUv = inUV * material.colorUvTransform.xy + material.colorUvTransform.zw;
albedo = texture(sampler2D(textures[nonuniformEXT(colorImageIndex)], samplers[nonuniformEXT(colorSamplerIndex)]), colorUv);
}
//albedo = albedo * inColor * m.colorFactor;

// Look into custom shaders specifically for these? More draw commands vs branching...
// 1 is transparent blend type
if (m.alphaProperties.y == 1) {
// Draw only if alpha is close enough to 1
if (albedo.w <= 1.0 - TRANSPARENT_ALPHA_EPSILON) {
discard;
}
}
albedo = albedo * inColor * material.colorFactor;

// 2 is "mask" (cutout) blend type
if (m.alphaProperties.y == 2){
// 2 is "mask" blend type
if (albedo.w < m.alphaProperties.x){
if (material.alphaProperties.y == 2){
// x is the cutout value (if any)
if (albedo.w < material.alphaProperties.x){
discard;
}
}

int metalSamplerIndex = int(m.textureSamplerIndices.y);
int metalImageIndex = int(m.textureImageIndices.y);
int metalSamplerIndex = int(material.textureSamplerIndices.y);
int metalImageIndex = int(material.textureImageIndices.y);

float metallic = m.metalRoughFactors.x;
float roughness = m.metalRoughFactors.y;
float metallic = material.metalRoughFactors.x;
float roughness = material.metalRoughFactors.y;
if (metalSamplerIndex > -1 && metalImageIndex > -1) {
vec2 metalRoughUv = inUV * m.metalRoughUvTransform.xy + m.metalRoughUvTransform.zw;
vec2 metalRoughUv = inUV * material.metalRoughUvTransform.xy + material.metalRoughUvTransform.zw;
vec4 metalRoughSample = texture(sampler2D(textures[nonuniformEXT(metalImageIndex)], samplers[nonuniformEXT(metalSamplerIndex)]), metalRoughUv);
metallic *= metalRoughSample.b;
roughness *= metalRoughSample.g;
Expand Down
26 changes: 15 additions & 11 deletions shaders/deferredMrt.vert
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

layout (set = 1, binding = 0) uniform Addresses
{
MaterialData materialBufferDeviceAddress;
PrimitiveData primitiveBufferDeviceAddress;
ModelData modelBufferDeviceAddress;
Instances instances;
Models models;
PrimitiveData primitives;
Materials materials;
} bufferAddresses;


Expand All @@ -30,22 +31,25 @@ layout (location = 6) out vec4 outCurrMvpPosition;
layout (location = 7) out vec4 outPrevMvpPosition;

void main() {
Primitive primitive = bufferAddresses.primitiveBufferDeviceAddress.primitives[gl_InstanceIndex];
uint modelIndex = primitive.modelIndex;
uint materialIndex = primitive.materialIndex;
Model models = bufferAddresses.modelBufferDeviceAddress.models[modelIndex];
Instance instances = bufferAddresses.instances.instanceArray[gl_InstanceIndex];

vec4 viewPos = sceneData.view * models.currentModelMatrix * vec4(position, 1.0);
Primitive primitive = bufferAddresses.primitives.primitiveArray[instances.primitiveDataIndex];
Model model = bufferAddresses.models.modelArray[instances.modelIndex];

Material material = bufferAddresses.materials.materialArray[primitive.materialIndex];


vec4 viewPos = sceneData.view * model.currentModelMatrix * vec4(position, 1.0);

outViewPosition = viewPos.xyz;
outViewNormal = mat3(sceneData.view) * adjugate(models.currentModelMatrix) * normal;
outViewNormal = mat3(sceneData.view) * adjugate(model.currentModelMatrix) * normal;
outColor = color;
outUV = uv;
outMaterialIndex = materialIndex;
outMaterialIndex = primitive.materialIndex;
outHasTransparent = primitive.bHasTransparent;

vec4 currClipPos = sceneData.proj * viewPos;
vec4 prevClipPos = sceneData.prevViewProj * models.previousModelMatrix * vec4(position, 1.0);
vec4 prevClipPos = sceneData.prevViewProj * model.previousModelMatrix * vec4(position, 1.0);
currClipPos.xy += currClipPos.w * sceneData.jitter.xy;
prevClipPos.xy += prevClipPos.w * sceneData.jitter.zw;
outCurrMvpPosition = currClipPos;
Expand Down
16 changes: 16 additions & 0 deletions shaders/environment/environment.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ layout (location = 3) out vec2 velocityTarget;// 16 X, 16 Y

layout(set = 1, binding = 0) uniform samplerCube environmentMap;

layout (push_constant) uniform PushConstants {
float sunSize;
float sunFalloff;
} push;


void main()
{
vec3 direction = normalize(uv);
direction.y = -direction.y;
vec3 envColor = textureLod(environmentMap, direction, 0).rgb;

vec3 sunDir = -sceneData.directionalLightData.direction;
float sunDot = dot(normalize(uv), sunDir);

if (sunDot > push.sunSize) {
float sunIntensity = smoothstep(push.sunSize, push.sunFalloff, sunDot);
vec3 sunColor = sceneData.directionalLightData.color * sceneData.directionalLightData.intensity;
envColor = mix(envColor, sunColor * 10.0, sunIntensity);
}


// 0 = "do not calculate lighting" flag
albedoTarget = vec4(envColor, 0.0);

Expand Down
7 changes: 6 additions & 1 deletion shaders/include/lights.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef LIGHTS_GLSL
#define LIGHTS_GLSL

struct DirectionalLight {
vec3 direction;
float intensity;
Expand All @@ -11,4 +14,6 @@ struct PointLight {
float radius;
int shadowMapIndex;
vec3 pad;
};
};

#endif // LIGHTS_GLSL
6 changes: 5 additions & 1 deletion shaders/include/scene.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "lights.glsl"

layout (std140, set = 0, binding = 0) uniform SceneData {
mat4 view;
mat4 proj;
Expand All @@ -24,8 +26,10 @@ layout (std140, set = 0, binding = 0) uniform SceneData {

vec4 jitter;

DirectionalLight directionalLightData;

vec2 renderTargetSize;
// equal to 1 / renderTargetSize

vec2 texelSize;
vec2 cameraPlanes;
float deltaTime;
Expand Down
80 changes: 68 additions & 12 deletions shaders/include/structure.glsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#extension GL_EXT_buffer_reference : require


struct Primitive
struct Instance
{
uint materialIndex;
uint modelIndex;
uint boundingVolumeIndex;
uint bHasTransparent;
int modelIndex;
int primitiveDataIndex;
int bIsDrawn;
uint padding0;
uint padding1;
uint padding2;
uint padding3;
uint padding4;
};

struct Model
Expand All @@ -16,6 +19,26 @@ struct Model
vec4 flags; // x: enabled, xyz: reserved for future use
};

struct MeshBounds
{
float radius;
vec3 position;
};

struct Primitive
{
uint firstIndex;
uint indexCount;
int vertexOffset;
uint bHasTransparent;
uint materialIndex;
uint padding0;
uint padding1;
uint padding2;
vec4 boundingSphere;
};


struct Material
{
vec4 colorFactor;
Expand All @@ -40,17 +63,50 @@ struct Material
vec4 physicalProperties; // x: IOR, y: dispersion, z: normalScale, w: occlusionStrength
};

struct VkDrawIndexedIndirectCommand
{
uint indexCount;
uint instanceCount;
uint firstIndex;
int vertexOffset;
uint firstInstance;
};

struct IndirectCount
{
uint opaqueCount;
uint transparentCount;
uint shadowCount;
// The maximum number of primitives that are in the buffer. Equal to size of indirect buffer
uint limit;
};

layout (buffer_reference, std430) readonly buffer Instances
{
Instance instanceArray[];
};

layout (buffer_reference, std430) readonly buffer Models
{
Model modelArray[];
};

layout (buffer_reference, std430) readonly buffer PrimitiveData
{
Primitive primitives[];
Primitive primitiveArray[];
};

layout (buffer_reference, std430) readonly buffer ModelData
layout (buffer_reference, std430) readonly buffer Materials
{
Model models[];
Material materialArray[];
};

layout (buffer_reference, std430) readonly buffer MaterialData
layout(buffer_reference, std430) buffer CommandBuffer
{
Material materials[];
};
VkDrawIndexedIndirectCommand commandArray[];
};

layout(buffer_reference, std430) buffer DrawCounts
{
IndirectCount indirectCount;
};
4 changes: 1 addition & 3 deletions shaders/postProcess.comp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ layout (rgba16f, set = 1, binding = 1) uniform image2D outputImage;


layout (push_constant) uniform PushConstants {
int width;
int height;
uint flags;
} push;

Expand All @@ -39,7 +37,7 @@ vec3 sharpen(vec3 centerColor, vec2 texelSize, vec2 uv) {

void main() {
ivec2 pixel = ivec2(gl_GlobalInvocationID.xy);
if (pixel.x >= push.width || pixel.y >= push.height) {
if (pixel.x >= sceneData.renderTargetSize.x || pixel.y >= sceneData.renderTargetSize.y) {
return;
}

Expand Down
Loading