hlsl

HLSL for getting cylinder effect

帅比萌擦擦* 提交于 2019-12-18 07:14:53
问题 I need to write an application with Silverlight 4 and need to show images like wrapped on cylinder. I need some HLSL code, as I wont to do that with Effects of Silverlight. I don't wont to do that with 3D libarries for silverlight. I only need HLSL code for changing pixels. I need for my image to look like this Thanks. 回答1: This seems to be the effect you want, you may wish to change the 0.2 value to increase or decrease the effect or make this adjustable in your shader but that's a simple

HLSL: Enforce Constant Register Limit at Compile Time

三世轮回 提交于 2019-12-17 21:17:42
问题 In HLSL, is there any way to limit the number of constant registers that the compiler uses? Specifically, if I have something like: float4 foobar[300]; In a vs_2_0 vertex shader, the compiler will merrily generate the effect with more than 256 constant registers. But a 2.0 vertex shader is only guaranteed to have access to 256 constant registers, so when I try to use the effect, it fails in an obscure and GPU-dependent way at runtime. I would much rather have it fail at compile time. This

How to achieve smooth tangent space normals?

家住魔仙堡 提交于 2019-12-17 06:53:22
问题 I'm trying to add bump mapping functionality to my application but I'm getting very faceted models: The reason it is happening is because I'm calculating tangent, binormal and normal on per face basis and completely ignoring the normals I'm getting from the model file. The calculation currently uses two edges of the triangle and texture space vectors to get tangent and binormal, which are then used to calculate normal by cross product. It is all done on the CPU as soon as the model loads and

How to achieve smooth tangent space normals?

混江龙づ霸主 提交于 2019-12-17 06:52:14
问题 I'm trying to add bump mapping functionality to my application but I'm getting very faceted models: The reason it is happening is because I'm calculating tangent, binormal and normal on per face basis and completely ignoring the normals I'm getting from the model file. The calculation currently uses two edges of the triangle and texture space vectors to get tangent and binormal, which are then used to calculate normal by cross product. It is all done on the CPU as soon as the model loads and

Do conditional statements slow down shaders?

烈酒焚心 提交于 2019-12-17 04:42:18
问题 I want to know if "if-statements" inside shaders (vertex / fragment / pixel...) are really slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using this: vec3 output; if(enable == 1) { output = input; } else { output = input2; } in another forum there was a talk about that (2013): http://answers.unity3d.com/questions/442688/shader-if-else-performance.html Here the guys are saying, that the If

Pack four bytes in a float

眉间皱痕 提交于 2019-12-14 00:19:36
问题 I'm writing a shader (HLSL), and I need to pack a color value into the R32 format. I've found various pieces of code for packing a float into the R8G8B8A8 format, but none of them seem to work in reverse. I'm targeting SM3.0, so (afaik) bit operations are not an option. To sum it up, I need to be able to do this: float4 color = ...; // Where color ranges from 0 -> 1 float packedValue = pack(color); Anyone know how to do this? UPDATE I've gotten some headway... perhaps this will help to

Creating a black filter for a custom ShaderEffect

假如想象 提交于 2019-12-13 19:36:52
问题 I am using this code example to adjust brightness and contrast on a BitmapImage for my WPF app. The relevant bit of HLSL code is this: sampler2D input : register(s0); float brightness : register(c0); float contrast : register(c1); float4 main(float2 uv : TEXCOORD) : COLOR { float4 color = tex2D(input, uv); float4 result = color; result = color + brightness; result = result * (1.0+contrast)/1.0; return result; } What I would like to do is add something to filter out low intensity pixels- the

find out which polygon were front facing (drawn) after the rasterization stage

ぐ巨炮叔叔 提交于 2019-12-13 18:25:22
问题 I want to be able to access the polygon id (PrimitiveID) of the the front facing polygons of a mesh. I can only see this happening after the rasterizer stage, in the pixel shader. I was thinking about creating an append buffer but since the pixel shader is executed multiple times it might append the same polygon id more than once. I also thought about creating an array boolean variables and using the primitive id from the input assembler stage in the pixel shader as an index and set it to

Is it legal to copy contents of one hlsl array to another using assignment on these arrays?

陌路散爱 提交于 2019-12-13 15:18:45
问题 In HLSL I have two arrays: int arr1[2]; int arr2[2]; I need to copy contents of arr1 to arr2 . Should I iterate through every element? arr2[0] = arr1[0]; arr2[1] = arr1[1]; Is there any specific HLSL tool (like memcpy() in C / C++ )? Or could I just write arr2 = arr1; and that will work for me? 来源: https://stackoverflow.com/questions/54041733/is-it-legal-to-copy-contents-of-one-hlsl-array-to-another-using-assignment-on-th

Mismatch between input assembler and vertex shader - but it looks right

余生颓废 提交于 2019-12-13 05:26:32
问题 I had a similar issue someone kindly solved here, but that led me to this one. The error is: "Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (SV_POSITION,0) as input, but it is not provided by the output stage." Here is my declaration and the vertex shader input. Can anyone tell me why they wouldn't match? I'm stumped. static const D3D11_INPUT_ELEMENT_DESC vertexLayout[] = { { "SV_POSITION", 0, DXGI_FORMAT