Hot answers tagged

10

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 ...


7

There are 2 issues in your synthetic sample: The first issue is that you are calling target.GetDataAsImage which is unoptimized in scenarios where you need to do it each frame. Internally the GetDataAsImage is creating a CPU/GPU staging resource (same size as the render target) and allocating an Image on the CPU (again same size on the render target). A ...


6

As catflier mentionned, moving from a "high level" framework like XNA to a low level Direct3D11 API would require quite some work in order to achieve the same results. But there are now some options that you could also consider: Use new SharpDX.Toolkit, which is basically a XNA like API on top of Direct3D11 API, running on Windows Desktop, WinRT and WP8. ...


6

I'm not familiar with SharpDX but I know a bit about the native xaudio C++ API. You can't call DestroyVoice() in a callback at least in the native API which I assume StreamEnd delegate is a just a thin wrapper for OnStreamEnd() callback in the native API. A workaround may be queuing the sourceVoice to a "deleteList" in the OnStreamEnd callback and deleting ...


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 valid formats for typeless Direct3D11 depth buffer are: DepthStencilBuffer: DXGI_FORMAT_R16_TYPELESS (instead of typical DXGI_FORMAT_D16_UNORM) DepthStencilBufferView: DXGI_FORMAT_R16_FLOAT DepthStencilBuffer: DXGI_FORMAT_R32_TYPELESS (instead of typical DXGI_FORMAT_D32_FLOAT) DepthStencilBufferView: DXGI_FORMAT_R32_FLOAT DepthStencilBuffer: ...


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

Back to back draw calls are extremely efficient. It should perform nearly identically to 'hardware instancing' features available in the APIs, aside from the added overhead of calling the API repeatedly. This is how we render relevant on-screen terrain fragments as well as all the random weapons in Borderlands. You can usually consider updating resources (...


4

I think Sprite.Begin will set it's own shader for drawing sprites and overwrite yours. So change the order. sprite.Begin(); effect.BeginPass(i); note: This is how it works with Xna, and i don't think your shader is ready for what sprite.Draw will do


4

I don't know in which case you would like to do this, though I have two cases in mind: If you are creating a Texture2D with an initial DataRectangle, the Pitch must be set to the number of bytes per row and is theoretically equal to TextureWidth * SharpDX.DXGI.FormatHelper.SizeOfInBytes(Format.XXX), unless you are laying out your data differently in memory....


4

Good news! Alexandre Mutel, the author of SharpDX, let me know that Microsoft removed the "helper methods" from Direct3D11. It wasn't an omission by SharpDX. And he also pointed me in the right direction; to use WIC to load my textures. I found sample code here: http://crazylights.googlecode.com/svn/CLReach/win8/SDX_CLGC/clgc.cs I just needed two of the ...


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

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

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

in the meantime i found out that it does use OpenGL for windows desktop and DirectX for windows 8 metro.


3

Could the problem be caused by an underflow due to the large values in the OrthoOffCenterLH projection? Don't know exactly what you mean. But no, this seems to neither be an issue with precision or overflow/underflow. What parameters do I have to pass for x,y,width,height in Unproject(...)? Straight from the documentation (x,y) is the location of the ...


3

You could try HQx or xBR filters. They are used e.g. in NES / SNES emulators to upscale pixel graphics.


3

There's a few options, since you mention SharpDX i guess you want to stay in c#. If you move to SlimDX/SharpDX, there's few things to take into consideration (which are also DirectX related) From DirectX10+, you have no more fixed function, so you will need to create shaders for your rendering. Also there's not really any proper built in model loader, so ...


3

Interesting problem. Staring at the picture and thinking about the problem I think a set of feelers might be the way to go. What you do is just put a couple vectors (lines or whatever) on each side of the agent and each time step you test if they are in a wall or not. If they are in the wall you steer away from it. So if your touching the right one you ...


3

Okay, first of all, I would like you to consider forfeiting the notion of "best practice". There are no such things as "best practices". Some things work, some don't, and none do under all assumptions and scenarios, therefore being "best". Every time you use the words "best practice", God kills a kitten, so please think of the kittens. Now, onto your ...


3

You seem to be using DirectX, so you can probably use the techniques described in this article. It explains how to use ID3D11Query objects to profile GPU code. Since you're in managed code, you might have to use some clever P/Invoke to get to that API if SharpDX doesn't expose the functions itself, although it seems like it does.


3

I think you are probably misunderstanding the coordinate system in which you are working. Higher numbers for X and Y are not necessarily up and right on the screen. So you're most likely seeing an upside down quad, or your camera is behind the thing you're looking at and you're seeing its back (a double-sided quad will show the mirror image of your texture ...


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

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. ...


2

If you're not a huge C++ fan, then the question I have is, are you already competent at C#? Any way you slice it, DirectX and its related APIs are fairly complex and you will get stuck in some places if this is your first time using a 3D graphics API. Because they are merely wrappers, they involve low-level stuff that you have to deal with on your own. If ...


2

Don't know much about internals of MonoGame, but texture are definitely not stored in a ConstantBuffer. The texture is not a constant buffer, it is a texture which has its own slot and is bounded completely separetly from the ConstantBuffer. To get the slot of the texture, this is done through the ShaderReflection object and method reflect....


2

tex2D(sampler,pos) return values between 0 and 1. Multiply by 255.0 to get your expected range.


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