Muli3D <6> Struct m3dtriangleinfo 的属性 fZDdx,fZDdy 的推导
来源:互联网 发布:网络语洗白白啥意思 编辑:程序博客网 时间:2024/06/05 16:22
记录一下:
根据
struct m3dtriangleinfo{float32fCommonGradient;///< Gradient constant.const m3dvsoutput*pBaseVertex;///< Base vertex for gradient computations./// z partial derivatives with respect to the screen-space x- and y-coordinates.float32fZDdx, fZDdy;/// w partial derivatives with respect to the screen-space x- and y-coordinates.float32fWDdx, fWDdy;shaderregShaderOutputsDdx[c_iPixelShaderRegisters];///< Shader register partial derivatives with respect to the screen-space x-coordinate.shaderregShaderOutputsDdy[c_iPixelShaderRegisters];///< Shader register partial derivatives with respect to the screen-space y-coordinate./// Integer-coordinates of current pixel; needed by pixel shader for computation of partial derivatives.uint32 iCurPixelX, iCurPixelY;float32 fCurPixelInvW; ///< 1.0f / w of the current pixel; needed by pixel shader for computation of partial derivatives.};
知道了 fZDdx, fZDdy 其实就是 z partial derivatives with respect to the screen-space x- and y-coordinates.就是 ∂z/∂x, ∂z/∂y
那么 怎么计算 ∂z/∂x, ∂z/∂y, 在Muli3D给出来结果:
// v1.x - v0.x, v2.x - v0.xconst float32 fDeltaX[2] = { i_pVSOutput1->vPosition.x - i_pVSOutput0->vPosition.x, i_pVSOutput2->vPosition.x - i_pVSOutput0->vPosition.x };// v1.y - v0.y, v2.y - v0.yconst float32 fDeltaY[2] = { i_pVSOutput1->vPosition.y - i_pVSOutput0->vPosition.y, i_pVSOutput2->vPosition.y - i_pVSOutput0->vPosition.y };// value = 1.0f / (v1.x - v0.x) * (v2.y - v0.y) - (v2.x - v0.x) * (v1.y - v0.y)m_TriangleInfo.fCommonGradient = 1.0f / ( fDeltaX[0] * fDeltaY[1] - fDeltaX[1] * fDeltaY[0] );// 设置pBaseVertexm_TriangleInfo.pBaseVertex = i_pVSOutput0;// The derivatives with respect to the y-coordinate are negated, because in screen-space the y-axis is reversed.// v1.z - v0.z , v2.z - v0.zconst float32 fDeltaZ[2] = { i_pVSOutput1->vPosition.z - i_pVSOutput0->vPosition.z, i_pVSOutput2->vPosition.z - i_pVSOutput0->vPosition.z };// ((v1.z - v0.z) * (v2.y - v0.y) - (v2.z - v0.z) * (v1.y - v0.y)) / (v1.x - v0.x) * (v2.y - v0.y) - (v2.x - v0.x) * (v1.y - v0.y)m_TriangleInfo.fZDdx = ( fDeltaZ[0] * fDeltaY[1] - fDeltaZ[1] * fDeltaY[0] ) * m_TriangleInfo.fCommonGradient;// -((v1.z - v0.z) * (v2.x - v0.x) - (v2.z - v0.z) * (v1.x - v0.x)) / (v1.x - v0.x) * (v2.y - v0.y) - (v2.x - v0.x) * (v1.y - v0.y)m_TriangleInfo.fZDdy = -( fDeltaZ[0] * fDeltaX[1] - fDeltaZ[1] * fDeltaX[0] ) * m_TriangleInfo.fCommonGradient;
那么问题来了,上面是怎么推导出来的:
主要参考 : http://blog.csdn.net/aa20274270/article/details/70159075
开始推导:
这里就已经推导出来了,
对比代码的 m_TriangleInfo.fZDdx
((v1.z - v0.z) * (v2.y - v0.y) - (v2.z - v0.z) * (v1.y - v0.y)) / (v1.x - v0.x) * (v2.y - v0.y) - (v2.x - v0.x) * (v1.y - v0.y)
和 m_TriangleInfo.fZDdy
-((v1.z - v0.z) * (v2.x - v0.x) - (v2.z - v0.z) * (v1.x - v0.x)) / (v1.x - v0.x) * (v2.y - v0.y) - (v2.x - v0.x) * (v1.y - v0.y)
完全一致。
接下来,对于 m3dtriangleinfo 的 属性 fWDdx, fWDdy; 方法也是一样的。
0 0
- Muli3D <6> Struct m3dtriangleinfo 的属性 fZDdx,fZDdy 的推导
- Muli3D <8> 计算Shader中顶点属性相对于屏幕坐标的偏导数
- Muli3D <9> CubeTexture的采样原理
- Muli3D <5> 判断点与面的关系
- Muli3D <7> 判断Ray与Sphere的关系
- Struct <s:select>标签的属性
- Struct <s:select>标签的属性
- Go语言中struct的匿名属性特征
- 获取一个文件的属性(struct stat结构体)
- 获取一个文件的属性(struct stat结构体)
- Go语言中struct的匿名属性特征
- 将cell数组转换为struct数组,将struct数组的某个属性转换为数组,找到struct数组中某个属性的最大值的索引
- 如何推导视景体的6各面
- Billboard矩阵的推导
- 人工智能推导的雏形
- 对数导数的推导
- stress majorization的推导
- 投影矩阵的推导
- 第三十三讲项目四 多数中的最大
- android自定义绘图控件,绘图所占画布比例过小
- 安卓环境配置
- Huawei OJ-人民币转换
- Spring 之AOP AspectJ切入点语法详解(最全面、最详细。)(转)
- Muli3D <6> Struct m3dtriangleinfo 的属性 fZDdx,fZDdy 的推导
- Android中图片优化之WebP使用
- IOS 界面跳转总结 记录
- EditTExt 输入完成之后自动加东西
- 解决QT4中文乱码的问题
- IcoMoon
- Android 隐藏图标 自启动 服务
- MongoDB可视化工具Robomongo 和 Mongochef
- JavaScript数字精度转载