当前位置:网站首页>数值重映射方法(Remap)
数值重映射方法(Remap)
2022-04-22 08:44:00 【勥小透明】
数值重映射虽然不属于系统的 api,但在我们平时的工作中又是不可或缺的。
0~1 之间其实很简单
-1,1 -> 0,1 时,就是 x * 0.5 + 0.5 = y
0,1 -> -1,1 时,就是 y * 2 - 1 = x
x和y是具有可逆性的
除了像上面这种确定的值外,比如我的范围是不固定的话怎么办?
别慌,这也是有公式可以用的,要不说数学的世界很神奇呢~
float Remap(float x, float t1, float t2, float s1, float s2)
{
return (s2 - s1) / (t2 - t1) * (x - t1) + s1;
return (x - t1) / (t2 - t1) * (s2 - s1) + s1;
}
上面这2条公式是等效的,具体怎么用,就看你要怎么组织了。
其中 x = 输入值, t1 = 输入值的最小值, t2 = 输入值的最大值, s1 = 输出值的最小值, s2 = 输出值的最大值
举个:
设 t1=0, t2=1, s1=-1, s2=1时,
当x=0时,函数输出值=-1
当x=1时,函数输出值=1
当x=0.5时,函数输出值=0
怎么样,聪明的你应该看懂怎么用了吧
上面一般是在逻辑脚本里的写法,如果换到 shader 这边,例如 hlsl 的话,因为有矢量寄存器的加持,写起来是这样的
void Remap(float4 In, float2 InMinMax, float2 OutMinMax, out float4 Out)
{
Out = (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x) + OutMinMax.x;
}
像 unity 如果想在 c# 里也能这么写的话,就需要它新的数据库 com.unity.mathematics 才行,它有 SIMD 功能的加持,当然有很多人其实是不太适应 hlsl 这种写法的~
版权声明
本文为[勥小透明]所创,转载请带上原文链接,感谢
https://blog.csdn.net/WPAPA/article/details/124320373
边栏推荐
- ThreadLocal actual combat
- 聊聊限流
- 合并两个有序链表(迭代)
- 手動搭建hyperledger fabric v2.x 生產網絡(四)創建通道,鏈碼的生命周期
- Flink流处理引擎系统学习(三)
- L2-004 搜索树判断
- A 2500 word article will take you to understand the basic knowledge of performance testing
- 玩转Kubernetes—基础概念篇
- 六个方法,可以让你在NFT交易中收益更多
- 2022 high voltage electrician test simulation 100 questions and answers
猜你喜欢

【微信小程序】为小程序设置底部菜单(tabBar)

Examples of cmake basic knowledge II: single file, multiple files, dynamic and static library and use

(CVPR-2014)通过预测 10,000 个类别的深度学习人脸表示

宝宝起名神器小程序源码_支持多种流量主模式

The penultimate node in the linked list (sequential search, speed pointer)

Shrimp noodles: what is zero copy? How to achieve zero copy?

运维数据该如何防泄露

A 2500 word article will take you to understand the basic knowledge of performance testing

Baby naming artifact applet source code_ Support multiple traffic master modes

14 py games source code sharing
随机推荐
flink 学习(十一)Watermark
用栈实现队列(双栈,输入栈、输出栈)
pip install shutil 报错
Construire manuellement le tissu hyperledger V2. X réseau de production (IV) Création de canaux, cycle de vie des codes de chaîne
On the difference between local variables and global variables
2022 high altitude installation, maintenance and demolition of special operation permit examination question bank and simulated examination platform operation
宝宝起名神器小程序源码_支持多种流量主模式
2022G3锅炉水处理上岗证题目及答案
numpy笔记(vstack,random.permutation,empty_like,empty,diff,random.choice,random.randint,isin)
Reverse linked list II
vector常见接口的用法
单片机开发之裸机也能 “多任务”?
【系统分析师之路】2020年下系统分析师案例分析真题
分隔链表(建两个空链表)
About the fact that I was cheated of fifteen thousand when I wanted to borrow money
新书推荐——IPv6技术与应用(锐捷版)
健身房会员管理系统需求分析文档
【图像隐写】Fixed Neural Network Steganography: Train the images, not the network 整理
智能手表的突破和新发展机遇
RHCSA第一天作业