Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Mar 2013
Offline Last Active Aug 01 2013 03:22 PM

#5078783 Directional Light

Posted by on 18 July 2013 - 03:02 PM

Are you transforming cameraPos?


If you were using visual studio 2012 you could debug the shader and inspect values after it runs.

#5078053 Compile HLSL at Runtime ?

Posted by on 15 July 2013 - 11:07 PM

It was from SV_POSITION. It used to be VPOS in D3D9.




Also I recommend using visual studio 2012 and compiling offline. My solution used to take 15 seconds to load because it compiled the shaders at run-time. I didn't have that many shaders. I switched to offline compiling and the screen comes up in under a second. It's huge for productivity. And according to some guy I'm not going to cite there's no real advantage to compiling at run-time since it increases loading by so much.

#5077002 Working with Light Shader

Posted by on 11 July 2013 - 08:20 PM

If you are in debug mode for D3D then there should be warnings or errors in the output window of Visual Studio.

#5076982 DX11 - HLSL - Billboarding

Posted by on 11 July 2013 - 05:17 PM

You don't rotate billboards. Billboards always face the camera because they are just 2-D sprites. The only matrix you need to store per instance in your instance buffer is the world matrix. This matrix will have the position and scale of the billboards, such that the further it is the smaller it gets.


Anyway for instancing models this is what I do:


struct InstanceBuffer

Then my shaders (note this is a normal model, not a billboard) look something like this:

PS_INPUT VS( VS_INPUT input, uint iid : SV_InstanceID)
    PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul( input.Pos, InstanceWorld[iid] );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );
    output.Norm = mul(float4(input.Norm, 0), InstanceWorld[iid] ).xyz;
	output.Tex = input.Tex;
    return output;

cbuffer InstanceBuffer : register(b1)
	matrix InstanceWorld[NUM_MAX_INSTANCES];

Someone else can chime in with the max size of the instance buffer. I just guessed 128 for now.


Any time I need to render a batch of instanced models I call UpdateSubresource() with my new instance buffer and then DrawInstanced(). For drawing thousands of models I would probably have multiple DrawInstanced() calls, but I don't know if there is a better way.

#5063960 Health Effect

Posted by on 22 May 2013 - 04:08 PM

Render-to-texture the scene, then make a new shader that combines the rendered image with the blood image (with transparency in the middle).


This is known as a post-process.

#5063344 vertice array

Posted by on 20 May 2013 - 05:22 PM

You can lay out your CUSTOMVERTEX however you want but I am assuming that the first 4 floats correspond to the position as a float4(x,y,z,w) and the last integer is a vertex color 0xRRGGBBAA for red, green, blue and transparency. In the first one it is probably the color teal.


Your input layout determines all of these (D3D11_INPUT_ELEMENT_DESC).

#5063340 How to get multiple textures on a model in DX11?

Posted by on 20 May 2013 - 05:16 PM

If you aren't blending textures then the easiest way is to combine the textures into one. You would have to recompute your texture coordinates.


Otherwise you need an index per-vertex telling you which texture to use in the pixel shader. You can add a uint to the input and output of your vertex shader. Your vertex buffer will need to specify the integer index of the texture for each vertex. The vertex shader will just pass the integer through to the pixel shader. Then change your Texture2D to an array like Texture2D mTexture[3] : register(t0); and call mTexture[input.index].Sample().



If you are doing something like terrain where you want to blend multiple textures then you just need multiple texture coordinates.

#5063306 Shadow mapping - near and far

Posted by on 20 May 2013 - 02:00 PM

If you are trying to cast a large shadow from a small object onto terrain you should be using a directional light (orthographic) since you are imitating the sun. Orthographic projections do not depend on distance so you can make the shadow map perfectly centered around the caster even if it is infinitely far away.

#5057147 Fringes around textures

Posted by on 26 April 2013 - 09:53 PM

Are you sure AddressU and AddressV in D3D11_SAMPLER_DESC for your sampler are set to D3D11_TEXTURE_ADDRESS_CLAMP? I had a border issue with a skybox but when I set it to clamp the border went away.