Adds bump env settings.

This commit is contained in:
Erik Abair 2022-01-28 07:02:55 -08:00
parent 0c6940b005
commit 966fab94f0
4 changed files with 70 additions and 23 deletions

View File

@ -160,4 +160,7 @@
#define NV097_SET_POINT_PARAMS_ENABLE 0x318
#define NV097_SET_POINT_SMOOTH_ENABLE 0x31C
// NV_PGRAPH_TEXFILTER0_CONVOLUTION_KERNEL from xemu.
#define NV097_SET_TEXTURE_FILTER_CONVOLUTION_KERNEL 0x0000E000
#endif // NXDK_ZBUFFER_TESTS_NXDK_MISSING_DEFINES_H

View File

@ -62,10 +62,6 @@ void VolumeTextureTests::Initialize() {
host_.SetFinalCombiner0(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false,
false, TestHost::SRC_R0);
host_.SetFinalCombiner1(TestHost::SRC_ZERO, false, false, TestHost::SRC_ZERO, false, false, TestHost::SRC_R0, true);
auto p = pb_begin();
p = pb_push1(p, NV097_SET_TEXTURE_BORDER_COLOR, 0xFFFFFF);
pb_end(p);
}
void VolumeTextureTests::CreateGeometry() {
@ -241,21 +237,13 @@ static int GeneratePalettizedSurface(uint8_t **ret, uint32_t width, uint32_t hei
auto pixel = *ret;
for (auto d = 0; d < depth; ++d) {
uint32_t layer_size = width * height;
uint32_t half_size = layer_size >> 1;
for (uint32_t i = 0; i < half_size; ++i, ++pixel) {
*pixel = (d << 2) & (palette_size - 1);
}
for (uint32_t i = half_size; i < layer_size; i += 4) {
uint8_t value = (i + (d << 2)) & (palette_size - 1);
*pixel++ = value;
*pixel++ = value;
*pixel++ = value;
*pixel++ = value;
uint32_t block_size = palette_size / 4;
uint32_t offset = 0;
for (auto d = 0; d < depth; ++d, offset += block_size) {
for (auto y = 0; y < height; ++y) {
for (auto x = 0; x < width; ++x) {
*pixel++ = (y + offset) & (palette_size - 1);
}
}
}

View File

@ -66,15 +66,12 @@ void TextureStage::Commit(uint32_t memory_dma_offset, uint32_t palette_dma_offse
// NV097_SET_TEXTURE_IMAGE_RECT
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_TX_NPOT_SIZE(stage_), size_param);
// set stage 0 texture modes
// (0x0W0V0U wrapping: 1=wrap 2=mirror 3=clamp 4=border 5=clamp to edge)
// NV097_SET_TEXTURE_ADDRESS
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_TX_WRAP(stage_), 0x00030303);
// set stage 0 texture filters (AA!)
// NV097_SET_TEXTURE_FILTER
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_TX_FILTER(stage_), 0x1012000);
// Note: Using 0x04074000 breaks 3d textures (the resultant buffer is 0'd out).
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_TX_FILTER(stage_), texture_filter_);
p = pb_push4(p, NV097_SET_TEXTURE_MATRIX_ENABLE, 0, 0, 0, 0);
@ -90,9 +87,27 @@ void TextureStage::Commit(uint32_t memory_dma_offset, uint32_t palette_dma_offse
// NV097_SET_TEXTURE_PALETTE
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_TX_PALETTE_OFFSET(stage_), palette_config);
p = pb_push1(p, NV097_SET_TEXTURE_BORDER_COLOR, border_color_);
p = pb_push4f(p, NV097_SET_TEXTURE_SET_BUMP_ENV_MAT, bump_env_material[0], bump_env_material[1], bump_env_material[2],
bump_env_material[3]);
p = pb_push1f(p, NV097_SET_TEXTURE_SET_BUMP_ENV_SCALE, bump_env_scale);
p = pb_push1f(p, NV097_SET_TEXTURE_SET_BUMP_ENV_OFFSET, bump_env_offset);
pb_end(p);
}
void TextureStage::SetFilter(uint32_t lod_bias, TextureStage::ConvolutionKernel kernel, TextureStage::MinFilter min,
TextureStage::MagFilter mag, bool signed_alpha, bool signed_red, bool signed_green,
bool signed_blue) {
texture_filter_ =
MASK(NV097_SET_TEXTURE_FILTER_MIPMAP_LOD_BIAS, lod_bias) |
MASK(NV097_SET_TEXTURE_FILTER_CONVOLUTION_KERNEL, kernel) | MASK(NV097_SET_TEXTURE_FILTER_MIN, min) |
MASK(NV097_SET_TEXTURE_FILTER_MAG, mag) | MASK(NV097_SET_TEXTURE_FILTER_ASIGNED, signed_alpha) |
MASK(NV097_SET_TEXTURE_FILTER_RSIGNED, signed_red) | MASK(NV097_SET_TEXTURE_FILTER_GSIGNED, signed_green) |
MASK(NV097_SET_TEXTURE_FILTER_BSIGNED, signed_blue);
}
int TextureStage::SetTexture(const SDL_Surface *surface, uint8_t *memory_base) const {
auto pixels = static_cast<uint32_t *>(surface->pixels);

View File

@ -7,9 +7,40 @@
#include "texture_format.h"
class TextureStage {
public:
enum ConvolutionKernel {
K_QUINCUNX = 1,
K_GAUSSIAN_3 = 2,
};
enum MinFilter {
MIN_BOX_LOD0 = 1,
MIN_TENT_LOD0,
MIN_BOX_NEARESTLOD,
MIN_TENT_NEARESTLOD,
MIN_BOX_TENT_LOD,
MIN_TENT_TENT_LOD,
MIN_CONVOLUTION_2D_LOD0,
};
enum MagFilter {
MAG_BOX_LOD0 = 1,
MAG_TENT_LOD0 = 2,
MAG_CONVOLUTION_2D_LOD0 = 4,
};
public:
void SetEnabled(bool enabled = true) { enabled_ = enabled; }
void SetFormat(const TextureFormatInfo &format) { format_ = format; }
void SetBorderColor(uint32_t color) { border_color_ = color; }
void SetBumpEnv(float x, float y, float z, float w, float scale, float offset = 0.0f) {
bump_env_material[0] = x;
bump_env_material[1] = y;
bump_env_material[2] = z;
bump_env_material[3] = w;
bump_env_scale = scale;
bump_env_offset = offset;
}
void SetDimensions(uint32_t width, uint32_t height, uint32_t depth = 1) {
width_ = width;
height_ = height;
@ -35,6 +66,9 @@ class TextureStage {
void SetTextureOffset(uint32_t offset) { texture_memory_offset_ = offset; }
void SetPaletteOffset(uint32_t offset) { palette_memory_offset_ = offset; }
void SetFilter(uint32_t lod_bias = 0, ConvolutionKernel kernel = K_QUINCUNX, MinFilter min = MIN_BOX_LOD0,
MagFilter mag = MAG_BOX_LOD0, bool signed_alpha = false, bool signed_red = false,
bool signed_green = false, bool signed_blue = false);
void Commit(uint32_t memory_dma_offset, uint32_t palette_dma_offset) const;
@ -58,6 +92,13 @@ class TextureStage {
uint32_t palette_length_{10};
uint32_t palette_memory_offset_{0};
uint32_t texture_filter_{0x1012000};
uint32_t border_color_{0};
float bump_env_material[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float bump_env_scale{0.0f};
float bump_env_offset{0.0f};
};
#endif // NXDK_PGRAPH_TESTS_TEXTURE_STAGE_H