Skip to content

Commit 87a90f4

Browse files
authored
Merge pull request #62 from Williscool13/render-context
Render Context
2 parents 5e31d6c + a6ea288 commit 87a90f4

88 files changed

Lines changed: 2026 additions & 1334 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ set(TEMP_SOURCES
309309
src/engine/renderer/assets/render_object/render_object_fwd.h
310310
src/engine/core/events/event_dispatcher.cpp
311311
src/engine/core/events/event_dispatcher.h
312+
src/engine/renderer/render_context.cpp
313+
src/engine/renderer/render_context.h
314+
src/engine/renderer/resources/render_target.cpp
315+
src/engine/renderer/resources/render_target.h
312316
)
313317

314318
add_executable(WillEngine main.cpp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"renderObject": {
3+
"id": 6331695,
4+
"name": "AlphaBlendModeTest",
5+
"sourcePath": "assets\\models\\AlphaBlendModeTest.glb"
6+
},
7+
"version": {
8+
"major": 0,
9+
"minor": 1,
10+
"patch": 0
11+
}
12+
}

assets/models/mySphere.willmodel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"renderObject": {
3+
"id": 3725271840,
4+
"name": "mySphere",
5+
"sourcePath": "assets\\models\\mySphere.glb"
6+
},
7+
"version": {
8+
"major": 0,
9+
"minor": 1,
10+
"patch": 0
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"renderObject": {
3+
"id": 3129368917,
4+
"name": "primitives",
5+
"sourcePath": "assets\\models\\primitives\\primitives.gltf"
6+
},
7+
"version": {
8+
"major": 0,
9+
"minor": 1,
10+
"patch": 0
11+
}
12+
}

assets/settings.willengine

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
},
1010
"cameraSettings": {
1111
"position": [
12-
-0.12309487164020538,
13-
9.832075119018555,
14-
-0.149642214179039
12+
23.16223907470703,
13+
24.40260124206543,
14+
-1.7917613983154297
1515
],
1616
"rotation": [
17-
-0.4356941878795624,
18-
-0.5376664400100708,
19-
-0.3827509880065918,
20-
0.6120350956916809
17+
0.19685576856136322,
18+
-0.782544732093811,
19+
-0.30430784821510315,
20+
-0.5062295794487
2121
],
2222
"fov": 1.3089969158172607,
2323
"aspectRatio": 1.7777777910232544,
@@ -27,14 +27,14 @@
2727
"lightSettings": {
2828
"mainLight": {
2929
"direction": [
30-
0.3107273280620575,
31-
-0.9343101978302002,
32-
-0.17467966675758362
30+
-0.6146882772445679,
31+
-0.7376258969306946,
32+
-0.2794037461280823
3333
],
3434
"color": [
35-
1.0,
36-
1.0,
37-
1.0
35+
0.5773502588272095,
36+
0.5773502588272095,
37+
0.5773502588272095
3838
],
3939
"intensity": 1.5
4040
}

shaders/deferredMrt.frag

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,43 @@ layout (location = 3) out vec2 velocityTarget;
2727

2828
layout (set = 1, binding = 0) uniform Addresses
2929
{
30-
MaterialData materialBufferDeviceAddress;
31-
ModelData modelBufferDeviceAddress;
30+
Instances instances;
31+
Models models;
32+
PrimitiveData primitives;
33+
Materials materials;
34+
3235
} bufferAddresses;
3336

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

3740
void main() {
38-
Material m = bufferAddresses.materialBufferDeviceAddress.materials[inMaterialIndex];
41+
Material material = bufferAddresses.materials.materialArray[inMaterialIndex];
3942
vec4 albedo = vec4(1.0f);
4043

41-
int colorSamplerIndex = m.textureSamplerIndices.x;
42-
int colorImageIndex = m.textureImageIndices.x;
44+
int colorSamplerIndex = material.textureSamplerIndices.x;
45+
int colorImageIndex = material.textureImageIndices.x;
4346
if (colorSamplerIndex > -1 && colorImageIndex > -1) {
44-
vec2 colorUv = inUV * m.colorUvTransform.xy + m.colorUvTransform.zw;
47+
vec2 colorUv = inUV * material.colorUvTransform.xy + material.colorUvTransform.zw;
4548
albedo = texture(sampler2D(textures[nonuniformEXT(colorImageIndex)], samplers[nonuniformEXT(colorSamplerIndex)]), colorUv);
4649
}
47-
//albedo = albedo * inColor * m.colorFactor;
48-
49-
// Look into custom shaders specifically for these? More draw commands vs branching...
50-
// 1 is transparent blend type
51-
if (m.alphaProperties.y == 1) {
52-
// Draw only if alpha is close enough to 1
53-
if (albedo.w <= 1.0 - TRANSPARENT_ALPHA_EPSILON) {
54-
discard;
55-
}
56-
}
50+
albedo = albedo * inColor * material.colorFactor;
5751

5852
// 2 is "mask" (cutout) blend type
59-
if (m.alphaProperties.y == 2){
60-
// 2 is "mask" blend type
61-
if (albedo.w < m.alphaProperties.x){
53+
if (material.alphaProperties.y == 2){
54+
// x is the cutout value (if any)
55+
if (albedo.w < material.alphaProperties.x){
6256
discard;
6357
}
6458
}
6559

66-
int metalSamplerIndex = int(m.textureSamplerIndices.y);
67-
int metalImageIndex = int(m.textureImageIndices.y);
60+
int metalSamplerIndex = int(material.textureSamplerIndices.y);
61+
int metalImageIndex = int(material.textureImageIndices.y);
6862

69-
float metallic = m.metalRoughFactors.x;
70-
float roughness = m.metalRoughFactors.y;
63+
float metallic = material.metalRoughFactors.x;
64+
float roughness = material.metalRoughFactors.y;
7165
if (metalSamplerIndex > -1 && metalImageIndex > -1) {
72-
vec2 metalRoughUv = inUV * m.metalRoughUvTransform.xy + m.metalRoughUvTransform.zw;
66+
vec2 metalRoughUv = inUV * material.metalRoughUvTransform.xy + material.metalRoughUvTransform.zw;
7367
vec4 metalRoughSample = texture(sampler2D(textures[nonuniformEXT(metalImageIndex)], samplers[nonuniformEXT(metalSamplerIndex)]), metalRoughUv);
7468
metallic *= metalRoughSample.b;
7569
roughness *= metalRoughSample.g;

shaders/deferredMrt.vert

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
layout (set = 1, binding = 0) uniform Addresses
1111
{
12-
MaterialData materialBufferDeviceAddress;
13-
PrimitiveData primitiveBufferDeviceAddress;
14-
ModelData modelBufferDeviceAddress;
12+
Instances instances;
13+
Models models;
14+
PrimitiveData primitives;
15+
Materials materials;
1516
} bufferAddresses;
1617

1718

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

3233
void main() {
33-
Primitive primitive = bufferAddresses.primitiveBufferDeviceAddress.primitives[gl_InstanceIndex];
34-
uint modelIndex = primitive.modelIndex;
35-
uint materialIndex = primitive.materialIndex;
36-
Model models = bufferAddresses.modelBufferDeviceAddress.models[modelIndex];
34+
Instance instances = bufferAddresses.instances.instanceArray[gl_InstanceIndex];
3735

38-
vec4 viewPos = sceneData.view * models.currentModelMatrix * vec4(position, 1.0);
36+
Primitive primitive = bufferAddresses.primitives.primitiveArray[instances.primitiveDataIndex];
37+
Model model = bufferAddresses.models.modelArray[instances.modelIndex];
38+
39+
Material material = bufferAddresses.materials.materialArray[primitive.materialIndex];
40+
41+
42+
vec4 viewPos = sceneData.view * model.currentModelMatrix * vec4(position, 1.0);
3943

4044
outViewPosition = viewPos.xyz;
41-
outViewNormal = mat3(sceneData.view) * adjugate(models.currentModelMatrix) * normal;
45+
outViewNormal = mat3(sceneData.view) * adjugate(model.currentModelMatrix) * normal;
4246
outColor = color;
4347
outUV = uv;
44-
outMaterialIndex = materialIndex;
48+
outMaterialIndex = primitive.materialIndex;
4549
outHasTransparent = primitive.bHasTransparent;
4650

4751
vec4 currClipPos = sceneData.proj * viewPos;
48-
vec4 prevClipPos = sceneData.prevViewProj * models.previousModelMatrix * vec4(position, 1.0);
52+
vec4 prevClipPos = sceneData.prevViewProj * model.previousModelMatrix * vec4(position, 1.0);
4953
currClipPos.xy += currClipPos.w * sceneData.jitter.xy;
5054
prevClipPos.xy += prevClipPos.w * sceneData.jitter.zw;
5155
outCurrMvpPosition = currClipPos;

shaders/environment/environment.frag

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,28 @@ layout (location = 3) out vec2 velocityTarget;// 16 X, 16 Y
1616

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

19+
layout (push_constant) uniform PushConstants {
20+
float sunSize;
21+
float sunFalloff;
22+
} push;
23+
24+
1925
void main()
2026
{
2127
vec3 direction = normalize(uv);
2228
direction.y = -direction.y;
2329
vec3 envColor = textureLod(environmentMap, direction, 0).rgb;
2430

31+
vec3 sunDir = -sceneData.directionalLightData.direction;
32+
float sunDot = dot(normalize(uv), sunDir);
33+
34+
if (sunDot > push.sunSize) {
35+
float sunIntensity = smoothstep(push.sunSize, push.sunFalloff, sunDot);
36+
vec3 sunColor = sceneData.directionalLightData.color * sceneData.directionalLightData.intensity;
37+
envColor = mix(envColor, sunColor * 10.0, sunIntensity);
38+
}
39+
40+
2541
// 0 = "do not calculate lighting" flag
2642
albedoTarget = vec4(envColor, 0.0);
2743

shaders/include/lights.glsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef LIGHTS_GLSL
2+
#define LIGHTS_GLSL
3+
14
struct DirectionalLight {
25
vec3 direction;
36
float intensity;
@@ -11,4 +14,6 @@ struct PointLight {
1114
float radius;
1215
int shadowMapIndex;
1316
vec3 pad;
14-
};
17+
};
18+
19+
#endif // LIGHTS_GLSL

shaders/include/scene.glsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "lights.glsl"
2+
13
layout (std140, set = 0, binding = 0) uniform SceneData {
24
mat4 view;
35
mat4 proj;
@@ -24,8 +26,10 @@ layout (std140, set = 0, binding = 0) uniform SceneData {
2426

2527
vec4 jitter;
2628

29+
DirectionalLight directionalLightData;
30+
2731
vec2 renderTargetSize;
28-
// equal to 1 / renderTargetSize
32+
2933
vec2 texelSize;
3034
vec2 cameraPlanes;
3135
float deltaTime;

0 commit comments

Comments
 (0)