FAQ Database Discussion Community


Porting Directional Light from OpenGL to DirectX11

opengl,directx,glsl,hlsl
I am porting my GLSL Directional Light Shader from OpenGL to DirectX11. My LightDirection is (1,0,0) (from left to right in the pictures) The Shader in GLSL looks like this: #version 330 core uniform sampler2D DiffuseMap; uniform sampler2D NormalMap; uniform sampler2D PositionMap; uniform sampler2D DepthMap; uniform vec3 LightDirection; uniform vec3...

Shader - Performance and functions

opengl,directx,glsl,shader,hlsl
I am creating vertex and fragment shaders and I would like to know if using functions inside my shader, for better readability, could have an impact on performance and optimisation.

How to use a huge array in HLSL (error X4505)

arrays,directx,shader,hlsl
When I try to compile I get the error: X4505: sum of temp register and indexable temp registers exceeds limit of 4096. However my shader does work in FX Composer. The reason it crashes is probably because I use a very large array since I'm using marching cubes. const static...

Draw effect XNA with multiple texture

c#,xna,hlsl
In Xna I would like to draw my model with a custom effect.. SO I would like to get the textures from the mesh. foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { effect.Parameters["World"].SetValue(World ); effect.Parameters["View"].SetValue(View); effect.Parameters["Projection"].SetValue(Projection); effect.Parameters["TextureEnabled"].SetValue(true); var basicEffect = part.Effect as BasicEffect; if (basicEffect !=...

Shader - Simple SSS lighting issue

opengl,directx,glsl,shader,hlsl
I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface...

Direct3D 11/HLSL Texture3D False Error?

direct3d,hlsl
I am getting this error: D3D11 ERROR: ID3D11DeviceContext::Dispatch: The Shader Resource View in slot 0 of the Compute Shader unit is using the Format (R32G32B32_FLOAT). This format does not support 'Sample', 'SampleLevel', 'SampleBias' or 'SampleGrad', at least one of which may being used on the Resource by the shader. This...

Efficient way to generate normal map (from height) for all 360 degrees of a rotated image

opengl,glsl,shader,hlsl,normals
I already have a shader that generates a normal map from a height map. Now I need to apply the effect to all 360 degrees of the rotated heightmap. Of coarse I could just apply the effect 360 times to each heighmap, but if I have already done it once...

Draw a sphere on a billboard with world normal from a pointlist

3d,directx,shader,hlsl
I am drawing spheres on billboards by passing center world positions via a StructuredBuffer and use the geometry shader to build a billboard facing the camera. The sphere is drawn correctly and I can figure out the UVs. Now I would like to light it but I cannot figure how...

Rendering a circle with a Vertex shader in DirectX

shader,hlsl,directx-9
I am trying to draw a simple 2D circle by manipulating texcoord coordinates inside a vertex shader. This is the code: float2 uv2 = 2.0 * (TextureCoordinate.xy - 0.5); float tnm = 1.0 - length(uv2); In pixel shader, this draws a circle. The same code inside the vertex shader would...

Shader's function parameters performance

opengl,directx,glsl,shader,hlsl
I'm trying to understand how passing parameters is implemented in shader languages. I've read several articles and documentation, but still I have some doubts. In particular I'm trying to understand the differences with a C++ function call, with a particular emphasis on performances. There are slightly differences between HSLS,Cg and...

DX11 Compute Shader writes only to one index

c++,hlsl,directcompute
I really can't figure out what's going on here. I have a compute shader that takes in an FFT result (from real input) and computes the powers of each bin, storing them in a different buffer (UAV). The FFT implementation is that of the D3DCSX library. The shader in question:...

Does a float3 in a constant buffer secretly add padding?

c#,directx,padding,hlsl,sharpdx
I have a cbuffer in my shader.fx file, like so: cbuffer lights : register (b1) { float4 Light1Color; float3 Light1Direction; float4 Light2Color; float3 Light2Direction; float4 Light3Color; float3 Light3Direction; } I had some issues filling this cbuffer from my code, it ended up being an array of the following struct: struct...

Issues refactoring GLES30 shader?

opengl-es,textures,glsl,shader,hlsl
I'm currently rewriting a shader written in GLES30 for the GLES20 shader language. I've hit a snag where the shader I need to convert makes a call to the function textureLod, which samples the currently bound texture using a specific level-of-detail. This call is made within the fragment shader, which...

Can't get texture.Sample to work, although I can get texture.Load to work fine in Direct 3d 11 shader

hlsl,texture2d,pixel-shader,direct3d11
In my HLSL for Direct3d 11 app, I'm having a problem where the texture.Sample intrinsic always return 0. I know my data and parameters are correct because if I use texture.Load instead of Sample the value returned is correct. Here are my declarations: extern Texture2D<float> texMask; SamplerState TextureSampler : register...

HLSL Particle system will not display

c++,directx,directx-11,hlsl,particle-system
I have been trying to add a particle system to my Directx11 graphics demo, and so i have been using the 'Introduction to 3d Game Programming with directx 11' book. Because of this am attempting to use a HLSL StreamOut technique to update the particle system and a separate technique...

Constant buffer is empty when passed HLSL C++

c++,directx,shader,hlsl
So I moved from this problem: Previous problem to this one :). I made 2 constant buffers in C++ which I'm passing to my HLSL Shader but when I debug and look into the buffers they are just filled with zeros except the last 3 numbers (which are -572662307). I...

D3D11 Post Shader Results in Dark Image

c++,directx,direct3d,hlsl,direct3d11
I'm trying to implement post shaders (pixel shaders) as a test. I have a texture to which all stuff is rendered, and the post shader simply copies this texture to the back buffer. If this texture is larger than the back buffer, the post shading process results in dimming: However,...

Directional per-face lighting using Geometry Shader?

directx,hlsl,normals,geometry-shader
Because of limitations I have to calculate vertex normals inside my geometry shader. Because of this limitation the normals are per-face instead of interpolated between faces on the vertex, meaning per-pixel directional lighting is just a waste. Because the normals are only known from the Geometry Shader onward, I can't...

Wrapping texture coordinates manually

c++,filter,textures,wrap,hlsl
Edit: I have identified the problem to be similar to the question here but I still can't come up with a solution since my problem is a little different. I am using C++ and HLSL and need to have my texture coordinates wrap so that the texture is tiled across...

Geometry shader output filling Z-Buffer with closest value possible? (DirectX)

c++,directx,shader,hlsl
I need lines of a certain thickness in my CAD viewer and found out that I should use a geometry shader to accomplish this. I then went ahead and found demo code of a geometry shader that creates lines at a given thickness. Here: https://github.com/paulhoux/Cinder-Samples/blob/master/GeometryShader/assets/shaders/lines1.geom Discussion about it here: https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader...