vk: brush: support normalmaps for water surfaces

Adds missing tangents.

Fixes #655
This commit is contained in:
Ivan Avdeev 2023-11-17 11:06:09 -05:00
parent de80c0da64
commit f0b80887e8
5 changed files with 29 additions and 6 deletions

View File

@ -1,3 +1,8 @@
# 2023-11-17 E332
- [-] backside emissive water polygons:
- adding them makes things worse in other parts of the level
- [x] water normalmap support -- added missing tangents
# 2023-11-16 E331
- [x] Emissive waters
- [x] add emissive water surface to polygon lights

View File

@ -106,7 +106,6 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
payload.base_color_a *= color;
payload.emissive.rgb *= color.rgb;
if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DISABLED) {
// Nop
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_SURFHASH) {

View File

@ -322,8 +322,12 @@ static void brushComputeWaterPolys( compute_water_polys_t args ) {
poly_vertices[i].normal[1] = 0;
poly_vertices[i].normal[2] = 0;
poly_vertices[i].tangent[0] = 0;
poly_vertices[i].tangent[1] = 0;
poly_vertices[i].tangent[2] = 0;
if (i > 1) {
vec3_t e0, e1, normal;
vec3_t e0, e1, normal, tangent;
VectorSubtract( poly_vertices[i - 1].pos, poly_vertices[0].pos, e0 );
VectorSubtract( poly_vertices[i].pos, poly_vertices[0].pos, e1 );
CrossProduct( e1, e0, normal );
@ -332,6 +336,13 @@ static void brushComputeWaterPolys( compute_water_polys_t args ) {
VectorAdd(normal, poly_vertices[i].normal, poly_vertices[i].normal);
VectorAdd(normal, poly_vertices[i - 1].normal, poly_vertices[i - 1].normal);
computeTangentE(tangent, e0, e1,
poly_vertices[0].gl_tc, poly_vertices[i-1].gl_tc, poly_vertices[i].gl_tc);
VectorAdd(tangent, poly_vertices[0].tangent, poly_vertices[0].tangent);
VectorAdd(tangent, poly_vertices[i].tangent, poly_vertices[i].tangent);
VectorAdd(tangent, poly_vertices[i - 1].tangent, poly_vertices[i - 1].tangent);
args.dst_indices[indices++] = (uint16_t)(vertices);
args.dst_indices[indices++] = (uint16_t)(vertices + i - 1);
args.dst_indices[indices++] = (uint16_t)(vertices + i);
@ -345,6 +356,7 @@ static void brushComputeWaterPolys( compute_water_polys_t args ) {
for( int i = 0; i < p->numverts; i++ ) {
VectorNormalize(poly_vertices[i].normal);
VectorNormalize(poly_vertices[i].tangent);
#if 0
//const float dot = DotProduct(poly_vertices[i].normal, args.warp->plane->normal);
//if (dot < 0.) {

View File

@ -267,12 +267,9 @@ void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z )
Matrix4x4_Concat( out, base, temp );
}
void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const vec3_t v2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2) {
vec3_t e1, e2;
void computeTangentE(vec3_t out_tangent, const vec3_t e1, const vec3_t e2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2) {
vec2_t duv1, duv2;
VectorSubtract(v1, v0, e1);
VectorSubtract(v2, v0, e2);
Vector2Subtract(uv1, uv0, duv1);
Vector2Subtract(uv2, uv0, duv2);
@ -287,6 +284,15 @@ void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const
out_tangent[2] = f * (duv2[1] * e1[2] - duv1[1] * e2[2]);
}
void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const vec3_t v2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2) {
vec3_t e1, e2;
VectorSubtract(v1, v0, e1);
VectorSubtract(v2, v0, e2);
computeTangentE(out_tangent, e1, e2, uv0, uv1, uv2);
}
void Matrix4x4_CreateFromVectors(matrix4x4 out, const vec3_t right, const vec3_t up, const vec3_t z, const vec3_t translate) {
out[0][0] = right[0];
out[1][0] = right[1];

View File

@ -21,6 +21,7 @@ void Matrix4x4_CreateProjection(matrix4x4 out, float xMax, float xMin, float yMa
void Matrix4x4_CreateOrtho(matrix4x4 m, float xLeft, float xRight, float yBottom, float yTop, float zNear, float zFar);
void Matrix4x4_CreateModelview( matrix4x4 out );
void computeTangentE(vec3_t out_tangent, const vec3_t e1, const vec3_t e2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2);
void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const vec3_t v2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2);
void Matrix4x4_CreateFromVectors(matrix4x4 out, const vec3_t right, const vec3_t up, const vec3_t z, const vec3_t translate);