Fixes up shaders
This commit is contained in:
@@ -22,7 +22,7 @@ Vertex vertexMain( uint index : SV_VertexID )
|
||||
|
||||
struct CompositeFragment {
|
||||
vec4 color;
|
||||
}
|
||||
};
|
||||
|
||||
struct GBufferInput {
|
||||
SubpassInput<vec4> color : COLOR;
|
||||
@@ -48,7 +48,9 @@ ParameterBlock< CameraData > camera : CAMERA;
|
||||
|
||||
//TODO: constant flags
|
||||
|
||||
vec3 sun_dir = normalize(vec3(-1.0, -1.0, -1.0));
|
||||
// Direction the sun is facing
|
||||
vec3 sun_dir = -normalize( vec3( 0.0, 0.0, 1.0 ) );
|
||||
vec3 anti_sun_dir = -sun_dir;
|
||||
|
||||
// GGX/Towbridge-Reitz normal distribution function.
|
||||
// Uses Disney's reparametrization of alpha = roughness^2.
|
||||
@@ -81,17 +83,17 @@ vec3 schlick(vec3 F0, float cosTheta)
|
||||
return F0 + (vec3(1.0) - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
}
|
||||
|
||||
|
||||
[shader("fragment")]
|
||||
CompositeFragment fragmentMain( Vertex vertex )
|
||||
{
|
||||
CompositeFragment frag;
|
||||
|
||||
// const vec3 test_sample = test.SubpassLoad().xyz;
|
||||
// const vec3 albedo = gbuffer.color.SubpassLoad().xyz * test_sample;
|
||||
const vec3 albedo = gbuffer.color.SubpassLoad().xyz;
|
||||
|
||||
const vec3 position = gbuffer.position.SubpassLoad().xyz;
|
||||
const vec3 normal = gbuffer.normal.SubpassLoad().xyz;
|
||||
|
||||
// metallic, roughness, occlusion
|
||||
// r, g, b
|
||||
const vec3 metallic_comb = gbuffer.metallic.SubpassLoad().xyz;
|
||||
@@ -117,7 +119,7 @@ CompositeFragment fragmentMain( Vertex vertex )
|
||||
|
||||
vec3 direct_lighting = vec3( 0.0 );
|
||||
|
||||
vec3 Li = -sun_dir;
|
||||
vec3 Li = anti_sun_dir;
|
||||
vec3 Lradiance = vec3(1.0);
|
||||
|
||||
vec3 Lh = normalize( Li + Lo );
|
||||
|
||||
@@ -24,7 +24,7 @@ public struct Metallic
|
||||
{
|
||||
return texture_id != INVALID_TEXTURE_ID;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public struct Normal
|
||||
{
|
||||
@@ -35,7 +35,7 @@ public struct Normal
|
||||
{
|
||||
return texture_id != INVALID_TEXTURE_ID;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public struct Occlusion
|
||||
{
|
||||
@@ -46,7 +46,7 @@ public struct Occlusion
|
||||
{
|
||||
return texture_id != INVALID_TEXTURE_ID;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public struct Emissive
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public struct Emissive
|
||||
{
|
||||
return texture_id != INVALID_TEXTURE_ID;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public struct Material
|
||||
@@ -67,5 +67,5 @@ public struct Material
|
||||
public Normal normal;
|
||||
public Occlusion occlusion;
|
||||
public Emissive emissive;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,4 +14,8 @@ public struct CameraData
|
||||
return vec3( inverse_view[ 0 ][ 3 ], inverse_view[ 1 ][ 3 ], inverse_view[ 2 ][ 3 ] );
|
||||
}
|
||||
|
||||
}
|
||||
public mat4x4 mat()
|
||||
{
|
||||
return mul( projection, view );
|
||||
}
|
||||
};
|
||||
@@ -11,7 +11,9 @@ struct CoarseVertex {
|
||||
float4 position : SV_Position;
|
||||
float3 world_pos;
|
||||
uint material_id;
|
||||
}
|
||||
mat4x4 matrix;
|
||||
vec4 tangent;
|
||||
};
|
||||
|
||||
[ [ vk::binding( 0, 1 ) ] ]
|
||||
ConstantBuffer< CameraData > camera : CAMERA;
|
||||
@@ -21,17 +23,19 @@ CoarseVertex vertexMain( ModelVertex in_vertex )
|
||||
{
|
||||
CoarseVertex out_vertex;
|
||||
|
||||
vec4 world_pos = mul(in_vertex.model_matrix, vec4(in_vertex.simple.position, 1.0));
|
||||
vec4 world_pos = mul(in_vertex.instance.model_matrix, vec4(in_vertex.simple.position, 1.0));
|
||||
|
||||
const float4 transformed_pos = mul( mul( camera.projection, camera.view ), world_pos );
|
||||
const float4 transformed_pos = mul( camera.mat(), world_pos );
|
||||
out_vertex.position = transformed_pos;
|
||||
out_vertex.world_pos = world_pos.xyz;
|
||||
|
||||
mat3 normal_matrix = transpose( inverse( mat3( in_vertex.model_matrix ) ) );
|
||||
mat3 normal_matrix = transpose( inverse( mat3( in_vertex.instance.model_matrix ) ) );
|
||||
|
||||
out_vertex.normal = normalize( mul(normal_matrix, in_vertex.normal) );
|
||||
out_vertex.tex_coord = in_vertex.uv;
|
||||
out_vertex.material_id = in_vertex.material_id;
|
||||
out_vertex.material_id = in_vertex.instance.material_id;
|
||||
out_vertex.matrix = in_vertex.instance.model_matrix;
|
||||
out_vertex.tangent = in_vertex.tangent;
|
||||
|
||||
return out_vertex;
|
||||
}
|
||||
@@ -78,6 +82,8 @@ GBufferFragment fragmentMain( CoarseVertex vertex )
|
||||
frag.color = material.color.factors;
|
||||
}
|
||||
|
||||
if ( frag.color.w <= 0.0f ) discard;
|
||||
|
||||
float metallic_scalar = 0.0;
|
||||
float roughness_scalar = 0.0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user