hlsl

Sort algorithm with fewest number of operations

What is the sort algorithm with fewest number of operations? I need to implement it in HLSL as part of a pixel shader effect v2.0 for WPF, so it needs to have a really small number of operations, considering Pixel Shader's limitations. I need to sort 9 values, specifically the current pixel and its neighbors. ...

Fastest implementation of the frac function in C#

I would like to implement a frac function in C# (just like the one in hsl here http://msdn.microsoft.com/en-us/library/bb509603%28VS.85%29.aspx) but since it is for a very processor intensive application i would like the best version possible. I was using something like public float Frac(float value) { return value - (float)Math.Tru...

how use shader effects in XNA

how use shader effects in XNA? ...

HLSL: Empty fx file: X3000: unexpected token '{'

The following error appears: Test.fx(1,1): error X3000: syntax error: unexpected token '{' Text.fx contains this: Nothing. I also tried it with an effect file that works fine in another test project: float4x4 mWorld; struct TInputVertex { float3 vPosition : POSITION0; float3 vNormal : NORMAL0; float2 vTexCoord ...

Are there major differences between shader languages?

I am currently learning GLSL. It would seem that once you learn one of the shader languages, learning one of the others would not be too difficult. Is it something analogous to learning a widget toolset like wxWidgets and then switching to Qt? Once you get the idea of what is happening within one widget toolset, another toolset will d...

How do you display something using directX 11 compute shader?

I am wanting to write to a texture from my directX 11 compute shader. However I have no idea how to display this onto the screen nor am I sure what sort of buffer I should be using to do this. ...

System.AccessViolationException storing a variable with reflectio.emit

Hi, I'm building a compiler with reflection.emit in my spare time, and i've come to a problem that i'm not understanding. A little context, I've a runtime with a couple of types and one of them is Float2, a simpler vector struct with two float values (X and Y). I've made a couple of properties that allow me to swizzle the values (a la h...

D3D10 HLSL: How do I bind a texture to a global Texture2D via reflection?

Ok so assuming I have, somewhere in my shader, a statement as follows (Note I am enabling legacy support to share shaders between DX9 and DX10): Texture2D DiffuseMap; I can compile up the shader with no problems but I'm at a slight loss as to how I bind a ShaderResourceView to "DiffuseMap". When I "Reflect" the shader I rather assu...

Silverlight: Polygon in combination with Pixel Shaders

Hello everyone, I am new to Silverlight and I got a small problem with effects in combination with polygons. I want to achieve that the rendering of the shader is only inside the edges instead of also outside the edges. As you see the brush is doing this, but not the output of the shader. Anybody knows a solution to fix this? Is there a...

XNA + Pixel Shader Difficulties

I've written a basic 2d pixel shader, and i can't seem to get it to work. If i draw with the effect active, then nothing draws to the screen. But if i disable it, then the texture draws to the screen as expected. My aim is to be able to draw an arbitrary texture to the screen, then have this pixel shader "carve" circular hunks of pixel...

Tutorials for writing 2D shaders?

I am needing to write some 2D shaders (not 3D, so no vertex shader code or any of that) in HLSL, but have a lot of trouble finding good tutorials. Do you have any resources I can use? ...

rightrotate without bitwise operators

How can I implement the rightrotate (and leftrotate) operations on 32 bit integers without using any bitwise operations? I need this because High Level Shader Language (HLSL) does not allow bitwise oeprations upon numbers, and I need rightrotate for a specific shader I'm trying to implement. ...

HLSL Shader to Subtract Background Image

I am trying to get an HLSL Pixel Shader for Silverlight to work to subtract the background image from a video image. Can anyone suggest a more sophisticated algorithm than I am using because my algorithm isn't doing it correctly? float Tolerance : register(C1); SamplerState ImageSampler : register(S0); SamplerState BackgroundSampler...

How do you count registers in HLSL?

With shader model 2.0, you can have 256 constant registers. I have been looking at various shaders, and trying to figure out what constitutes a single register? For example, in my instancing shader, I have the following variables declared at the top, outside of functions: float4x4 InstanceTransforms[40]; float4 InstanceDiffuses[40]; ...

Error with short form opcodes in Reflection.Emit

Hi. I'm making a small language that is very similar to hlsl but supports only pixel shaders. This language uses reflection.emit to build dot net assemblies that implement the same functionality. I'm currently testing my implementation of the branch instruction "if" and in one of my unit tests (a large if with inner if else's) failed wit...

HLSL: Using arrays inside a struct

I came across a weird behavior of HLSL. I am trying to use an array that is contained within a struct, like this (Pixel Shader code): struct VSOUT { float4 projected : SV_POSITION; float3 pos: POSITION; float3 normal : NORMAL; }; struct Something { float a[17]; }; float4 shMain (VSOUT input) : SV_Target { Someth...

Are there any shader inputs other than TEXCOORD that wpf supports

I know that you can tie constant registers to dependency properties as well as tie a brush to a sampler, but every example I have seen of a wpf shader uses the declaration main( float2 uv : TEXCOORD ) : COLOR I am a complete newbie to HLSL but I know there are other semantics than TEXCOORD. Can any of them be used with a WPF shader? ...

Dynamically compiling and running shaders from file in XNA

Hello, im wondering if its possible to dynamically compile a pixel-shader from file and apply it to a mesh. First I'll just start with some background information. I have a system which creates HLSL pixel-shaders based on a range of data which is not really important to the question. What is important is that these shaders do not use te...

Structure of a HLSL 4 File

Hi, I'm new to HLSL programming and although there are many nice hello-world type examples on the internet, it's difficult to know how I should be structuring my HLSL files. For example I have a HLSL file called DrawImage which is just used for drawing 2D billboard-type images on-screen: Texture2D image; SamplerState Sampler { Fi...

Obtaining minimum and maximum rendered UV values (Direct3D)

I need to calculate the minimum and maximum UV values assigned to the pixels produced when a given object is drawn onscreen from a certain perspective. For example, if I have a UV-mapped cube but only the front face is visible, min(UV) and max(UV) should be set to the minimum and maximum UV coordinates assigned to the pixels of the visib...