HLSL is a proprietary shading language developed by Microsoft for use with the Microsoft Direct3D API.
-4
votes
1answer
61 views
how can i improve this shader [closed]
I am trying to improve this vertex shader. I am wondering if anyone has any opinions on going about with it? Thank you.
struct VertexShaderData
{
float3 VertexPosition : POSITION;
float2 ...
-3
votes
0answers
43 views
improve the phong lighting vertex shader [closed]
How can I improve this HLSL shader?
PixelShaderData VertexShader_Light( const VertexShaderData input )
{
// Transformation
float4 WorldPosition = mul( input.VertexPosition, modelworldMat ...
2
votes
1answer
73 views
Switching to a vertex shader
TL;DR I need to switch from a vertex array passed to the pixel shader with a real vertex shader approach.
In my prototype, the terrain is procedurally generated and I have the following result:
...
0
votes
1answer
50 views
Adding Shader Model 3.0 support to my Direct3D9 app
So far, we've only used pixel shaders because we never needed to do any custom processing at the vertex shader level. However, the 3.0 model shader forces you to define a vertex shader. And that's ...
2
votes
2answers
149 views
Why does matrix multiplication lead to different result if it's done on CPU, compared to GPU(shader)?
If I'm calculating a "camera space" on the CPU, by multiplying the view with the projection matrix on the CPU , and afterwards multiplying the world to the result my vertices do not pass to the pixel ...
4
votes
1answer
137 views
What happens to data between vertex shader and pixel shader?
Short version: What can happen to the output of a vertex shader that leads to no(or very few) pixels being drawn, especially in relation to a perspective matrix.
Long version:
My problem refers to ...
4
votes
1answer
148 views
Applying an outline effect to primitives
I am trying to draw an outline on a collection of quads in Direct3D. I have three intersecting quads on the same plane in the following configuration:
(The different colors here are just to ...
0
votes
0answers
36 views
Cascaded Shadow Maps left handed to right handed coord system
Im trying to port the Directx SDK (june 2010) sample (CascadedShadowMaps11) into a right handed version (to later implement in my engine) but i can't figure out the math, so far i got it partially ...
0
votes
2answers
60 views
The saturate function is not working in my pixel shader
I wrote a pixel shader for my game and when I tried to compile it an error occurred:
ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
When I removed all the saturate ...
3
votes
1answer
88 views
Constant Buffer size mismatch on PS, fine on VS and GS
I have the following C/C++ struct:
struct ShadowMapCB {
Math::Matrix4 cropMatrix[4];
Math::Matrix4 textureMatrix[4];
float splitPlane[4];
};
and my HLSL constant buffer:
...
3
votes
1answer
128 views
Per Instance Textures, and Vertex And Pixel Shaders?
How do you implement per instance textures, vertex shaders, and pixel shaders?
Given:
1. Two different model templates in Vertex Buffer, Square & Triangle
2. Instance Buffer with [n] instances of ...
0
votes
2answers
66 views
How to implement input-texture limited alphablending of 2 textures with HLSL?
I try to implement a HLSL shader the does the normal Alphablend with premultiplied colors (just as XNA4 does) but depending on some existing colors. One can think of adding a glow to a 2D terrain ...
5
votes
1answer
136 views
HLSL Circle all white
I have been trying to get my shader code (HLSL) to draw a simple circle but after a day and a half I am getting nowhere. It seems people are using the x^2 + y^2 = r^2 and remap texcoords but I only ...
1
vote
1answer
83 views
Blur offset artifacts
I have simple blur shader which I calculate offsets in:
Piece of vertex shader:
output.texCoord1 = input.tex + float2( texelSize * -4.0f, 0.0f );
output.texCoord12 = input.tex + float2( texelSize * ...
0
votes
1answer
102 views
XNA 3D custom shader/effect gives shakey rendering in the distance
I am rendering a simple flat plane + texture to use as the floor for a game. I'm rendering it using a custom effect I've written.
The problem I have is that the ground in the distance gets a bit ...
0
votes
2answers
122 views
HLSL compiler specification (optimizations)
Can I read somewhere about optimizations that HLSL compiler performs?
For example, in some codes I have different variables that get a constant value (just to let myself adjust the shader with other ...
2
votes
1answer
57 views
Direct3D shader compilation fails with constant buffers
I've been particularly annoyed by a 'bug' for a couple days involving D3DCompile and vertex shaders with constant buffers. I'm assuming the bug is my fault (missing flag or small nuance of the poorly ...
1
vote
1answer
43 views
In the Direct3D 9 Effect API, how do you find the texture variable linked to a sampler?
In Direct3D 9 effect files you can write a sampler state that specifies a texture variable to use, like
Texture2D g_texSkyDome;
SamplerState g_samplerSkyDome
{
Texture = <g_texSkyDome>;
...
0
votes
2answers
217 views
HLSL shader optimization [closed]
The following HLSL shader (without preprocessing) results in 65 arithmetic operations (see below). Can the same effect achieved with <=64 operations?
// Center of "light"
float x;
float y;
// ...
2
votes
1answer
78 views
Nine Patch Images in DirectX
In Android development I found nine patch images very useful to draw images that have a fixed border. When the image is scaled the inner part scales, but the border stays at a fixed size.
I was ...
1
vote
2answers
95 views
Diffuse light direction
I'm learning a tutorial from Rastertek about diffuse light with DX 11, here's the shader code:
float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float3 ...
1
vote
1answer
137 views
MultiTexturing by neighbouring points textures
Visual example:
I've been trying to understand multitexturing for a while now, I've created a terrain generator but have no need for height just yet and I still want one texture to blend over to ...
3
votes
1answer
151 views
Why are some objects not rendering properly?
Here's a button I exported from Blender into a .x format:
Now here it is in the game with BasicEffect applied to everything:
And now with my custom shader:
And there's the problem. While the ...
6
votes
1answer
96 views
XNA Deferred + Forward, Depth Problem?
Im working with my deferred engine in XNA 4.0 and Im combining it with a forwardpipeline to support semi-transparency and other "forward only" effects.
Let me describe what I do:
Render GBuffer ...
5
votes
1answer
194 views
Changing water color based on depth
I'm looking to make a water shader that colors the water based on its depth. Up until now my water shader that I've used has basically been extremely reflective and only looked somewhat blue because ...
1
vote
0answers
140 views
How to simulate objects floating on water without a physics engine?
In my game the water movement is done in a shader using Gerstner equations. The water movement looks realistic enough for a school project but I encounter serious problem when I wanted to do sailing ...
3
votes
2answers
156 views
Which will be faster? Switching shaders or ignore that some cases don't need full code?
I have two types of 2d objects:
In first case (for about 70% of objects), I need that code in the shader:
float2 texCoord = input.TexCoord + textureCoord.xy
But in the second case I have to use:
...
0
votes
0answers
71 views
How to efficiently render resizable GUI elements in DirectX?
I wonder what would be most efficient way to render the GUI elements.
When we're talking about constant-size elements (that can still be moving), the textures' atlas seems to be good.
But what with ...
1
vote
1answer
94 views
Texture the quad with different parts of texture
I have a 2D quad. Let say it's position is (5,10) and size is (7,11).
I want to texture it with one texture, but using three different parts of it.
I want to texture the part of quad from x = 5 to x ...
9
votes
4answers
438 views
Avoid if statements in DirectX 10 shaders?
I have heard that if statements should be avoid in shaders, because both parts of the statements will be execute, and than the wrong will be dropped (which harms the performance).
It's still a ...
1
vote
1answer
154 views
Low-level GPU code and Shader Compilation
Bear with me, because I will raise several questions at once. I still feel, though, that overall this can be treated as one question that may be answered succinctly.
I recently dove into solidifying ...
3
votes
1answer
323 views
In HLSL pixel shader , why is SV_POSITION different to other semantics?
In my HLSL pixel shader, SV_POSITION seems to have different values to any other semantic I use. I don't understand why this is. Can you please explain it?
For example, I am using a triangle with the ...
1
vote
1answer
95 views
Confusion on HLSL Samplers. Can I Set Samplers Inside Functions?
I'm trying to create a system where I can instance a quad to the screen, however I've run into a problem. Like I said, I'm trying to instance the quad, so I'm trying to use the same geometry several ...
1
vote
2answers
267 views
HLSL Pixel Shader that does palette swap
I have implemented a simple pixel shader which can replace a particular colour in a sprite with another colour.
It looks something like this:
sampler input : register(s0);
float4 ...
1
vote
2answers
161 views
Doubling the DPI with a shader?
I'm developing a game where the map is generated with Perlin Noise, but on the CPU. I am generating some perlin noise onto a texture with a small size, and then I stretch it out to the whole screen to ...
4
votes
2answers
316 views
Rain drops on screen
I am trying to make simple rain drop effect on screen.Something like this
http://fc00.deviantart.net/fs20/f/2007/302/5/6/Rain_drops_by_rockraikar.png
My idea is to:
Create small drop shaped normal ...
1
vote
0answers
239 views
Need help transforming DirectX 9 skybox hlsl shader to DirectX 11
I am in the middle of implementing a skybox to my game. I have been following this tutorial http://rbwhitaker.wikidot.com/skyboxes-2. I am using MonoGame as a framework and in order to support both ...
1
vote
1answer
165 views
XNA Shader Texture Memory
I was wondering about texture optimization in XNA 4.0.
Will the the contentmanager send the texturedata to the GPU directly when the texture gets loaded or do I send the texture data to the GPU when ...
5
votes
1answer
265 views
Partial Shader Signatures HLSL D3D11 C++
I had been debugging a problem I was having in a single shader file with 2 functions in it. I'm using DirectX 11, vs_5_0 and ps_5_0. I have stripped it down to its basic components to understand what ...
12
votes
2answers
1k views
Best way to mask 2D sprites in XNA?
I currently am trying to mask some sprites. Rather than explaining it in words, I've made up some example pictures:
The area to mask (in white)
Now, the red sprite that needs to be cropped.
The ...
2
votes
1answer
124 views
Why is my shadowmap all white?
I was trying out a shadowmap. But all my shadow is white. I think there is some problem with my homogeneous component. Can anybody help me? The rest of my code is written in xna
Here is the hlsl code ...
1
vote
0answers
164 views
Outline Shader Effect for Orthogonal Geometry in XNA
I just recently started learning the art of shading, but I can't give an outline width to 2D, concave geometry when restrained to a single vertex/pixel shader technique (thanks to XNA).
the shape I ...
1
vote
1answer
92 views
HLSL problem with divide by homogeneous component
When I try to divide my position.z by my position.w in HLSL I get as result always 1.0f or higher. Is this a common problem for some reason? When I divide my position.x or y by the w this works fine. ...
3
votes
1answer
204 views
Pass large array to pixel shader
I am trying to write a Pixelshader for a curve effect in Direct2d.
A curve effect maps each color channel value to a different value by using a look up table.
For this effect I would need to pass 3 ...
4
votes
1answer
223 views
A Quick HLSL Question (How to modify some HLSL code)
Thanks for wanting to help!
I'm trying to create a circular, repeating ring (that moves outward) on a texture. I've achieved this, to a degree, with the following code:
float distance = ...
0
votes
1answer
101 views
how to create texture for modelmesh?
Is there a possibiltiy to create a texture from a meshpart in xna. By getting a flat version of the mesh. So I can create a texture for it and edit that texture(via rendertarget)? I need to get the ...
1
vote
1answer
205 views
Heightmap in Shader not working
I'm trying to implement GPU-based geometry clipmapping and have problems to apply a simple heightmap to my terrain. For the heightmap I use a simple texture with the surface format "single". I've ...
0
votes
1answer
298 views
Shadows shimmer when camera moves
I've implemented shadow maps in my simple block engine as an exercise. I'm using one directional light and using the view volume to create the shadow matrices. I'm experiencing some problems with the ...
5
votes
1answer
419 views
Dealing with alpha for 2D per pixel lighting
Right now I've got a simple light shader. Every bitmap I draw goes through it to make up the scene. I only draw quads.
texture tex;
sampler2D s = sampler_state {
texture = <tex>;
...
4
votes
3answers
248 views
Finding out what pixel on the screen the fragment falls on
In my 2D game, I render tiles. I want to do lighting without needing an extra buffer the size of the screen.
Either in glsl or hlsl, what could I feed to the shader each time I render a bitmap so ...