Skip to content

Commit 8e86d67

Browse files
authored
Merge branch 'PanosK92:master' into linux
2 parents 08aa224 + e52efde commit 8e86d67

47 files changed

Lines changed: 1190 additions & 451 deletions

Some content is hidden

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

data/shaders/common_resources.hlsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ struct FrameBufferData
7878
float cloud_shadows;
7979
float padding3;
8080
float padding4;
81+
82+
// vr stereo - right eye matrices (left eye uses the primary matrices above)
83+
matrix view_right;
84+
matrix projection_right;
85+
matrix view_projection_right;
86+
matrix view_projection_inverted_right;
87+
matrix view_projection_previous_right;
88+
uint is_multiview;
89+
uint padding_mv0;
90+
uint padding_mv1;
91+
uint padding_mv2;
8192
};
8293

8394
// push constant buffer - carries per-draw and per-pass data

data/shaders/common_structs.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ struct Light
392392
return tex2.SampleLevel(samplers[sampler_bilinear_clamp_border], atlas_uv, 0).r;
393393
}
394394

395+
// computes the roughness widening for area lights so that the specular
396+
// highlight spreads to match the light's angular extent instead of
397+
// collapsing into a point-like peak (Karis 2013)
398+
float compute_area_roughness_modification(float roughness_alpha, float distance)
399+
{
400+
float area_size = max(area_width, area_height) * 0.5f;
401+
float solid_angle = saturate(area_size / (2.0f * max(distance, 0.01f)));
402+
return saturate(roughness_alpha + solid_angle / (2.0f * roughness_alpha + solid_angle));
403+
}
404+
395405
void Build(uint index, Surface surface)
396406
{
397407
LightParameters light = light_parameters[index];

data/shaders/common_tessellation.hlsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ gbuffer_vertex main_ds(HsConstantDataOutput input, float3 bary_coords : SV_Domai
110110
vertex.uv_misc.xy = barycentric(patch[0].uv_misc.xy, patch[1].uv_misc.xy, patch[2].uv_misc.xy, bary_coords);
111111
vertex.uv_misc.z = barycentric(patch[0].uv_misc.z, patch[1].uv_misc.z, patch[2].uv_misc.z, bary_coords);
112112
vertex.uv_misc.w = patch[0].uv_misc.w; // instance_id is constant per patch
113+
vertex.view_id = patch[0].view_id; // view_id is constant per patch
113114

114115
// reconstruct world positions from interpolated clip
115116
float clip_w = vertex.position.w;
@@ -150,9 +151,11 @@ gbuffer_vertex main_ds(HsConstantDataOutput input, float3 bary_coords : SV_Domai
150151
}
151152
}
152153

153-
// write final clip space
154-
vertex.position = mul(float4(position, 1.0f), buffer_frame.view_projection);
155-
vertex.position_previous = mul(float4(position_previous, 1.0f), buffer_frame.view_projection_previous);
154+
// write final clip space (select per-eye matrices for multiview stereo)
155+
matrix vp = (buffer_frame.is_multiview && vertex.view_id == 1) ? buffer_frame.view_projection_right : buffer_frame.view_projection;
156+
matrix vp_prev = (buffer_frame.is_multiview && vertex.view_id == 1) ? buffer_frame.view_projection_previous_right : buffer_frame.view_projection_previous;
157+
vertex.position = mul(float4(position, 1.0f), vp);
158+
vertex.position_previous = mul(float4(position_previous, 1.0f), vp_prev);
156159

157160
return vertex;
158161
}

data/shaders/common_vertex_processing.hlsl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct gbuffer_vertex
7070
float4 uv_misc : TEXCOORD; // xy = uv, z = height_percent, w = instance_id - packed together to reduced the interpolators (shader registers) the gpu needs to track
7171
float width_percent : TEXCOORD2; // temp, will remove
7272
nointerpolation uint material_index : TEXCOORD3; // for indirect draws, material index passed from vs
73+
nointerpolation uint view_id : TEXCOORD4; // multiview eye index (0 = left, 1 = right)
7374
};
7475

7576
float4x4 compose_instance_transform(min16float instance_position_x, min16float instance_position_y, min16float instance_position_z, uint instance_normal_oct, uint instance_yaw, uint instance_scale)
@@ -396,10 +397,16 @@ gbuffer_vertex transform_to_world_space(Vertex_PosUvNorTan input, uint instance_
396397
return vertex;
397398
}
398399

399-
gbuffer_vertex transform_to_clip_space(gbuffer_vertex vertex, float3 position, float3 position_previous)
400+
gbuffer_vertex transform_to_clip_space(gbuffer_vertex vertex, float3 position, float3 position_previous, uint view_id = 0)
400401
{
401-
vertex.position = mul(float4(position, 1.0f), buffer_frame.view_projection);
402-
vertex.position_previous = mul(float4(position_previous, 1.0f), buffer_frame.view_projection_previous);
402+
vertex.view_id = view_id;
403+
404+
// select per-eye matrices when rendering in multiview stereo
405+
matrix vp = (buffer_frame.is_multiview && view_id == 1) ? buffer_frame.view_projection_right : buffer_frame.view_projection;
406+
matrix vp_prev = (buffer_frame.is_multiview && view_id == 1) ? buffer_frame.view_projection_previous_right : buffer_frame.view_projection_previous;
407+
408+
vertex.position = mul(float4(position, 1.0f), vp);
409+
vertex.position_previous = mul(float4(position_previous, 1.0f), vp_prev);
403410

404411
return vertex;
405412
}

data/shaders/depth_light.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceI
4545
float3 position_world_previous = 0.0f;
4646
gbuffer_vertex vertex = transform_to_world_space(input, instance_id, _draw.transform, position_world, position_world_previous);
4747
vertex.material_index = _draw.material_index;
48+
vertex.view_id = 0;
4849
vertex.position = mul(float4(position_world, 1.0f), light.transform[index_array]);
4950

5051
return vertex;

data/shaders/depth_prepass.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525
//=================================
2626

2727
#ifdef INDIRECT_DRAW
28-
gbuffer_vertex main_vs(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID, [[vk::builtin("DrawIndex")]] uint draw_id : DRAW_INDEX)
28+
gbuffer_vertex main_vs(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID, [[vk::builtin("DrawIndex")]] uint draw_id : DRAW_INDEX, uint view_id : SV_ViewID)
2929
{
3030
_draw = indirect_draw_data_out[draw_id];
3131
Vertex_PosUvNorTan input = pull_vertex(vertex_id);
3232
#else
33-
gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID)
33+
gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID, uint view_id : SV_ViewID)
3434
{
3535
_draw = draw_data[buffer_pass.draw_index];
3636
#endif
@@ -39,7 +39,7 @@ gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceI
3939
float3 position_world_previous = 0.0f;
4040
gbuffer_vertex vertex = transform_to_world_space(input, instance_id, _draw.transform, position_world, position_world_previous);
4141
vertex.material_index = _draw.material_index;
42-
return transform_to_clip_space(vertex, position_world, position_world_previous);
42+
return transform_to_clip_space(vertex, position_world, position_world_previous, view_id);
4343
}
4444

4545
void main_ps(gbuffer_vertex vertex)

data/shaders/g_buffer.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ float3 compute_flower_color(float height_percent, uint instance_id)
112112
}
113113

114114
#ifdef INDIRECT_DRAW
115-
gbuffer_vertex main_vs(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID, [[vk::builtin("DrawIndex")]] uint draw_id : DRAW_INDEX)
115+
gbuffer_vertex main_vs(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID, [[vk::builtin("DrawIndex")]] uint draw_id : DRAW_INDEX, uint view_id : SV_ViewID)
116116
{
117117
_draw = indirect_draw_data_out[draw_id];
118118
Vertex_PosUvNorTan input = pull_vertex(vertex_id);
119119
#else
120-
gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID)
120+
gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID, uint view_id : SV_ViewID)
121121
{
122122
_draw = draw_data[buffer_pass.draw_index];
123123
#endif
@@ -126,7 +126,7 @@ gbuffer_vertex main_vs(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceI
126126
float3 position_world_previous = 0.0f;
127127
gbuffer_vertex vertex = transform_to_world_space(input, instance_id, _draw.transform, position_world, position_world_previous);
128128
vertex.material_index = _draw.material_index;
129-
return transform_to_clip_space(vertex, position_world, position_world_previous);
129+
return transform_to_clip_space(vertex, position_world, position_world_previous, view_id);
130130
}
131131

132132
gbuffer main_ps(gbuffer_vertex vertex, bool is_front_face : SV_IsFrontFace)

data/shaders/light.hlsl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ void main_cs(uint3 thread_id : SV_DispatchThreadID)
200200
AngularInfo angular_info;
201201
angular_info.Build(light, surface);
202202

203+
// for area lights, widen the specular distribution to match the light's angular
204+
// extent - this prevents the highlight from collapsing into a concentrated point
205+
float original_roughness = surface.roughness;
206+
float original_roughness_alpha = surface.roughness_alpha;
207+
if (light.is_area())
208+
{
209+
surface.roughness_alpha = light.compute_area_roughness_modification(surface.roughness_alpha, light.distance_to_pixel);
210+
surface.roughness = sqrt(surface.roughness_alpha);
211+
}
212+
203213
// compute specular brdf lobes
204214
{
205215
// main specular lobe (anisotropic or isotropic)
@@ -230,6 +240,10 @@ void main_cs(uint3 thread_id : SV_DispatchThreadID)
230240
L_subsurface += subsurface_scattering(surface, light, angular_info);
231241
}
232242
}
243+
244+
// restore original roughness so other lights aren't affected
245+
surface.roughness = original_roughness;
246+
surface.roughness_alpha = original_roughness_alpha;
233247

234248
// compute diffuse brdf term
235249
L_diffuse_term += BRDF_Diffuse(surface, angular_info);

0 commit comments

Comments
 (0)