Shader Improvements and cleanup

Added sharpen shader

Added support for bloom and sharpen shader

cleanup

cleanup
This commit is contained in:
danyalzia 2013-10-30 00:12:19 +05:00 committed by DanyalZia
parent 122f19a3cf
commit 950c961dbc
5 changed files with 79 additions and 4 deletions

View File

@ -835,7 +835,7 @@ void FramebufferManager::CopyDisplayToOutput() {
// These are in the output display coordinates // These are in the output display coordinates
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height); DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
} else if (usePostShader_ && extraFBOs_.size() == 1 && !postShaderAtOutputResolution_) { } else if (usePostShader_ && extraFBOs_.size() == 1 && !postShaderAtOutputResolution_) {
// An additional pass, FXAA to the extra FBO. // An additional pass, post-processing shader to the extra FBO.
fbo_bind_as_render_target(extraFBOs_[0]); fbo_bind_as_render_target(extraFBOs_[0]);
int fbo_w, fbo_h; int fbo_w, fbo_h;
fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h); fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h);
@ -844,7 +844,7 @@ void FramebufferManager::CopyDisplayToOutput() {
fbo_unbind(); fbo_unbind();
// Use the extra FBO, with applied FXAA, as a texture. // Use the extra FBO, with applied post-processing shader, as a texture.
// fbo_bind_color_as_texture(extraFBOs_[0], 0); // fbo_bind_color_as_texture(extraFBOs_[0], 0);
if (extraFBOs_.size() == 0) { if (extraFBOs_.size() == 0) {
ERROR_LOG(G3D, "WTF?"); ERROR_LOG(G3D, "WTF?");

View File

@ -206,7 +206,7 @@ private:
bool usePostShader_; bool usePostShader_;
bool postShaderAtOutputResolution_; bool postShaderAtOutputResolution_;
// Used by antialiasing // Used by post-processing shader
std::vector<FBO *> extraFBOs_; std::vector<FBO *> extraFBOs_;
bool resized_; bool resized_;

48
assets/shaders/bloom.fsh Normal file
View File

@ -0,0 +1,48 @@
// Simple Bloom shader; created to use in PPSSPP.
// Without excessive samples and complex nested loops
// (to make it compatible with low-end GPUs and to ensure ps_2_0 compatibility).
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_texcoord0;
float amount = 0.75; // suitable range = 0.00 - 1.00
float power = 0.5; // suitable range = 0.0 - 1.0
void main()
{
vec3 color = texture2D(sampler0, v_texcoord0.xy).xyz;
vec4 sum = vec4(0);
vec3 bloom;
for(int i= -2 ;i < 2; i++)
{
sum += texture2D(sampler0, v_texcoord0 + vec2(-1, i)*0.004) * amount;
sum += texture2D(sampler0, v_texcoord0 + vec2(0, i)*0.004) * amount;
sum += texture2D(sampler0, v_texcoord0 + vec2(1, i)*0.004) * amount;
}
if (color.r < 0.3)
{
bloom = sum.xyz*sum.xyz*0.012 + color;
}
else
{
if (color.r < 0.5)
{
bloom = sum.xyz*sum.xyz*0.009 + color;
}
else
{
bloom = sum.xyz*sum.xyz*0.0075 + color;
}
}
bloom = mix(color, bloom, power);
gl_FragColor.rgb = bloom;
gl_FragColor.a = 1.0;
}

View File

@ -18,6 +18,14 @@ Name=Vignette
Author=Henrik Author=Henrik
Fragment=vignette.fsh Fragment=vignette.fsh
Vertex=fxaa.vsh Vertex=fxaa.vsh
[Bloom]
Name=Bloom
Fragment=bloom.fsh
Vertex=fxaa.vsh
[Sharpen]
Name=Sharpen
Fragment=sharpen.fsh
Vertex=fxaa.vsh
[InverseColors] [InverseColors]
Name=Inverse Colors Name=Inverse Colors
Author=Henrik Author=Henrik
@ -45,4 +53,4 @@ Name=Spline36 Upscaler
Fragment=upscale_spline36.fsh Fragment=upscale_spline36.fsh
Vertex=upscale_spline36.vsh Vertex=upscale_spline36.vsh
OutputResolution=True OutputResolution=True
RequiresIntSupport=True RequiresIntSupport=True

View File

@ -0,0 +1,19 @@
// Simple sharpen shader; created to use in PPSSPP
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_texcoord0;
float amount = 1.5;
void main()
{
vec3 color = texture2D(sampler0, v_texcoord0.xy).xyz;
color -= texture2D(sampler0, v_texcoord0.xy+0.0001).xyz*7.0*amount;
color += texture2D(sampler0, v_texcoord0.xy-0.0001).xyz*7.0*amount;
gl_FragColor.rgb = color;
}