riperiperi / FreeSO

Re-implementation of The Sims Online.
http://freeso.org
Mozilla Public License 2.0
810 stars 95 forks source link

[World] Censor shader #27

Open riperiperi opened 7 years ago

riperiperi commented 7 years ago

Obvious enough. Might need to force using a backbuffer rendertarget for this one (right now only used in software depth). TS1 has this easy because of their rendering pipeline.

image

ssinakhot commented 3 years ago

I'm not big on graphics but I might be able to help out if you can give me some direction?

riperiperi commented 3 years ago

The censor blur is a sprite that simply draws what is behind it on the screen, except heavily mosaiced. Since you cannot use a render target as a texture as you're rendering to it, you must first copy the screen render texture to another texture at the time you want to start drawing transparent effects like this. You could do this to a half res render target on standby each frame.

The blur itself is rather simple to do using SV_Position in the shader to sample the copied screen texture at the fragment position, then you can quantize that by removing the fractional part (float2 frac = fmod(SV_Position.xy, pixelSize), float2 uv = SV_Position.xy - frac)

It's a bit more difficult to get it to match the original, where the mosaic always starts at the top left of the box, but it's possible if you're able to get the top left position to the fragment shader.

riperiperi commented 3 years ago

Note: It's been a while since I used HLSL, so I'm not sure what coordinate space SV_Position is in. (0-1, or pixels eg. 0-1920) Either way, texture sampling will expect it in 0-1 uv space.