hlsl

HLSL: Enforce Constant Register Limit at Compile Time

青春壹個敷衍的年華 提交于 2019-11-28 14:27:41
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 problem is especially annoying as the compiler itself allocates constant registers behind the scenes, on

How much performance do conditionals and unused samplers/textures add to SM2/3 pixel shaders?

前提是你 提交于 2019-11-27 20:25:09
问题 We've one pixel shader in HLSL which is used for slightly different things in a few places, and as such has several conditional blocks meaning that complex functionality is omitted in some cases. As well, this means we pass textures as sampler parameters which may not always be used. I have no idea how much of a performance hit these two things add but especially since we support SM2.0 on integrated graphics chips, inefficiencies are an issue. So, does passing a texture in and not using it

Can I generate a random number inside a pixel shader?

耗尽温柔 提交于 2019-11-27 12:56:11
I'm trying to write a very simple shader that adds random sparkle to applicable objects. The way I'd like to do this is by adding a random shade of white (R = G = B) to the pixel value within the pixel shader. It seems that noise() doesn't work the way I hope it does: float multiplier = noise(float3(Input.Position[0], Input.Position[1], time)); It gives me "error X4532: cannot map expression to pixel shader instruction set" referring to the call to noise() . Since I don't know of a way to retain a number between calls to the shader, I don't think I can just write a simple random number

Does If-statements slow down my shader?

妖精的绣舞 提交于 2019-11-27 06:08:43
I want to know if "If-statements" inside shaders (vertex / fragment / pixel...) are realy 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-statements are realy bad for the performance of the shader. Also here they are talking about how much is inside

How to achieve smooth tangent space normals?

久未见 提交于 2019-11-27 02:02:45
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 the values are then stored as a part of model's geometry. vector1 = vertex2.coords - vertex1.coords;

Can I generate a random number inside a pixel shader?

巧了我就是萌 提交于 2019-11-26 16:22:29
问题 I'm trying to write a very simple shader that adds random sparkle to applicable objects. The way I'd like to do this is by adding a random shade of white (R = G = B) to the pixel value within the pixel shader. It seems that noise() doesn't work the way I hope it does: float multiplier = noise(float3(Input.Position[0], Input.Position[1], time)); It gives me "error X4532: cannot map expression to pixel shader instruction set" referring to the call to noise() . Since I don't know of a way to