Add a raw verts version for queue_textured_quad

This commit is contained in:
Phillip Stephens 2022-02-07 04:22:51 -08:00
parent 4c705683bc
commit b8e60eac1b
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
5 changed files with 91 additions and 19 deletions

View File

@ -14,7 +14,7 @@ use fog_volume_filter::queue_fog_volume_filter;
use fog_volume_plane::queue_fog_volume_plane; use fog_volume_plane::queue_fog_volume_plane;
use model::{add_material_set, add_model}; use model::{add_material_set, add_model};
use texture::{create_render_texture, create_static_texture_2d, drop_texture}; use texture::{create_render_texture, create_static_texture_2d, drop_texture};
use textured_quad::queue_textured_quad; use textured_quad::{queue_textured_quad_verts, queue_textured_quad};
use twox_hash::Xxh3Hash64; use twox_hash::Xxh3Hash64;
use wgpu::RenderPipeline; use wgpu::RenderPipeline;
@ -185,6 +185,15 @@ mod ffi {
fn queue_aabb(aabb: CAABox, color: CColor, z_only: bool); fn queue_aabb(aabb: CAABox, color: CColor, z_only: bool);
fn queue_fog_volume_plane(verts: &CxxVector<CVector4f>, pass: u8); fn queue_fog_volume_plane(verts: &CxxVector<CVector4f>, pass: u8);
fn queue_fog_volume_filter(color: CColor, two_way: bool); fn queue_fog_volume_filter(color: CColor, two_way: bool);
fn queue_textured_quad_verts(
filter_type: CameraFilterType,
texture: TextureRef,
z_test: ZTest,
color: CColor,
pos: &[CVector3f],
uvs: &[CVector2f],
lod: f32,
);
fn queue_textured_quad( fn queue_textured_quad(
filter_type: CameraFilterType, filter_type: CameraFilterType,
texture: TextureRef, texture: TextureRef,

View File

@ -7,6 +7,7 @@ use crate::{
get_app, get_app,
gpu::GraphicsConfig, gpu::GraphicsConfig,
shaders::{ shaders::{
get_combined_matrix,
bind_pipeline, bind_pipeline,
BuiltBuffers, BuiltBuffers,
ffi::{CameraFilterType, TextureRef, ZTest}, pipeline_ref, PipelineCreateCommand, PipelineHolder, PipelineRef, ffi::{CameraFilterType, TextureRef, ZTest}, pipeline_ref, PipelineCreateCommand, PipelineHolder, PipelineRef,
@ -267,6 +268,15 @@ pub(crate) fn queue_textured_quad(
lod: 0.0, lod: 0.0,
}); });
push_textured_quad(texture, pipeline, vert_range, uniform_range);
}
fn push_textured_quad(
texture: TextureRef,
pipeline: PipelineRef,
vert_range: Range<u64>,
uniform_range: Range<u64>
){
// TODO defer bind group creation to draw time or another thread? // TODO defer bind group creation to draw time or another thread?
let state = unsafe { STATE.as_mut().unwrap_unchecked() }; let state = unsafe { STATE.as_mut().unwrap_unchecked() };
let groups = &mut state.textured_quad.texture_bind_groups; let groups = &mut state.textured_quad.texture_bind_groups;

View File

@ -1,5 +1,6 @@
use bytemuck_derive::{Pod, Zeroable}; use bytemuck_derive::{Pod, Zeroable};
use cxx::{type_id, ExternType}; use cxx::{type_id, ExternType};
use crate::util::{Vec2, Vec3};
#[derive(Debug, Copy, Clone, Pod, Zeroable, Default)] #[derive(Debug, Copy, Clone, Pod, Zeroable, Default)]
#[repr(C)] #[repr(C)]
@ -169,3 +170,42 @@ impl From<CMatrix4f> for cgmath::Matrix4<f32> {
} }
} }
} }
impl From<Vec2<f32>> for CVector2f {
fn from(v: Vec2<f32>) -> Self {
Self {
x: v.x,
y: v.y,
_p1: 0.0,
_p2: 0.0
}
}
}
impl From<CVector2f> for Vec2<f32> {
fn from(v: CVector2f) -> Self {
Self {
x: v.x,
y: v.y,
}
}
}
impl From<Vec3<f32>> for CVector3f {
fn from(v: Vec3<f32>) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
_p: 0.0,
}
}
}
impl From<CVector3f> for Vec3<f32> {
fn from(v: CVector3f) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
}
}

View File

@ -59,7 +59,7 @@ CAuiImagePane::Filters::Filters(TLockedToken<CTexture>& tex)
, m_addQuad{{CTexturedQuadFilterAlpha{EFilterType::Add, tex}, CTexturedQuadFilterAlpha{EFilterType::Add, tex}}} {} , m_addQuad{{CTexturedQuadFilterAlpha{EFilterType::Add, tex}, CTexturedQuadFilterAlpha{EFilterType::Add, tex}}} {}
void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float alpha, bool noBlur, void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float alpha, bool noBlur,
CTexturedQuadFilterAlpha& quad) const { EFilterType filter) const {
zeus::CColor useColor = color; zeus::CColor useColor = color;
useColor.a() *= alpha; useColor.a() *= alpha;
@ -82,6 +82,12 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t
useUVs = &x114_uvs; useUVs = &x114_uvs;
} }
std::vector<zeus::CVector2f> realUseUvs;
realUseUvs.reserve(4);
for (auto v : *useUVs) {
realUseUvs.push_back(v + xd0_uvBias0);
}
const std::array<CTexturedQuadFilter::Vert, 4> verts{{ const std::array<CTexturedQuadFilter::Vert, 4> verts{{
{xe0_coords[0], (*useUVs)[0] + xd0_uvBias0}, {xe0_coords[0], (*useUVs)[0] + xd0_uvBias0},
{xe0_coords[1], (*useUVs)[1] + xd0_uvBias0}, {xe0_coords[1], (*useUVs)[1] + xd0_uvBias0},
@ -90,14 +96,21 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t
}}; }};
if (noBlur) { if (noBlur) {
quad.drawVerts(useColor, verts); aurora::shaders::queue_textured_quad_verts(
aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::None, useColor,
{xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, 0);
// quad.drawVerts(useColor, verts);
} else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) { } else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) {
quad.drawVerts(useColor, verts, 0.f); aurora::shaders::queue_textured_quad_verts(
aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::None, useColor,
{xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, 0);
} else { } else {
const float tmp = (1.f - x14c_deResFactor) * alpha; const float tmp = (1.f - x14c_deResFactor) * alpha;
const float tmp3 = 1.f - tmp * tmp * tmp; const float tmp3 = 1.f - tmp * tmp * tmp;
const float mip = tmp3 * static_cast<float>(tex.GetNumMips() - 1); const float mip = tmp3 * static_cast<float>(tex.GetNumMips() - 1);
quad.drawVerts(useColor, verts, mip); aurora::shaders::queue_textured_quad_verts(
aurora::shaders::CameraFilterType(filter), tex.GetTexture()->ref, aurora::shaders::ZTest::None, useColor,
{xe0_coords.data(), xe0_coords.size()}, {realUseUvs.data(), xe0_coords.size()}, mip);
} }
} }
@ -130,46 +143,46 @@ void CAuiImagePane::Draw(const CGuiWidgetDrawParms& params) {
} }
// Alpha blend // Alpha blend
DoDrawImagePane(color * zeus::CColor(0.f, 0.5f), *xb8_tex0Tok, frame0, 1.f, true, filters.m_darkenerQuad); DoDrawImagePane(color * zeus::CColor(0.f, 0.5f), *xb8_tex0Tok, frame0, 1.f, true, EFilterType::Blend);
if (x150_flashFactor > 0.f) { if (x150_flashFactor > 0.f) {
// Additive blend // Additive blend
zeus::CColor color2 = xa8_color2; zeus::CColor color2 = xa8_color2;
color2.a() = x150_flashFactor; color2.a() = x150_flashFactor;
DoDrawImagePane(color2, *xb8_tex0Tok, frame0, blur0, false, filters.m_flashQuad[0]); DoDrawImagePane(color2, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Blend);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color2, *xb8_tex0Tok, frame1, blur1, false, filters.m_flashQuad[1]); DoDrawImagePane(color2, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Blend);
} }
switch (xac_drawFlags) { switch (xac_drawFlags) {
case EGuiModelDrawFlags::Shadeless: case EGuiModelDrawFlags::Shadeless:
case EGuiModelDrawFlags::Opaque: case EGuiModelDrawFlags::Opaque:
// Opaque blend // Opaque blend
DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, filters.m_alphaQuad[0]); DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Blend);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, filters.m_alphaQuad[1]); DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Blend);
break; break;
case EGuiModelDrawFlags::Alpha: case EGuiModelDrawFlags::Alpha:
// Alpha blend // Alpha blend
DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, filters.m_alphaQuad[0]); DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Blend);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, filters.m_alphaQuad[1]); DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Blend);
break; break;
case EGuiModelDrawFlags::Additive: case EGuiModelDrawFlags::Additive:
// Additive blend // Additive blend
DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, filters.m_addQuad[0]); DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Add);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, filters.m_addQuad[1]); DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Add);
break; break;
case EGuiModelDrawFlags::AlphaAdditiveOverdraw: case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
// Alpha blend // Alpha blend
DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, filters.m_alphaQuad[0]); DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Blend);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, filters.m_alphaQuad[1]); DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Blend);
// Full additive blend // Full additive blend
DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, filters.m_addQuad[0]); DoDrawImagePane(color, *xb8_tex0Tok, frame0, blur0, false, EFilterType::Add);
if (blur1 > 0.f) if (blur1 > 0.f)
DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, filters.m_addQuad[1]); DoDrawImagePane(color, *xb8_tex0Tok, frame1, blur1, false, EFilterType::Add);
break; break;
default: default:
break; break;

View File

@ -42,7 +42,7 @@ class CAuiImagePane : public CGuiWidget {
}; };
std::optional<Filters> m_filters; std::optional<Filters> m_filters;
void DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float blurAmt, bool noBlur, void DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float blurAmt, bool noBlur,
CTexturedQuadFilterAlpha& quad) const; EFilterType filter) const;
public: public:
CAuiImagePane(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId, CAssetId, CAuiImagePane(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId, CAssetId,