归一化UV坐标
This commit is contained in:
parent
8d1bb03372
commit
aed0083122
@ -32,7 +32,7 @@ function(compile_slang_shaders input_file stage entry_point)
|
||||
set(output_file ${output_dir}/${filename}_${entry_point}.glsl)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_file}
|
||||
COMMAND slangc -target glsl -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file}
|
||||
COMMAND slangc -target glsl -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file} -DUSE_OPENGL=1 -DUV_FLIP=1
|
||||
DEPENDS ${input_file}
|
||||
COMMENT "Compiling ${input_file} to GLSL (${stage}, ${entry_point})"
|
||||
)
|
||||
@ -43,7 +43,7 @@ function(compile_slang_shaders input_file stage entry_point)
|
||||
set(output_file ${output_dir}/${filename}_${entry_point}.dxbc)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_file}
|
||||
COMMAND slangc -target dxbc -profile ${profile} -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file}
|
||||
COMMAND slangc -target dxbc -profile ${profile} -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file} -DUSE_DX=1
|
||||
DEPENDS ${input_file}
|
||||
COMMENT "Compiling ${input_file} to DXBC (${stage}, ${entry_point}) with profile ${profile}"
|
||||
)
|
||||
@ -54,7 +54,7 @@ function(compile_slang_shaders input_file stage entry_point)
|
||||
set(output_file ${output_dir}/${filename}_${entry_point}.spirv)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_file}
|
||||
COMMAND slangc -target spirv -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file}
|
||||
COMMAND slangc -target spirv -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file} -DUSE_VULKAN=1 -DUV_FLIP=1
|
||||
DEPENDS ${input_file}
|
||||
COMMENT "Compiling ${input_file} to SPIR-V (${stage}, ${entry_point})"
|
||||
)
|
||||
@ -65,7 +65,7 @@ function(compile_slang_shaders input_file stage entry_point)
|
||||
set(output_file ${output_dir}/${filename}_${entry_point}.metal)
|
||||
add_custom_command(
|
||||
OUTPUT ${output_file}
|
||||
COMMAND slangc -target msl -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file}
|
||||
COMMAND slangc -target msl -entry ${entry_point} -stage ${stage} ${extra_args} -o ${output_file} ${input_file} -DUSE_METAL=1
|
||||
DEPENDS ${input_file}
|
||||
COMMENT "Compiling ${input_file} to Metal Shading Language (${stage}, ${entry_point})"
|
||||
)
|
||||
|
@ -14,13 +14,10 @@ void renderer_context::draw_rectangle(const Eigen::Vector2f& in_pos, const Eigen
|
||||
void renderer_context::draw_rounded_rectangle(const Eigen::Vector2f& in_pos, const Eigen::Vector2f& in_size, const linear_color& in_color, float in_angle, const rect_radius& in_radius) {
|
||||
to_rounded_rect_pipeline(in_pos, in_size, in_radius);
|
||||
// in_angle传入的是角度, 需要转换为弧度
|
||||
#define M_PI 3.14159265358979323846
|
||||
in_angle = in_angle * M_PI / 180;
|
||||
|
||||
make_rect(in_pos, in_size, in_color, in_angle);
|
||||
if (in_angle != 0) {
|
||||
auto center = in_pos + in_size / 2;
|
||||
rotate_vertex(in_angle, center);
|
||||
}
|
||||
// 立刻绘制并重置管线, 因为下一个绘制命令的参数可能不同, 所以无法合批
|
||||
flush();
|
||||
}
|
||||
@ -90,10 +87,23 @@ void renderer_context::to_segment_pipeline(const Eigen::Vector2f& in_pos_p1, con
|
||||
|
||||
void renderer_context::make_rect(const Eigen::Vector2f& in_pos, const Eigen::Vector2f& in_size,
|
||||
const linear_color& in_color, float in_angle) {
|
||||
const aorii_vertex v1{ { in_pos.x(), in_pos.y() }, { -1, 1 }, in_color }; // 左上角
|
||||
const aorii_vertex v2{ { in_pos.x() + in_size.x(), in_pos.y() }, { 1, 1 }, in_color }; // 右上角
|
||||
const aorii_vertex v3{ { in_pos.x(), in_pos.y() + in_size.y() }, { -1, -1 }, in_color }; // 左下角
|
||||
const aorii_vertex v4{ { in_pos.x() + in_size.x(), in_pos.y() + in_size.y() }, { 1, -1 }, in_color }; // 右下角
|
||||
aorii_vertex v1{ { in_pos.x(), in_pos.y() }, { 0, 0 }, in_color }; // 左上角
|
||||
aorii_vertex v2{ { in_pos.x() + in_size.x(), in_pos.y() }, { 1, 0 }, in_color }; // 右上角
|
||||
aorii_vertex v3{ { in_pos.x(), in_pos.y() + in_size.y() }, { 0, 1 }, in_color }; // 左下角
|
||||
aorii_vertex v4{ { in_pos.x() + in_size.x(), in_pos.y() + in_size.y() }, { 1, 1 }, in_color }; // 右下角
|
||||
|
||||
if (in_angle != 0) {
|
||||
auto center = in_pos + in_size / 2;
|
||||
const Eigen::Affine2f transform =
|
||||
Eigen::Translation<float, 2>(center) * // 平移到旋转中心
|
||||
Eigen::Rotation2D<float>(in_angle) * // 旋转
|
||||
Eigen::Translation<float, 2>(-center); // 平移回原点
|
||||
|
||||
v1.position = transform * v1.position;
|
||||
v2.position = transform * v2.position;
|
||||
v3.position = transform * v3.position;
|
||||
v4.position = transform * v4.position;
|
||||
}
|
||||
|
||||
const uint32_t index1 = vertices.size();
|
||||
vertices.push_back(v1);
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include "aorii_util.slang"
|
||||
|
||||
cbuffer ParamBuffer : register(b0)
|
||||
{
|
||||
matrix transform;
|
||||
@ -38,11 +40,11 @@ float distance_from_rect_uv(float2 p, float corner_radius) {
|
||||
|
||||
float4 pixel_main(PSInput input) : SV_Target
|
||||
{
|
||||
float2 p = input.uv;
|
||||
float2 p = uv_to_ndc(input.uv);
|
||||
|
||||
// 象限
|
||||
int2 quadrant = sign(p);
|
||||
int idx = (quadrant.x > 0 ? 1 : 0) + (quadrant.y > 0 ? 0 : 2);
|
||||
int idx = (quadrant.x > 0 ? 1 : 0) + (quadrant.y > 0 ? 2 : 0);
|
||||
float r = radius[idx];
|
||||
float d = distance_from_rect_uv(p, r);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user