hlsl

DirectX compute shader: how to write a function with variable array size argument?

纵然是瞬间 提交于 2019-12-13 03:07:58
问题 I'm trying to write a function within a compute shader (HLSL) that accept an argument being an array on different size. The compiler always reject it. Example (not working!): void TestFunc(in uint SA[]) { int K; for (K = 0; SA[K] != 0; K++) { // Some code using SA array } } [numthreads(1, 1, 1)] void CSMain( uint S1[] = {1, 2, 3, 4 }; // Compiler happy and discover the array size uint S2[] = {10, 20}; // Compiler happy and discover the array size TestFunc(S1); TestFunc(S2); } If I give an

Unity 3d Sprite Shader (How do I limit Max Brightness to 1 with Multiple Lights Hitting)

送分小仙女□ 提交于 2019-12-12 10:09:23
问题 I am creating a videogame in Unity. Every sprite is rendered with a Sprite Renderer with a Material that has the CornucopiaShader.shader. The problem I have is I want to limit the max brightness (or color) of the sprite to just be a normal image of the sprite regardless of the power of how many point lights are hitting it, the intensity of the lights, and also the ambient light in the unity scene. When the intensity of the lights hitting the sprite is below that max brightness level I want it

Calculating screen texture coordinates in CG/HLSL

纵然是瞬间 提交于 2019-12-12 09:13:24
问题 In OpenGL , sometimes when doing multi-pass rendering and post-processing I need to apply texels to the primitive's assembly fragments which are part of full screen texture composition.That is usually the case when the current pass comes from FBO texture to which the screen quad had been rendered during previous pass.To achieve this I calculate objects UV coordinates in SCREEN SPACE .In GLSL I calculate it like this: vec2 texelSize = 1.0 / vec2(textureSize(TEXTURE, 0)); vec2 screenTexCoords =

Multiple Render Targets not saving data

折月煮酒 提交于 2019-12-12 08:13:19
问题 I'm using SlimDX, targeting DirectX 11 with shader model 4. I have a pixel shader "preProc" which processes my vertices and saves three textures of data. One for per-pixel normals, one for per-pixel position data and one for color and depth (color takes up rgb and depth takes the alpha channel). I then later use these textures in a postprocessing shader in order to implement Screen Space Ambient Occlusion, however it seems none of the data is getting saved in the first shader. Here's my pixel

Can I put HLSL into a .lib somehow?

流过昼夜 提交于 2019-12-12 06:23:18
问题 I made a sprite renderer using DirectX and C++ and I would like to put that into a .lib file. Is it possible to somehow put the two (compiled) shaders into the .lib so I don't have to include them everywhere? Right now I read them from disk at runtime which of course means that I have to put the two .cso files somewhere so they can be read. The solution I came up with is to put them into the project as strings and then compile them at runtime but that's not as convenient... 回答1: How about

Calculate ray direction vector from screen coordanate

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:08:00
问题 I'm looking for a better way (or a note that this is the best way) to transfer a pixel coordinate to its corresponding ray direction from a arbitrary camera position/direction. My current method is as follows. I define a "camera" as a position vector, lookat vector, and up vector, named as such. (Note that the lookat vector is a unit vector in the direction the camera is facing, NOT where (position - lookat) is the direction, as is the standard in XNA's Matrix.CreateLookAt) These three

How to remove Blur halo effect

假如想象 提交于 2019-12-12 02:46:44
问题 I'm trying to blur my depth buffer and then get surface normal for my fluid simulation here is my hlsl pixels shader Bilateral Filter float depth = depthTexture.Sample( defss1, pin.Tex).x; float blurDepthFalloff = 2.0f; float radius = 4.0f; float blurScale = 2.0f / radius; float sum = 0.0f; float wsum = 0.0f; float2 scale = (1.0f/(1920.0f), 1.0f/(1080.0f)); for(float x=-radius; x<=radius; x+=1.0f) { float cur = depthTexture.Sample( defss1, pin.Tex + x * scale).x; // range domain float r2 =

D3D10 Constant buffer not working

半腔热情 提交于 2019-12-12 01:45:36
问题 I am using a constant buffer to transfer data to my pixel shader The problem is that the buffer contains 0s in the shader during runtime for x, y, z, and w of the float4 member, regardless of what data is updated to the buffer Structure definitions are as follows: // (C++) struct Buffer { XMMATRIX mvp_; XMFLOAT4 rgba_; int usemvp_; }; // HLSL cbuffer Buffer : register( b0 ) { matrix mvp_; float4 rgba_; int usemvp_; }; Any help is much appreciated 回答1: You need to pad your struct to make it 16

2D Water Bump Mapping - Monogame

别来无恙 提交于 2019-12-11 18:45:55
问题 Thanks for taking the time to check out my issue. I am working on improving the ocean in my first attempt at a game. I have decided on a using a bump map against my ocean tiles to add a little texture to the water. To do this, I draw my water tiles to a renderTarget and then apply a pixel shader while drawing the render target to the backbuffer. The problem I am having is that the pixel shader seems to offset or displace the position of render target that is drawn. Observe these two photos:

Flipping bits in an integer without bitwise operations

喜欢而已 提交于 2019-12-11 15:04:23
问题 I need to flip the bits in an integer from 1 to 0 and 0 to 1. E.g 10010 to 01101 The problem is that in HLSL ps_3_0 there are no binary operators. No ~, <<, >>,... Is there a mathematical way of accomplishing this? 回答1: You can use the following solution int inverse(int x) { return 0xFFFFFFFFU - x; } otherwise: int inverse(int x) { return -x - 1; // because -x = ~x + 1, only works in 2's complement } 来源: https://stackoverflow.com/questions/24107095/flipping-bits-in-an-integer-without-bitwise