mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Scale quads after rendering to a screen texture instead of scaling directly. Fixes discontinuities in room editor and menu edges.
This commit is contained in:
@@ -17,28 +17,8 @@ float3 SamplePixel(int2 texCoord)
|
||||
|
||||
SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input)
|
||||
{
|
||||
float dx = ddx(input.texCoord.x);
|
||||
float dy = ddy(input.texCoord.y);
|
||||
|
||||
float2 pixelTopLeftCoord = max(0.0, input.texCoord.xy - float2(dx, dy) * 0.5);
|
||||
float2 pixelBottomRightCoord = pixelTopLeftCoord + min(float2(1.0, 1.0), float2(dx, dy));
|
||||
|
||||
int2 topLeftCoordInteger = int2(floor(pixelTopLeftCoord));
|
||||
int2 bottomRightCoordInteger = int2(floor(pixelBottomRightCoord));
|
||||
|
||||
float2 interpolators = saturate((pixelBottomRightCoord - float2(bottomRightCoordInteger)) / float2(dx, dy));
|
||||
|
||||
float3 topLeftColor = SamplePixel(topLeftCoordInteger);
|
||||
float3 topRightColor = SamplePixel(int2(bottomRightCoordInteger.x, topLeftCoordInteger.y));
|
||||
float3 bottomLeftColor = SamplePixel(int2(topLeftCoordInteger.x, bottomRightCoordInteger.y));
|
||||
float3 bottomRightColor = SamplePixel(bottomRightCoordInteger);
|
||||
|
||||
float3 topColor = (1.0 - interpolators.x) * topLeftColor + interpolators.x * topRightColor;
|
||||
float3 bottomColor = (1.0 - interpolators.x) * bottomLeftColor + interpolators.x * bottomRightColor;
|
||||
float3 interpolatedColor = (1.0 - interpolators.y) * topColor + interpolators.y * bottomColor;
|
||||
|
||||
SDrawQuadPixelOutput result;
|
||||
result.color = float4(interpolatedColor, 1.0);
|
||||
result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "DrawQuad.h"
|
||||
|
||||
SamplerState surfaceSampler : register(s0);
|
||||
Texture2D<float> surfaceTexture : register(t0);
|
||||
Texture2D<float3> surfaceTexture : register(t0);
|
||||
|
||||
struct SDrawQuadPixelOutput
|
||||
{
|
||||
@@ -10,9 +10,9 @@ struct SDrawQuadPixelOutput
|
||||
|
||||
SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input)
|
||||
{
|
||||
float surfaceColor = surfaceTexture.Sample(surfaceSampler, input.texCoord.xy).r;
|
||||
float3 surfaceColor = surfaceTexture.Load(int3(input.texCoord.xy, 0)).rgb;
|
||||
|
||||
SDrawQuadPixelOutput result;
|
||||
result.color = float4(surfaceColor, input.texCoord.x, input.texCoord.y, 1.0);
|
||||
result.color = float4(surfaceColor, 1.0);
|
||||
return result;
|
||||
}
|
||||
|
||||
41
ShaderSrc/ScaleQuadP.hlsl
Normal file
41
ShaderSrc/ScaleQuadP.hlsl
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "DrawQuad.h"
|
||||
|
||||
SamplerState surfaceSampler : register(s0);
|
||||
Texture2D<float3> surfaceTexture : register(t0);
|
||||
|
||||
struct SDrawQuadPixelOutput
|
||||
{
|
||||
float4 color : SV_TARGET;
|
||||
};
|
||||
|
||||
float3 SamplePixel(int2 coord)
|
||||
{
|
||||
return surfaceTexture.Load(int3(coord, 0)).rgb;
|
||||
}
|
||||
|
||||
SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input)
|
||||
{
|
||||
float dx = ddx(input.texCoord.x);
|
||||
float dy = ddy(input.texCoord.y);
|
||||
|
||||
float2 pixelTopLeftCoord = max(0.0, input.texCoord.xy - float2(dx, dy) * 0.5);
|
||||
float2 pixelBottomRightCoord = pixelTopLeftCoord + min(float2(1.0, 1.0), float2(dx, dy));
|
||||
|
||||
int2 topLeftCoordInteger = int2(floor(pixelTopLeftCoord));
|
||||
int2 bottomRightCoordInteger = int2(floor(pixelBottomRightCoord));
|
||||
|
||||
float2 interpolators = saturate((pixelBottomRightCoord - float2(bottomRightCoordInteger)) / float2(dx, dy));
|
||||
|
||||
float3 topLeftColor = SamplePixel(topLeftCoordInteger);
|
||||
float3 topRightColor = SamplePixel(int2(bottomRightCoordInteger.x, topLeftCoordInteger.y));
|
||||
float3 bottomLeftColor = SamplePixel(int2(topLeftCoordInteger.x, bottomRightCoordInteger.y));
|
||||
float3 bottomRightColor = SamplePixel(bottomRightCoordInteger);
|
||||
|
||||
float3 topColor = (1.0 - interpolators.x) * topLeftColor + interpolators.x * topRightColor;
|
||||
float3 bottomColor = (1.0 - interpolators.x) * bottomLeftColor + interpolators.x * bottomRightColor;
|
||||
float3 interpolatedColor = (1.0 - interpolators.y) * topColor + interpolators.y * bottomColor;
|
||||
|
||||
SDrawQuadPixelOutput result;
|
||||
result.color = float4(interpolatedColor, 1.0);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user