This would add the Red and Green decimal values together, and then divide them by 2 to get the average. If you were to change your code as little as possible, it would look like this.įloat4 outputColor = PaletteTexture.Sample(PaletteTextureSampler, float2((texColor.r + texColor.g) / 2.0, 0.0)) I could be wrong about that, but I know it’s the way that sampling works in most other shaders I’ve worked with. The value you get back from sampling the UV coordinates from the original texture should theoretically be a float value between 0 and 1, so it shouldn’t be necessary to alter it any further. Just saying.Īlso, I think you may be calculating your UV coordinates incorrectly, as well as unnecessarily. But by using the green value as a map to the V axis of the UV coordinates, you could multiply the potential colors instead. At best, it will allow you to double your potential colors from 256 to 512. Also, taking the average of two colors may not be the best way to go about things. Converting them to a decimal format will work more accurately if you multiply them by 255. The potential values for byte-style colors are not 1-256, they are 0-255. In your pixel shader function, you are multiplying the red and green values by 256, but you should be multiplying them by 255. I can point out one issue that might be affecting things. this shader originally worked when compiling for ps_4_0_level_9_1 but since switching to MonoGame+OpenGL it has stopped working. PixelShader = compile ps_3_0 PixelShaderFunction() Į: I thought I mentioned this when posting but apparently I forgot. ![]() Texture = magfilter = POINT minfilter = POINT mipfilter = POINT AddressU = clamp AddressV = clamp įloat4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : SV_Targetįloat4 texColor = Texture.Sample(TextureSampler, texCoord) įloat4 outputColor = PaletteTexture.Sample(PaletteTextureSampler, float2(((texColor.r 256) + (texColor.g256))/PaletteTextureWidth, 0)) Sampler PaletteTextureSampler = sampler_state Texture = magfilter = NONE minfilter = NONE mipfilter = NONE AddressU = clamp AddressV = clamp However, it seems to be grabbing colors interpolated between two colors on the palette sprite I have, like so: The original sprite’s colors have a R value equal to the X of the replacement color on the palette G is set to be used as well if I ever need to go over 256. Hi, I have a shader set up to swap out colors in a sprite based on the R and G values of each color.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |