Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postshader: Let shaders use the previous frame #14528

Merged
merged 6 commits into from
Jun 12, 2021

Conversation

unknownbrackets
Copy link
Collaborator

@unknownbrackets unknownbrackets commented Jun 12, 2021

This is useful for i.e. simulating the slow update speed of the PSP's LCD screen, but could in theory be used for other effects.

Here's a test fragment shader I was using:

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D sampler0;
uniform sampler2D sampler2;
varying vec2 v_texcoord0;

void main() {
	vec3 update = texture2D(sampler0, v_texcoord0.xy).rgb;
	vec3 prev = texture2D(sampler2, v_texcoord0.xy).rgb;

	gl_FragColor.rgb = mix(prev, update, 0.1);
	gl_FragColor.a = 1.0;
}

Using 0.1 makes the effect very obvious, but of course that varies by rendered FPS. For that reason I added a u_timeDelta:

Value Meaning Speeds up if unthrottled Changes on load state
u_timeDelta.x Fractional seconds, in real time, since last frame No No
u_timeDelta.y Fractional seconds, in emulated time, since last frame (approx) Yes Yes
u_timeDelta.z Number of vblanks (which occur 60 times every 1001ms, i.e. 59.94 times per second) since last frame Yes Yes
u_timeDelta.w In practice, always 1.0 (delta number of flips) N/A N/A

With this, the above example can be amended with uniform vec4 u_timeDelta; at the top, and u_timeDelta.y * 6 in place of 0.1 to have a more stable effect regardless of game FPS. But you could also force 60 FPS output.

-[Unknown]

This is useful for i.e. simulating the slow update speed of the PSP's LCD
screen, but could in theory be used for other effects.
Useful mainly when using previous frame output.
Copy link
Owner

@hrydgard hrydgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring too! Just nitpicking.

@@ -1329,6 +1332,7 @@ Framebuffer *D3D11DrawContext::CreateFramebuffer(const FramebufferDesc &desc) {
void D3D11DrawContext::BindTextures(int start, int count, Texture **textures) {
// Collect the resource views from the textures.
ID3D11ShaderResourceView *views[8];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well change this array length to MAX_BOUND_TEXTURES since you're here poking around

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed. Went ahead and cleaned up some other GL checks in Draw too along the same lines.

-[Unknown]

@@ -1338,6 +1342,7 @@ void D3D11DrawContext::BindTextures(int start, int count, Texture **textures) {

void D3D11DrawContext::BindSamplerStates(int start, int count, SamplerState **states) {
ID3D11SamplerState *samplers[8];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@hrydgard hrydgard added the User Interface PPSSPP's own user interface / UX label Jun 12, 2021
@hrydgard hrydgard added this to the v1.12.0 milestone Jun 12, 2021
GL actually had a check for 16 but then an array for 8.  This should make
it easier to figure out if we ever hit those limits.
@hrydgard hrydgard merged commit b07d907 into hrydgard:master Jun 12, 2021
@unknownbrackets unknownbrackets deleted the postshader branch June 12, 2021 22:54
@LunaMoo
Copy link
Collaborator

LunaMoo commented Jun 13, 2021

Not sure if I'm doing something wrong, but even with a test shader posted here past frame is always black, so the test shader results in a 90% mix of black and 10% of current frame, so just a very dark image from current frame.
Does this have some special requirements? I have the same results on all backends.

@iota97
Copy link
Contributor

iota97 commented Jun 13, 2021

Does this have some special requirements?

Have you set UsePreviousFrame=true in the ini?

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jun 13, 2021

Aw, I completely missed that, it works fine now;3, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User Interface PPSSPP's own user interface / UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants