Skip to content
This repository was archived by the owner on Jun 7, 2025. It is now read-only.

Commit 6de5421

Browse files
authored
Merge pull request #245 from BVE-Reborn/backport-texture-fixes
2 parents c6b40d8 + 0446502 commit 6de5421

18 files changed

+20
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Per Keep a Changelog there are 6 main categories of changes:
2929

3030
## Unreleased
3131

32+
### Fixed
33+
- rend3: Fixed bug where in gpu mode, changing textures would cause a brief flash.
34+
- rend3-pbr: Fixed normal mapping.
35+
- rend3-pbr: Fixed some UV transforms.
36+
3237
## v0.2.1
3338

3439
Released 2021-10-24
260 Bytes
Binary file not shown.
272 Bytes
Binary file not shown.
44 Bytes
Binary file not shown.
44 Bytes
Binary file not shown.
-1.19 KB
Binary file not shown.
-1.88 KB
Binary file not shown.
-188 Bytes
Binary file not shown.
-200 Bytes
Binary file not shown.
316 Bytes
Binary file not shown.
516 Bytes
Binary file not shown.
-1.35 KB
Binary file not shown.
-2.04 KB
Binary file not shown.

rend3-pbr/shaders/src/depth.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "structures.glsl"
99

1010
layout(location = 0) in vec4 i_position;
11-
layout(location = 1) in vec2 i_coords;
11+
layout(location = 1) in vec2 i_coords0;
1212
layout(location = 2) in vec4 i_color;
1313
layout(location = 3) flat in uint i_material;
1414

@@ -44,7 +44,7 @@ void main() {
4444

4545
bool has_albedo = HAS_ALBEDO_TEXTURE;
4646

47-
vec2 coords = i_coords;
47+
vec2 coords = vec2(material.uv_transform0 * vec3(i_coords0, 1.0));
4848
vec2 uvdx = dFdx(coords);
4949
vec2 uvdy = dFdy(coords);
5050

rend3-pbr/shaders/src/depth.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ layout(location = 7) in uint i_object_idx;
1515
#endif
1616

1717
layout(location = 0) out vec4 o_position;
18-
layout(location = 1) out vec2 o_coords;
18+
layout(location = 1) out vec2 o_coords0;
1919
layout(location = 2) out vec4 o_color;
2020
layout(location = 3) flat out uint o_material;
2121

@@ -54,5 +54,5 @@ void main() {
5454

5555
o_color = i_color;
5656

57-
o_coords = vec2(material.uv_transform0 * vec3(i_coords0, 1.0));
57+
o_coords0 = i_coords0;
5858
}

rend3-pbr/shaders/src/lighting/pixel.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct PixelData {
4242
PixelData get_per_pixel_data_sampled(MATERIAL_TYPE material, sampler s) {
4343
PixelData pixel;
4444

45-
vec2 coords = i_coords0;
45+
vec2 coords = vec2(material.uv_transform0 * vec3(i_coords0, 1.0));
4646
vec2 uvdx = dFdx(coords);
4747
vec2 uvdy = dFdy(coords);
4848

@@ -82,7 +82,7 @@ PixelData get_per_pixel_data_sampled(MATERIAL_TYPE material, sampler s) {
8282

8383
normal = vec3(bicomp, sqrt(1 - (bicomp.r * bicomp.r) - (bicomp.g * bicomp.g)));
8484
} else {
85-
normal = normalize(texture_read.rgb);
85+
normal = normalize(texture_read.rgb * 2.0 - 1.0);
8686
}
8787
vec3 in_normal = normalize(i_normal);
8888
vec3 in_tangent = normalize(i_tangent);

rend3-pbr/shaders/src/opaque.vert

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ void main() {
6363

6464
o_color = i_color;
6565

66-
o_coords0 = vec2(material.uv_transform0 * vec3(i_coords0, 1.0));
67-
o_coords1 = vec2(material.uv_transform1 * vec3(i_coords1, 1.0));
66+
o_coords0 = i_coords0;
67+
o_coords1 = i_coords1;
6868

6969
#ifdef BAKING
70-
gl_Position = vec4(o_coords1 * 2.0 - 1.0, 0.0, 1.0);
70+
vec2 coord1_adj = vec2(material.uv_transform1 * vec3(i_coords1, 1.0));
71+
gl_Position = vec4(coord1_adj * 2.0 - 1.0, 0.0, 1.0);
7172
#else
7273
gl_Position = data.model_view_proj * vec4(i_position, 1.0);
7374
#endif

rend3/src/renderer/render.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ pub fn render_loop<Input, Output>(
100100
}
101101

102102
// Do these in dependency order
103-
// Level 2
103+
// Level 3
104104
object_manager.ready(&mut material_manager);
105105

106+
// Level 2
107+
let d2_texture = texture_manager_2d.ready(&renderer.device);
108+
106109
// Level 1
110+
// The material manager needs to be able to pull correct internal indices from the d2 texture manager, so it has to go first.
107111
material_manager.ready(
108112
&renderer.device,
109113
&renderer.queue,
@@ -112,7 +116,6 @@ pub fn render_loop<Input, Output>(
112116
);
113117

114118
// Level 0
115-
let d2_texture = texture_manager_2d.ready(&renderer.device);
116119
let d2c_texture = texture_manager_cube.ready(&renderer.device);
117120
let directional_light_cameras = directional_light_manager.ready(&renderer.device, &renderer.queue, &camera_manager);
118121
mesh_manager.ready();

0 commit comments

Comments
 (0)