当前位置:网站首页>[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
2022-07-01 03:42:00 【zczplus】
【TA- Frost Wolf _may-《 Hundred people plan 》】2.3 Introduction to common functions
【TA- Frost Wolf _may-《 Hundred people plan 》】2.3 Introduction to common functions
2.3HLSL Common functions
2.3.1 Basic mathematical operations
max(a,b) min(a,b) mul(a,b) abs(a) round(x)
sqrt(x) return x The square root of
rsqrt(x) return x The reciprocal of the square root of
degrees(x) Convert radians to angles
redians(x) Convert angles into radians
noise(x) Noise function
2.3.2 Power exponential pair function
pow(x,y) x Of y The next power (x and y Can be an independent variable or a specific number )
exp(x) Return to e The exponential function at the bottom
exp2(value x) Return to 2 Bottom ,x Is a power of the exponent
ldexp(x,exp) return x And 2 Of exp The product of power
log(x)
log10(x)
log2(x)
frexp(x,out exp) Floating point x Decompose into mantissa and exponent x = ret*2^exp, The return value is the mantissa ,exp The value returned by the parameter is the exponent
( If x Parameter is 0, Then the mantissa and exponent of this function return 0)
2.3.3 Trigonometric and hyperbolic functions
sin(x) cos(x) tan(x)
sincos(x, out s, out c) return x The sine and cosine of
tan(y,x) asin(x) acos(x) atan(x) atan2(y,x) return y/x The arctangent of
Aforementioned x Values are in radians
sinh(x) return x The hyperbolic sine of namely (ex-e-x) / 2
cosh(x) return x The hyperbolic cosine value of namely (ex+e-x) / 2
tanh(x) return x The hyperbolic sine of namely (ex-e-x) / (ex+e-x)
2.3.4 Data range class
ceil(x) return >=x Minimum integer of
floor(x) return <=x Maximum integer for
step(x,y) x<=y by 1, Otherwise 0
saturate(x) Return to x Clamp to 0 and 1 Between the value of the
clamp(x,min,max) hold x Restriction on [min,max] Within the scope of , Judgment x Is it within this range , If yes, the original value is returned , If not, return to the upper or lower limit
fmod(x,y) return x Yes y Remainder of remainder
frac(x) return x Decimal part of
modf(x, out ip) Will value x Divided into decimal and integral parts ( The symbols of each part are the same as x identical )
ip Returns the integer part , The whole returns the decimal part
The interpolation function
lerp(x,y,s) according to s stay x To y Interpolation between , Return x*(1-s)+y*s;
smoothstep(min,max,x) If x stay [min, max] Within the scope of , Returns a value between 0 And 1 The smoothness between Hermite interpolation , Use smoothstep Create a smooth experience between two values . For example, you can blend two colors smoothly .
2.3.5 Type judgment class
all(x) Determines whether all components of the specified quantity are non-zero , If both are non-zero, return True, otherwise false( Scalar 、 Vector or matrix can )
clip(x) If the input value is less than zero , The current pixel is discarded It is often used to determine the range ( It's not just about 0, The return value is void), Or test alpha, If each component represents the distance to the plane , It can also be used to simulate the shear plane
sign(x) return x It's positive and negative If x Less than zero returns -1, If x Equal to zero returns 0, If x Greater than zero returns 1
isinf(x) Judge whether it is infinite or infinitesimal
isfinite(x) Judge x Whether the parameters are limited
isnan(x) Judge whether it is NAN
2.3.6 Vector and matrix classes
length(v)
normalize(v)
distance(a,b) Express : Two vectors , Returns the sum of the squares of the differences of the components under the root sign ( No, it is. The distance to the destination )
dot(a,b) Dot product
cross(a,b) Cross product
determinant(m) Return matrix m The value calculated as a determinant
transpose(m) Return matrix m The transpose matrix of
2.3.7 Ray operation class
reflect(i,n) Return to i Is the incidence direction ,n Is the reflected light in the normal direction
refract(i,n,ri) Return to i Is the incident vector ,n Is the normal direction ,ri Is the refractive index of the refracted light
lit(n_dot_I, n_dot_h, m) They correspond to each other (normallight,normal Half angle vector h, The specular reflection coefficient m) Returns an illumination vector ( The ambient light , Diffuse light , Specular highlights ,1)
faceforward(n,i,ng) The input and output of the surface normal vector facing the view direction is the same element vector , return -n*sign(dot(i,ng))(normal,light,normal)
Illumination vector
Illumination vector ( The ambient light , Diffuse light , Specular highlights ,1)(Blinn Model )
2.3.8 Texture lookup
GPU In slice element processing (PixelShader) The stage is in screen space XY In the coordinate system, each pixel is searched for the corresponding texture element to determine the color of the pixel ( The name is easy to understand )
1D
Methods are not commonly used , Few store data in this way , Corresponding to a one-dimensional array
2D
Corresponding to two-dimensional array , That's the matrix
3D Texture lookup
Search for 3D data , It is composed of multi-layer two-dimensional arrays .
tex(s,t) In a given texture sampler (s, It refers to the sampled image ) Under the circumstances , adopt t(1D Scalar below ,2D、3D Is vector , That is, the position coordinates ) To determine the texture data .
Projection texture correlation ( Not very clear Look again. )
tex1Dproj(s, t) Project the texture into the scene as a slide , Firstly, the projection texture coordinates are calculated by using the projection texture technique ( Due to the change of the angle between the projection ray and the projection surface , So the coordinates of the projected texture are not simply scaled , There will also be other problems such as oblique cutting , In addition, the irregular projection surface is also a problem that needs to be solved ), Finally, we use the projected texture coordinates to query the texture elements .
ddx、ddy Focus on checking by yourself
mipmap
A good picture , Better understand why memory space is only used up 1/3
Stereo texture lookup
Unlike 3D search , You need to specify a specific face , And the performance cost is higher .
summary
Write what you think is most commonly used 5 A function ?
- When looking at the essentials of the introduction, I found that there are many operations on matrices and vectors , among mul(x,y) As a high-frequency application point, it must be indispensable ;
- Normalization should also be common , therefore saturate(x) Should also be more commonly used ;
- The interpolation function ;
- Ray operation class should be the key and difficult , Generally, objects will be illuminated , It should be a common function ;
- In texture lookup mipmap Correlation function is an unavoidable problem in the whole rendering process , So it's a common function ;
ddx、ddy and Mipmap
I saw Games101 P9, Begin to understand .
- stay Mipmap in ,ddx and ddy Its main purpose is to calculate the coverage length of screen pixels in the texture , from
L = MAX(sqrt(ddx(u, v)2, ddy(u, v)2)) The approximate side length of the covering texture rectangle can be obtained ; - recycling D=Log2(L) Get what you need Mipmap The number of layers , take Log2(L) Because ,Mipmap Each layer of is reduced to the upper layer 1/2, Just find Log2(L) layer , here L On this layer is the unit length , Thus, the process of re sampling is saved ;
- also ,Log2(L) In general, it is a non integer , At this time, use the Mipmap Layer to perform another linear interpolation , It can make the result more accurate , therefore Mipmap This method is also called cubic linear interpolation .
边栏推荐
- 392. 判断子序列
- Idea plug-in backup table
- 10、Scanner.next() 无法读取空格/indexOf -1
- [daily training] 1175 Prime permutation
- 208. 实现 Trie (前缀树)
- 后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
- Explain spark operation mode in detail (local+standalone+yarn)
- 文件上传下载
- Implement pow (x, n) function
- Take you through a circuit board, from design to production (dry goods)
猜你喜欢
随机推荐
10、Scanner. Next() cannot read spaces /indexof -1
静态库使用MFC和共享库使用MFC的区别
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
TEC: Knowledge Graph Embedding with Triple Context
How to use hybrid format to output ISO files? isohybrid:command not found
Leetcode:829. Sum of continuous integers
Database DDL (data definition language) knowledge points
Feign remote call and getaway gateway
Use of comment keyword in database
Cookie&Session
谷粒学院微信扫码登录过程记录以及bug解决
Research on target recognition and tracking based on 3D laser point cloud
服务器渲染技术jsp
ECMAScript 6.0
Binary tree god level traversal: Morris traversal
SEM of C language_ Tvariable type
File upload and download
还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板
166. 分数到小数








