Hot answers tagged hlsl
27
coderanger is right about HLSL targeting DirectX, GLSL targeting OpenGL and CG being available with both interfaces.
However there are other things to consider (learned on the OGRE forum) :
CG will not allow you to use the latest features of GLSL (I'm not sure about HLSL). It's a middle ground so you'll not be able to fully exploit the GLSL features, only ...
25
A wide-angle lens should not behave differently than other regular lens models. They just have a larger FOV (in the D3DXMatrixPerspectiveFovLH sense -- I'm assuming you use DirectX), or larger left/right and bottom/top values (in the OpenGL glFrustum sense).
I believe the really interesting part lies in modeling the fisheye lens. There's Fisheye Quake that ...
14
Your dilemma hints at a larger problem that's well-known to the graphics programming community, commonly referred to as "combinatorial shader explosion." As the name implies, it's usually considered in the context of very large numbers of shader permutations, but the basic principle is the same. Solutions geared toward solving the overarching problem are ...
14
HDR techniques allows you to simulate a greater range of detail than you can view on screen than with traditional lighting/textures. You can compare it to how the eye behaves when exposed to different amounts of light - when there's too much light the eye lets less light in so things are still in your visible range. When there is not enough light, the iris ...
13
I can only talk about CG vs HLSL because those are the 2 I have used so far.
Cg is not the same as HLSL.
In Cg, NVIDIA did an excellent job in creating a very clean shader syntax. Its very similar to HLSL.
But, tie-together with D3D9/D3D11 (init code, shader compilation code) is much cleaner on HLSL than Cg. -1 Cg. Cg has a nasty bit of start up code ...
12
Depends on how the texture is defined I suppose - I haven't used XNA, but textures (or texture stages) generally have options on whether to wrap, mirror or clamp.
In OpenGL, the wrap type is defined on the texture object, on DirectX it's set in texture stages. Both have their good and bad sides.
Common wrap types include:
Clamp to edge - repeats the ...
11
How does it like......know to
change....Im confused exactly at the
pipeline between HLSL and the actual
Pixels/Vertex on the screen.
It works roughly like this: when you issue a draw call (DrawPrimitives, DrawIndexedPrimitives in D3D, Draw in 10+, et cetera), the geometry data you've bound to the pipeline (your vertex buffers) are processed. For ...
11
Make a flood fill from the player's position; every area "flooded" is then a valid play area, and all others are walls.
EDIT: As to the "reachable in a straight line" additional requirement, keep in mind that in a discrete space, you have to define this a bit further. For example, all of the paths above could be a valid "straight line" in such an ...
10
Neat idea for the game. The problem is that light really doesn't look like this. Light decay is NOT gausian :). That's for the begining. What i want to propose is adding simple (but relatively physicaly correct) fog or dust. Mean volumetric effect. You will have to implement volumetric raycasting on the gpu. Don't panic. It is not that hard as it might ...
9
I'll try to explain how things work without using much jargon.
If simplicity rather than interactive speed is your concern, a 3D surface in the computer would be just a huge cloud of points in space, dense enough so we can just render each point individually, without gaps between them.
You want to store a model only once in memory, but you need to display ...
9
Many rules for micro-optimising shaders are the same as for traditional CPUs with vector extensions. Here are a few hints:
there are built-in test functions (test, lerp/mix)
adding two vectors has the same cost as adding two floats
swizzling is free
It is true that branches are cheaper on modern hardware than they used to be, but it is still better to ...
9
My impression is that this color is essentially a fog color, thinking of the water as being a fog volume with a shiny surface. The simplest thing to do is probably to just let your artists pick a shallow color and a deep color, and lerp between them based on the depth. Something like:
lerp(shallowColor, deepColor, saturate(depth * depthColorScale));
...
8
Another crucial difference between HLSL and GLSL (I don't know CG so I can't speak for it) is that with HLSL Microsoft provide the shader compiler as part of the D3D runtime whereas with GLSL your hardware vendor provides it as part of their driver.
This has advantages and disadvantages on both sides.
With the GLSL method the vendor can tune the compiler ...
8
The problem is that XNA on Windows Phone doesn't have custom shader support - so you can't write a vertex shader or pixel shader. However, you can use a trick described by Catalin Zima that deforms a vertex grid to achieve the same effect.
If you are not targetting Windows Phone 7, you can use a trick that I described on my blog. Copying the relevant bits ...
8
Pseudo random numbers in a pixel shader aren't easy to obtain. A pseudo random number generator on the CPU will have some state which it both reads from and writes to, on every call to the function. You can't do that in a pixel shader.
Here's some options:
Use a compute shader instead of a pixel shader - they support read-write access to a buffer, so you ...
7
If you want to speed things up you can use something called a texture atlas.
Wikipedia — A texture atlas is a large
image, or "atlas" which contains many
smaller sub-images, each of which is a
texture for some part of a 3D object.
The sub-textures can be rendered by
modifying the texture coordinates of
the object's uvmap on the atlas,
...
7
I don't know if the answer you are looking for exists, but personally I don't like the idea of independently generating values that you hope will end up identical.
I'm assuming that the map data is something you only generate once in the beginning of the scene. If so, much better to generate the data once, and use it twice. You should either generate the ...
7
The ID3D11Buffer references an actual chunk of memory that holds your data, whether it's a vertex buffer, constant buffer, or whatever.
Constant buffers work the same way as vertex buffers and other kinds of buffers. Namely, the data in them isn't accessed by the GPU until it actually renders the frame, so the buffer has to remain valid until the GPU is ...
6
Practical answer: No (in SM 3.0; apparently you can in SM 4.0, but I haven't checked.)
Technically the answer is yes, as it is legal HLSL. But if the sampler index cannot be determined at compile time, then compilation will fail because there is no way to express this as a GPU instruction.
So, you can only select a sampler by index if that index is ...
6
You are probably hitting 100% CPU because you are at the batch limit. You get a few hundred batches per frame. A batch is basically equivalent to a call to one of the GraphicsDevice.Draw* functions.
You probably want to read this answer.
While you can reduce the number of batches with instancing, because your geometry is so simple you are probably better ...
6
There are three steps:
Load effect and set the technique
Provide data to the effect
Render
1) Load effect and set the technique
// Declaration of your effect variable
LPD3DXEFFECT mDSEGeometryStage;
...
initEffects()
{
//With this method you load your effect file
HR(**D3DXCreateEffectFromFile**( d3ddev, ...
6
Unfortunately no. You cannot read from the current render target in a shader. You have two basic options:
If the operation you would do with the read fragment color is simple enough that you can achieve it using blend state operations, you can use those.
You can pass the color data you need into shader via some other resource, for example, a texture ...
6
I've managed to get it working with a few minor changes to the sample. Here's the steps I took, but let me know if you need additional help.
On the BloomComponent Class
Add a new private RenderTarget2D instance to the BloomComponent class. I called it finalRenderTarget (Line 29).
Add a public getter FinalRenderTarget so that you can retrieve it from ...
6
Firstly you can do texture fetching inside conditional blocks in HLSL. tex2Dlod() and tex2Dgrad() will work fine inside one. It's just tex2D() that won't compile, and you can work round that by computing ddx() and ddy() outside the conditional and using tex2Dgrad().
To reliably stop the texture fetch (or any other block of code) being executed in HLSL, use ...
6
Bitwise operations and integer operations were new for SM 4.0/DX10. As your error says:
Bitwise operations not supported on legacy targets.
You'll have to target DX10.
Alternatively, this blog post suggests using a texture to map results of AND,OR,XOR to different color channels.
bitwise operators texture: AND,OR,XOR
Seems plausible, and might be ...
6
You can use your pixel shader approach but it is incomplete.
You will also need to add some parameters to it that inform the pixel shader where you want your stencil to be located.
sampler BaseTexture : register(s0);
sampler MaskTexture : register(s1) {
addressU = Clamp;
addressV = Clamp;
};
//All of these variables are pixel values
//Feel free to ...
6
Using the stencil buffer.
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.Transparent, 0, 0);
var m = Matrix.CreateOrthographicOffCenter(0,
graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
0, 0, 1
);
var a = new ...
6
The fragment shader is executed for each fragment with a single uv for this fragment which will probably never fall perfectly on 1.
You could map the target area roughly to the width of a render target fragment.
Eg something like:
abs(hyp - 1) * CircleRadiusInPixel < BorderWidthInPixel*0.5
Further explanation:
Your gpu rasterizes the triangles and ...
6
Well, a lot of stuff happens between the Vertex and Pixel shaders, but before we get into that, I'm worried that you may be a bit confused about what the Vertex and Pixel shaders do. So let's quickly go through the entire Direct3D 9 programmable pipeline again. This nice chart shows the entire pipeline, and you should print it out for reference.
(feel free ...
5
Or is this somehing that normal
mapping doesn't require?
That's right, normal mapping doesn't require this.
In most cases the best way to do normal mapping is to store the normal map normals in tangent space. That is, a normal in the normal map pointing in the same direction as the surface normal is <0,0,1>. (This is why many normal maps are ...
Only top voted, non community-wiki answers of a minimum length are eligible
