- changed default values of curvature, vignetting, reflection, round
corner and smooth border to 0
- reverted compute_size_subroutine() back to non static
- removed some test code
This commit is contained in:
ImJezze 2015-10-18 14:35:46 +02:00
parent 534cd86c17
commit 2577b29602
5 changed files with 56 additions and 62 deletions

View File

@ -114,7 +114,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
uniform float CurvatureAmount = 0.0f; uniform float CurvatureAmount = 0.0f;
uniform float RoundCornerAmount = 0.0f; uniform float RoundCornerAmount = 0.0f;
uniform float SmoothBorderAmount = 0.5f; uniform float SmoothBorderAmount = 0.0f;
uniform float VignettingAmount = 0.0f; uniform float VignettingAmount = 0.0f;
uniform float ReflectionAmount = 0.0f; uniform float ReflectionAmount = 0.0f;
@ -122,7 +122,7 @@ uniform bool OrientationSwapXY = false; // false landscape, true portrait for de
uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation uniform bool RotationSwapXY = false; // swapped default screen orientation due to screen rotation
uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270° uniform int RotationType = 0; // 0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°
float2 GetRatioCorrecton() float2 GetRatioCorrection()
{ {
float ScreenRatio = ScreenDims.x / ScreenDims.y; float ScreenRatio = ScreenDims.x / ScreenDims.y;
float QuadRatio = QuadDims.x / QuadDims.y; float QuadRatio = QuadDims.x / QuadDims.y;
@ -155,7 +155,7 @@ float GetVignetteFactor(float2 coord, float amount)
float GetSpotAddend(float2 coord, float amount) float GetSpotAddend(float2 coord, float amount)
{ {
float2 RatioCorrection = GetRatioCorrecton(); float2 RatioCorrection = GetRatioCorrection();
// normalized screen quad ratio // normalized screen quad ratio
float2 QuadRatio = float2 (1.0f, QuadDims.y / QuadDims.x); float2 QuadRatio = float2 (1.0f, QuadDims.y / QuadDims.x);
@ -191,19 +191,17 @@ float GetSpotAddend(float2 coord, float amount)
float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount) float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount)
{ {
float2 RatioCorrection = GetRatioCorrecton(); float2 RatioCorrection = GetRatioCorrection();
// reduce smooth amount down to radius amount
smoothAmount = min(smoothAmount, radiusAmount); smoothAmount = min(smoothAmount, radiusAmount);
float2 RoundCornerCoord = coord * 2; float range = min(ScreenDims.x, ScreenDims.y) * 0.5;
float radius = range * max(radiusAmount, 0.01f);
float MinScreenDims = min(ScreenDims.x, ScreenDims.y); float smooth = 1.0 / (range * max(smoothAmount, 0.01f));
float radius = MinScreenDims * 0.5 * max(radiusAmount, 0.01f);
float smooth = 1.0 / (MinScreenDims * 0.25 * max(smoothAmount, 0.01f));
// compute box // compute box
float box = roundBox(ScreenDims * RoundCornerCoord, ScreenDims * RatioCorrection, radius); float box = roundBox(ScreenDims * (coord * 2.0f), ScreenDims * RatioCorrection, radius);
// apply smooth // apply smooth
box *= smooth; box *= smooth;
@ -215,17 +213,10 @@ float GetRoundCornerFactor(float2 coord, float radiusAmount, float smoothAmount)
} }
// www.francois-tarlier.com/blog/cubic-lens-distortion-shader/ // www.francois-tarlier.com/blog/cubic-lens-distortion-shader/
float2 GetDistortedCoords(float2 coord, float amount) float2 GetDistortedCoords(float2 centerCoord, float amount)
{ {
amount *= 0.25f; // reduced amount amount *= 0.25f; // reduced amount
float2 RatioCorrection = GetRatioCorrecton();
// center coordinates
coord -= 0.5f;
coord /= RatioCorrection;
// lens distortion coefficient // lens distortion coefficient
float k = amount; float k = amount;
@ -233,20 +224,37 @@ float2 GetDistortedCoords(float2 coord, float amount)
float kcube = amount * 2.0f; float kcube = amount * 2.0f;
// compute cubic distortion factor // compute cubic distortion factor
float r2 = coord.x * coord.x + coord.y * coord.y; float r2 = centerCoord.x * centerCoord.x + centerCoord.y * centerCoord.y;
float f = kcube == 0.0f float f = kcube == 0.0f
? 1 + r2 * k ? 1.0f + r2 * k
: 1 + r2 * (k + kcube * sqrt(r2)); : 1.0f + r2 * (k + kcube * sqrt(r2));
// correct zoom // fit screen bounds
f /= 1.0f + amount * 0.5f; f /= 1.0f + amount * 0.5f;
// apply cubic distortion factor // apply cubic distortion factor
coord *= f; centerCoord *= f;
return centerCoord;
}
float2 GetCoords(float2 coord, float distortionAmount)
{
float2 RatioCorrection = GetRatioCorrection();
// center coordinates
coord -= 0.5f;
// apply ratio difference between screen and quad
coord /= RatioCorrection;
// distort coordinates
coord = GetDistortedCoords(coord, distortionAmount);
// revert ratio difference between screen and quad
coord *= RatioCorrection; coord *= RatioCorrection;
// uncenter coordinates // un-center coordinates
coord += 0.5f; coord += 0.5f;
return coord; return coord;
@ -257,22 +265,12 @@ float4 ps_main(PS_INPUT Input) : COLOR
float2 TexCoord = Input.TexCoord; float2 TexCoord = Input.TexCoord;
float2 BaseCoord = TexCoord; float2 BaseCoord = TexCoord;
// // test code
// // BaseCoord.x += (TexCoord.x > 0.5f ? -0.5f : 0.0f);
// BaseCoord.y += (TexCoord.y > 0.5f ? -0.5f : 0.0f);
// BaseCoord.y *= 2.0f;
// Screen Curvature // Screen Curvature
BaseCoord = GetDistortedCoords(BaseCoord, CurvatureAmount); BaseCoord = GetCoords(BaseCoord, CurvatureAmount);
float2 BaseCoordCentered = BaseCoord; float2 BaseCoordCentered = BaseCoord;
BaseCoordCentered -= 0.5f; BaseCoordCentered -= 0.5f;
// // test code
// BaseCoord.y /= 2.0f;
// // BaseCoord.x += (TexCoord.x > 0.5f ? +0.5f : 0.0f);
// BaseCoord.y += (TexCoord.y > 0.5 ? +0.5f : 0.0f);
// Color // Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
BaseColor.a = 1.0f; BaseColor.a = 1.0f;
@ -284,7 +282,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
BaseColor.rgb *= VignetteFactor; BaseColor.rgb *= VignetteFactor;
// Light Reflection Simulation // Light Reflection Simulation
float3 LightColor = float3(1.0f, 0.90f, 0.80f); float3 LightColor = float3(1.0f, 0.90f, 0.80f); // color temperature 5.000 Kelvin
float2 SpotCoord = BaseCoordCentered; float2 SpotCoord = BaseCoordCentered;
float2 NoiseCoord = BaseCoordCentered; float2 NoiseCoord = BaseCoordCentered;
@ -299,10 +297,6 @@ float4 ps_main(PS_INPUT Input) : COLOR
float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount); float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, RoundCornerAmount, SmoothBorderAmount);
BaseColor.rgb *= roundCornerFactor; BaseColor.rgb *= roundCornerFactor;
// // test code
// BaseColor.rgb = BaseCoord.x * BaseCoord.y;
// BaseColor.rgb = TexCoord.y > 0.5f ? 1.0f : 0.5f;
return BaseColor; return BaseColor;
} }

View File

@ -146,11 +146,10 @@ public:
vec2f & get_uvstop() { return m_stop; } vec2f & get_uvstop() { return m_stop; }
vec2f & get_rawdims() { return m_rawdims; } vec2f & get_rawdims() { return m_rawdims; }
static void compute_size_subroutine(texture_manager* texture_manager, int texwidth, int texheight, int* p_width, int* p_height);
private: private:
void prescale(); void prescale();
void compute_size(int texwidth, int texheight); void compute_size(int texwidth, int texheight);
void compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height);
texture_manager * m_texture_manager; // texture manager pointer texture_manager * m_texture_manager; // texture manager pointer

View File

@ -1609,7 +1609,8 @@ int shaders::distortion_pass(render_target *rt, int source_index, poly_info *pol
if (options->reflection == 0 && if (options->reflection == 0 &&
options->vignetting == 0 && options->vignetting == 0 &&
options->curvature == 0 && options->curvature == 0 &&
options->round_corner == 0) options->round_corner == 0 &&
options->smooth_border == 0)
{ {
return next_index; return next_index;
} }
@ -2765,11 +2766,11 @@ shaders::slider_desc shaders::s_sliders[] =
{ "Shadow Mask Pixel Count Y", 1, 6, 64, 1, slider_shadow_mask_vsize }, { "Shadow Mask Pixel Count Y", 1, 6, 64, 1, slider_shadow_mask_vsize },
{ "Shadow Mask Offset X", -100, 0, 100, 1, slider_shadow_mask_uoffset }, { "Shadow Mask Offset X", -100, 0, 100, 1, slider_shadow_mask_uoffset },
{ "Shadow Mask Offset Y", -100, 0, 100, 1, slider_shadow_mask_voffset }, { "Shadow Mask Offset Y", -100, 0, 100, 1, slider_shadow_mask_voffset },
{ "Screen Curvature", 0, 3, 100, 1, slider_curvature }, { "Screen Curvature", 0, 0, 100, 1, slider_curvature },
{ "Screen Round Corner", 0, 3, 100, 1, slider_round_corner }, { "Screen Round Corner", 0, 0, 100, 1, slider_round_corner },
{ "Screen Smooth Border", 0, 3, 100, 1, slider_smooth_border }, { "Screen Smooth Border", 0, 0, 100, 1, slider_smooth_border },
{ "Screen Reflection", 0, 3, 100, 1, slider_reflection }, { "Screen Reflection", 0, 0, 100, 1, slider_reflection },
{ "Image Vignetting", 0, 3, 100, 1, slider_vignetting }, { "Image Vignetting", 0, 0, 100, 1, slider_vignetting },
{ "Scanline Darkness", 0, 100, 100, 1, slider_scanline_alpha }, { "Scanline Darkness", 0, 100, 100, 1, slider_scanline_alpha },
{ "Scanline Screen Height", 1, 20, 80, 1, slider_scanline_scale }, { "Scanline Screen Height", 1, 20, 80, 1, slider_scanline_scale },
{ "Scanline Indiv. Height", 1, 20, 80, 1, slider_scanline_height }, { "Scanline Indiv. Height", 1, 20, 80, 1, slider_scanline_height },
@ -2922,7 +2923,7 @@ void uniform::update()
} }
case CU_SOURCE_DIMS: case CU_SOURCE_DIMS:
{ {
vec2f& sourcedims = shadersys->curr_texture->get_rawdims(); vec2f sourcedims = shadersys->curr_texture->get_rawdims();
m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); m_shader->set_vector("SourceDims", 2, &sourcedims.c.x);
break; break;
} }

View File

@ -2074,13 +2074,13 @@ error:
// texture_info::compute_size_subroutine // texture_info::compute_size_subroutine
//============================================================ //============================================================
void texture_info::compute_size_subroutine(texture_manager* texture_manager, int texwidth, int texheight, int* p_width, int* p_height) void texture_info::compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height)
{ {
int finalheight = texheight; int finalheight = texheight;
int finalwidth = texwidth; int finalwidth = texwidth;
// round width/height up to nearest power of 2 if we need to // round width/height up to nearest power of 2 if we need to
if (!(texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) if (!(m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
{ {
// first the width // first the width
if (finalwidth & (finalwidth - 1)) if (finalwidth & (finalwidth - 1))
@ -2104,7 +2104,7 @@ void texture_info::compute_size_subroutine(texture_manager* texture_manager, int
} }
// round up to square if we need to // round up to square if we need to
if (texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) if (m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY)
{ {
if (finalwidth < finalheight) if (finalwidth < finalheight)
finalwidth = finalheight; finalwidth = finalheight;
@ -2113,11 +2113,11 @@ void texture_info::compute_size_subroutine(texture_manager* texture_manager, int
} }
// adjust the aspect ratio if we need to // adjust the aspect ratio if we need to
while (finalwidth < finalheight && finalheight / finalwidth > texture_manager->get_max_texture_aspect()) while (finalwidth < finalheight && finalheight / finalwidth > m_texture_manager->get_max_texture_aspect())
{ {
finalwidth *= 2; finalwidth *= 2;
} }
while (finalheight < finalwidth && finalwidth / finalheight > texture_manager->get_max_texture_aspect()) while (finalheight < finalwidth && finalwidth / finalheight > m_texture_manager->get_max_texture_aspect())
{ {
finalheight *= 2; finalheight *= 2;
} }
@ -2151,7 +2151,7 @@ void texture_info::compute_size(int texwidth, int texheight)
finalwidth += 2 * m_xborderpix; finalwidth += 2 * m_xborderpix;
finalheight += 2 * m_yborderpix; finalheight += 2 * m_yborderpix;
texture_info::compute_size_subroutine(m_texture_manager, finalwidth, finalheight, &finalwidth, &finalheight); compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight);
// if we added pixels for the border, and that just barely pushed us over, take it back // if we added pixels for the border, and that just barely pushed us over, take it back
if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height()) if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height())
@ -2162,7 +2162,7 @@ void texture_info::compute_size(int texwidth, int texheight)
m_xborderpix = 0; m_xborderpix = 0;
m_yborderpix = 0; m_yborderpix = 0;
texture_info::compute_size_subroutine(m_texture_manager, finalwidth, finalheight, &finalwidth, &finalheight); compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight);
} }
// if we're above the max width/height, do what? // if we're above the max width/height, do what?

View File

@ -302,11 +302,11 @@ const options_entry windows_options::s_option_entries[] =
{ WINOPTION_SHADOW_MASK_VSIZE";fs_shadwv(0.0-1.0)", "0.1875", OPTION_FLOAT, "shadow mask texture size in V direction" }, { WINOPTION_SHADOW_MASK_VSIZE";fs_shadwv(0.0-1.0)", "0.1875", OPTION_FLOAT, "shadow mask texture size in V direction" },
{ WINOPTION_SHADOW_MASK_UOFFSET";fs_shadwou(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in U direction" }, { WINOPTION_SHADOW_MASK_UOFFSET";fs_shadwou(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in U direction" },
{ WINOPTION_SHADOW_MASK_VOFFSET";fs_shadwov(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in V direction" }, { WINOPTION_SHADOW_MASK_VOFFSET";fs_shadwov(-1.0-1.0)", "0.0", OPTION_FLOAT, "shadow mask texture offset in V direction" },
{ WINOPTION_CURVATURE";fs_curv(0.0-1.0)", "0.03", OPTION_FLOAT, "screen curvature amount" }, { WINOPTION_CURVATURE";fs_curv(0.0-1.0)", "0.0", OPTION_FLOAT, "screen curvature amount" },
{ WINOPTION_ROUND_CORNER";fs_rndc(0.0-1.0)", "0.03", OPTION_FLOAT, "screen round corner amount" }, { WINOPTION_ROUND_CORNER";fs_rndc(0.0-1.0)", "0.0", OPTION_FLOAT, "screen round corner amount" },
{ WINOPTION_SMOOTH_BORDER";fs_smob(0.0-1.0)", "0.03", OPTION_FLOAT, "screen smooth border amount" }, { WINOPTION_SMOOTH_BORDER";fs_smob(0.0-1.0)", "0.0", OPTION_FLOAT, "screen smooth border amount" },
{ WINOPTION_REFLECTION";fs_ref(0.0-1.0)", "0.03", OPTION_FLOAT, "screen reflection amount" }, { WINOPTION_REFLECTION";fs_ref(0.0-1.0)", "0.0", OPTION_FLOAT, "screen reflection amount" },
{ WINOPTION_VIGNETTING";fs_vig(0.0-1.0)", "0.03", OPTION_FLOAT, "image vignetting amount" }, { WINOPTION_VIGNETTING";fs_vig(0.0-1.0)", "0.0", OPTION_FLOAT, "image vignetting amount" },
/* Beam-related values below this line*/ /* Beam-related values below this line*/
{ WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)", "1.0", OPTION_FLOAT, "overall alpha scaling value for scanlines" }, { WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)", "1.0", OPTION_FLOAT, "overall alpha scaling value for scanlines" },
{ WINOPTION_SCANLINE_SCALE";fs_scansc(0.0-4.0)", "1.0", OPTION_FLOAT, "overall height scaling value for scanlines" }, { WINOPTION_SCANLINE_SCALE";fs_scansc(0.0-4.0)", "1.0", OPTION_FLOAT, "overall height scaling value for scanlines" },