vk: add normal_scale to materials

This commit is contained in:
Ivan Avdeev 2023-04-12 10:26:37 -07:00 committed by Ivan Avdeev
parent 9116b0268e
commit 1fd9e49f63
5 changed files with 9 additions and 3 deletions

View File

@ -86,10 +86,9 @@ struct Kusok {
float roughness;
float metalness;
float normal_scale;
uint flags;
PAD(1)
mat4 prev_transform;
};

View File

@ -44,7 +44,9 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
T = normalize(T - dot(T, geom.normal_shading) * geom.normal_shading);
const vec3 B = normalize(cross(geom.normal_shading, T));
const mat3 TBN = mat3(T, B, geom.normal_shading);
const vec3 tnorm = sampleTexture(tex_normal, geom.uv, geom.uv_lods).xyz * 2. - 1.; // TODO is this sampling correct for normal data?
vec3 tnorm = sampleTexture(tex_normal, geom.uv, geom.uv_lods).xyz * 2. - 1.; // TODO is this sampling correct for normal data?
tnorm.xy *= kusok.normal_scale;
tnorm.z = sqrt(max(0., 1. - dot(tnorm.xy, tnorm.xy)));
geom.normal_shading = normalize(TBN * tnorm);
}
#endif

View File

@ -16,6 +16,7 @@ static xvk_material_t k_default_material = {
.metalness = 0.f,
.roughness = 1.f,
.normal_scale = 1.f,
.base_color = { 1.f, 1.f, 1.f, 1.f },
.set = false,
@ -157,6 +158,8 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
} else if (Q_stricmp(key, "metalness") == 0) {
sscanf(value, "%f", &current_material.metalness);
metalness_set = true;
} else if (Q_stricmp(key, "normal_scale") == 0) {
sscanf(value, "%f", &current_material.normal_scale);
} else if (Q_stricmp(key, "base_color") == 0) {
sscanf(value, "%f %f %f %f", &current_material.base_color[0], &current_material.base_color[1], &current_material.base_color[2], &current_material.base_color[3]);
} else {

View File

@ -11,6 +11,7 @@ typedef struct {
vec4_t base_color;
float roughness;
float metalness;
float normal_scale;
qboolean set;
} xvk_material_t;

View File

@ -172,6 +172,7 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
kusok->roughness = mat->roughness;
kusok->metalness = mat->metalness;
kusok->normal_scale = mat->normal_scale;
kusok->flags = 0;