Hot answers tagged

11

The Sample method accepts a UV coordinate (where the texture covers the [0, 1] range), does mipmap selection based on the UV derivatives, applies addressing modes (clamp, wrap, border) and does filtering (bilinear, trilinear, aniso). The Load method accepts a texel coordinate in the [0, textureWidth - 1] x [0, textureHeight - 1] range, and the desired mip ...


6

Loading up DirectX (via SharpDX or XNA) to do the conversion is probably overkill. Why not simply decode the format on the CPU? It's simple enough. There is a DXT decoder in MonoGame you might be able to borrow. (In case the file changes, the latest revision at time of writing is here.) BC3_UNORM is equivalent to DXT5, which that will happily decode. You'...


5

The depth buffer is not linear. More bits of precision are available closer to the camera and so changes in depth close up end up being very tiny changes that don't convert to color differences you could actually see. Dividing by w linearizes the depth buffer such that small changes in depth result in visible changes in color. http://www.gamedev.net/topic/...


4

Assuming Z is the vertical axis, the orientation in the XY plane can be computed using atan2: float dx = target.x - position.x; float dy = target.y - position.y; yaw = atan2(dy, dx); And same for the elevation angle: float dz = target.z - position.z; pitch = atan2(dz, sqrt(dx * dx + dy * dy));


4

Well for antialiasing there are many approaches like yours, downsampling an oversampled picture, which is very costly. Using a renderTarget seems also overkill to me. The best option would be to make a custom shader for you SpriteBatch that does parametric sphere ray-casting (not that expensive, was working on my old Sony Ericsson Mini Pro). You can apply ...


4

There are two basic ways to update a buffer. Use DeviceContext.UpdateSubresource(). source is your source data, in the form of a DataBox (you can pass most value types and arrays as DataBox), and resource is your vertex buffer. This is the easiest way to copy small data in one pass, and I use it mostly for updating constant buffers. In your case it could ...


4

Sorry for not posting a complete solution, but I have done something relatively similar to what you're doing. You may be able to adapt this idea into your program. What I did was output a video file into a Direct3D 9 (not 11) texture for rendering. I'm pretty sure it was possible to select a webcam as a video source instead of a video file, so in general ...


3

Anisotropic filtering does not alter the size of the texture. Anisotropic filtering allows the texture to be probed at a different rate on each axis, versus isotropic filtering (linear, bilinear, trilinear...) which must be probed at the same rate on each axis. Anisotropic filtering is primarily to solve the problem of texture blurring at highly oblique ...


3

Ok, I'll give it a shot... Your camera will need much of the same functionality as your regular entities in the game. Specifically, it will need to have both a position and orientation in your game world. A simple 3D vector can be used to store the world position whilst a unit quaternion can be used to represent its rotation from some reference direction. ...


3

When using an Effect in the Toolkit (which is similar to the XNA Effect or the native D3D11 Effect API), you are not suppose to access directly the constant buffer but instead setting parameters directly on the effect: _effect.Parameters["slideX"].SetValue(0.0f); _effect.Parameters["sinPi075"].SetValue((float)Math.Sin(Math.PI * 0.75)); _effect.Parameters["...


3

I don't know what vertex data you're using to draw that, but supposing it is a cube, I wouldn't say that the perspective is VERY wrong, or even wrong at all, on the left picture. Based on your commented-out code, your ultimate view-projection matrix is getting calculated like this: identity * translation * projection * rotation Your drawing is getting ...


3

I have two methods for doing this I will post them both. Code is in VB.net and using sharpDX 3.0.2 Basically you copy your texture data to a staging resource and then write that staging resource to disk using WIC. If I recall I may have pulled this out of the SharpDX.Toolkit, DrawContext is just a wrapper around Device context so it should just be a name ...


2

Alpha has nothing to do with the depth test. All vertex shader outputs just get interpolated across the pixels, and don't change based on per-pixel visibility. In your example, if an alpha parameter is output from the vertex shader as 0 at one end and 1 at the other end of the rectangle, it will be 0.5 in the center.


2

The depth it is referring to is the depth value of a pixel, often (though not always) on a scale of 0 - 1 (relative, although usually nonlinearly, to the near plane and far planes). This value is used for something called depth testing, or z-testing. Depth testing is an optimization that prevents pixels from being written to the buffer if they would be ...


2

Instancing requires to change the InputLayout of vertex buffers and pass an instancing buffer along the mesh vertices. Unfortunately, there is nothing automatic to do this with Toolkit models, though possible but would require to dig into the internals to do this yourself. Before even trying to do some instancing with models, you should start with a basic ...


2

If I would have to solve this I think I would use a simple small gaussian blur. As a shader this shouldn't be that big performance issue and simple to implement, and also be a very nice-looking approach.


2

This typically happens when calling a D3D function with an invalid parameter (e.g. a NULL pointer where not permitted). This is exactly what the SwapChain's constructor documentation says: InvalidCallException The method call is invalid. For example, a method's parameter might contain an invalid value. You need to check one by one the parameters you ...


2

Unfortunately, the toolkit doesn't support inline definition of sampler in the shader (as legacy fx does). In order to use a sampler, you need to: Simply declare a plain sampler state in hlsl: SamplerState MySampler; Pass a sampler state from C# available in GraphicsDevice.BlendStates (or create your own) and set it on the parameter effect.Parameters["...


2

The problem is that you don't sort your polygons here thus can not use alpha blending properly. The common ways to resolve this are: Alpha testing: discard the pixels which are below a certain alpha threshold so that you gain proper Z buffering, Z discard. This results is hard edges when looked from up close. Alpha to coverage: you have to set up a blend ...


2

I guess that the problem lies in here: _up = Vector3.TransformCoordinate(Vector3.Up, rotateYTempMatrix); You're calculating the up vector (and also the rest of them) from a matrix unrelated to the cameraRotationMatrix matrix, in which you have stored the new rotation. Usually, what I do is multiply an old rotation matrix by the new rotation ...


2

As already mentioned in the comments, you cannot specify your sampler states in the shader unless you use the effect framework. To utilize sampler states without the effect framework specify their location with the register keyword: sampler anisotropySampler : register(s0); sampler pointSampler : register(s1); Then initialize the slots with the following ...


2

A couple of things i try to do first to debug it. For your ui just set the pixel shader to write out white with alpha set to 1.0f. If that is rendering and is no longer transparent then you can localize it. But if not i would also look at your blend state. I assume your ui isnt using a zbuffer? If it is then is it cleared every frame? You are ...


2

On the right hand side of the page is a list of actions. On the bottom, it says "Download Package". It prompts a download of the nuget package, which I believe is what you want. This is the link: https://www.nuget.org/api/v2/package/SharpDX/4.2.0 About Nuget: To use a nuget package, you need a nuget package manager. Alternatively, you can open them with a ...


2

A vector to your camera's right is the same as the forward vector of a camera that's looking 90 degrees further in yaw, and at zero pitch. So you can modify your look vector code to give you your right vector. var rx = Math.Cos(yaw); var ry = 0; var rz = -Math.Sin(yaw); this._right = new Vector3(rx, ry, rz); (Here I used the identities that Sin(a + 90°) = ...


1

Something like this could help? public static Joystick[] GetSticks() { var sticks = new List<SlimDX.DirectInput.Joystick>(); foreach (DeviceInstance device in Input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { // create the device try { ...


1

If you make a light structure and send that as an array it should work, also maybe use two constant buffers? Looks something like this(HLSL): struct Light { float4 vLightDir; float4 vLightColor; }; cbuffer Camera : register(b0) { matrix mWorld; matrix mView; matrix mProj; } cbuffer Lights : register(b1) { Light lights[]; } C# [StructLayout(LayoutKind....


1

You could use a lookup texture for the alphabet. Then draw a quad for every letter and select the right letter by texture coordinates. You don't use transformation matrixes on this of course. This is a simple way to get started. Advanced font rendering is a complex topic and you might want to use a library like FreeType for that. However, the basic ...


Only top voted, non community-wiki answers of a minimum length are eligible