dx11 入门 Tutorial 04: DX、HLSL中矩阵的内存存储和数学计算方式 DirectXSampleBrowser(June 2010)

主要是两方面:

1.shader数据和dx的通信,使用constant Buffer

2.矩阵的数学计算方式和内存存储方式再DX和HLSL中的异同

先说第一个: dx中的常量数据matrix等传入shader中流程:

The first thing that we need to do is declare three constant buffer variables. Constant buffers are used to store data that the application needs to pass to shaders. Before rendering, the application usually writes important data to constant buffers, and then during rendering the data can be read from within the shaders.

第一步:在shader中 声明constantBuffer变量,constantBuffer存储application中传入shader的数据,在渲染时,shader可以读入这些数据

    cbuffer ConstantBuffer : register( b0 )
    {
        matrix World;
        matrix View;
        matrix Projection;
    }

Before rendering, we copy the values of these matrices to the shader constant buffer.

第二步:在dx中,使用device创建buffer,这个buffer定义的数据结构和shader内constantBuffer  struct相同

	hr = g_pd3dDevice->CreateBuffer( &bd, NULL, &g_pConstantBuffer );

             第三第四步:context来设置、更新constantBuffer,用来每帧更新数据,传入shader中

笔记二:矩阵数学操作方式、内存存储方式再dx和hlsl中的异同

疑问来源:because matrices are arranged differently in memory in C++ and HLSL, we must transpose the matrices before updating them.

需要进行矩阵转置,再copy到shader里,但dx9中,使用constantTable来setMatrix时,并没有转置啊?

参考:http://www.cnblogs.com/kex1n/archive/2013/10/29/3395023.html

时间: 2024-08-05 01:56:17

dx11 入门 Tutorial 04: DX、HLSL中矩阵的内存存储和数学计算方式 DirectXSampleBrowser(June 2010)的相关文章

HDP3.1 中 YRAN 和 MR2 的内存大小配置的计算方式

Container 是 YARN 中基本的处理单元,它是对内存.CPU等计算的封装.总的来说,每个core每块硬盘 分配2个 container,能获得较好的集群利用率. 1. 确定可用内存大小. 对于每台主机来说,YARN 和 MapReduce 能用内存大小是除去预留给系统的内存(如果还有 HBase,还要相应留内存给它)后的大小,即: YARN 可用内存(RAM for YARN) = 总内存(Total RAM) - 系统预留(Reserved for System) - HBase预留

dx11 入门 Tutorial 05: DepthBuffer的创建 DirectXSampleBrowser(June 2010)

本课主要是矩阵变换和DepthBuffer的创建: 笔记:关于depthBuffer 问题:1.depthBuffer的作用? 2.怎么创建? 作用:我想到的:1.depthTest,保证遮挡,同一个pixel中z值小的渲染:  2.三维世界,需要z值来表示近大远小  3.dx中值在1到0之间 MSDN的解释:1.depthBuffer存储每个pixel的z值,也可以存储stencil值,常用32bit,24bit用于depth数据 8bit用于stencil数据 2.当一个pixel渲染后,里

dx11 入门篇 Tutorial 01: 基本要素的创建 DirectXSampleBrowser(June 2010)

目标:这几天迅速入门dx11 第一讲主要是基本要素的创建:device .context.view.swap: 笔记: 1.In Direct3D 10, the device object was used to perform both rendering and resource creation. In Direct3D 11, the immediate context is used by the application to perform rendering onto a buf

dx11 入门 Tutorial 02: 数据传入GPU的设置 和绘制一个三角形 DirectXSampleBrowser(June 2010)

烦...一年前看过教程,但全忘掉了,这一年我都干什么了... 教程2遇到的两个error: error 1:ID3DBlob调用不成功 ,是重复调用版本冲突的原因?ID3DBlob在D3DCommon.h中, 因为window include里和SDK里各有一份,造成了冲突,修改头文件的调用,先调用SDK内的即可.参考:http://www.cnblogs.com/Wilson-Loo/archive/2013/01/20/2797902.html 那为什么先后顺序就解决问题呢> error 2

dx11 入门 Tutorial 03: 什么是shader DirectXSampleBrowser(June 2010)

对shader的认知: shader是什么? In Direct3D 11, shaders reside in different stages of the graphics pipeline. They are short programs that, executed by the GPU, take certain input data, process that data, and then output the result to the next stage of the pip

dx11 入门 Tutorial 06: 明白context->updateSubsource和setConstantBuffers DirectXSampleBrowser(June 2010)

需要明白constantBuffer传入数据到shader的正确使用:: cb1.vOutputColor = XMFLOAT4(0, 0, 0, 0); g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb1, 0, 0 ); //更新cube的数据 // // Render the cube // g_pImmediateContext->VSSetShader( g_pVertexShade

Java中的栈内存和堆内存

为什么我们常说基本类型传递的是具体的值,而对象传递的是对象的内存地址呢.要搞清楚这个问题就要搞清楚栈内存与堆内存. java的内存分为栈内存和堆内存,两者的作用是不同的,我们可以简单的理解如下: 当我们创建一个java基本类型的变量时,只会用到栈内存而不会用到堆内存,栈内存中所存储的内容就是基本类型的值. int a = 3;  int b = 3; 执行第一行 int a = 3;时,JVM先会创建一个变量为a的引用,然后在栈内存中查找是否已经存在3这个值,没有找到,就会在栈内存中开辟一片区域

Angular系列----AngularJS入门教程04:迭代器过滤(转载)

我们在上一步做了很多基础性的训练,所以现在我们可以来做一些简单的事情喽.我们要加入全文检索功能(没错,这个真的非常简单!).同时,我们也会写一个端到端测试,因为一个好的端到端测试可以帮上很大忙.它监视着你的应用,并且在发生回归的时候迅速报告. 请重置工作目录: git checkout -f step-3 我们的应用现在有了一个搜索框.注意到页面上的手机列表随着用户在搜索框中的输入而变化. 步骤2和步骤3之间最重要的不同在下面列出.你可以在GitHub里看到完整的差别. 控制器 我们对控制器不做

jQuery入门(4)jQuery中的Ajax应用

jQuery入门(1)jQuery中万能的选择器 jQuery入门(2)使用jQuery操作元素的属性与样式 jQuery入门(3)事件与事件对象 jQuery入门(4)jQuery中的Ajax应用 一.原始Ajax与jQuery中的Ajax 首先通过实例, 来看一下jQuery实现Ajax有多简单. 下面是一个使用原始Ajax的示例: 01 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "