migf1 Δημοσ. 2 Οκτωβρίου 2015 Δημοσ. 2 Οκτωβρίου 2015 Ενδιαφέρεται κανείς με εμπειρία σε DirectX HLSL shaders να επεκτείνει κάνα-δυο υπάρχοντες shaders ώστε να μετατρέπουν stereoscopic (h)sbs/(h)ou 3d movies σε anaglyph-debois red-cyan? Έχω βρει για παράδειγμα τους παρακάτω prototype HLSL shaders για μετατροπή από hsbs 3d σε anaglyph red-cyan. Ο 1ος είναι τελείως straight-forward, ο 2ος χρησιμοποιεί lanczos2 (παρεμπιπτόντως, παρόλο που στα σχόλια λένε πως θέλουν full-screen input, στην πράξη θέλουν half-width input)... 1ος: // prototype basic fullscreen side-by-side to red-cyan anaglyph 3D stereoscopic view // This shader should be run as a screen space pixel shader. // This shader requires compiling with ps_2_0, but higher is better, see http://en.wikipedia.org/wiki/Pixel_shader to look up what PS version your video card supports. // For this shader to work correctly, the video width in pixels on screen has to be an even amount. sampler s0; float2 c0; float2 c1; float4 main( float2 tex : TEXCOORD0 ) : COLOR { float2 texr = tex; float2 vr = float2( 0., c0.x ); float2 CurPixel = tex * c0 - .5; float ox = CurPixel.x - vr.x;// video-relative x position // the two images are half-width, compensate for that, round half-pixel offsets down float PixelOffset = floor( -.5 * ox ); // adjust the x coordinate of the source position to the correct side of the video image using the pixel offset we just calculated tex.x += PixelOffset * c1.x; // adjust the pixel offset to the video frame on the right side of the video data texr.x += (PixelOffset + .5 * (vr.y-vr.x)) * c1.x; // sample from the left and right images and only pass-trough the red channel for the left, and the green and blue channels for the right view return float4( tex2D(s0, tex).r, tex2D(s0, texr).gbb ); } 2ος: // prototype basic fullscreen side-by-side to red-cyan anaglyph 3D stereoscopic view with compensated Lanczos2 resizing // This shader should be run as a screen space pixel shader. // This shader requires compiling with ps_2_0, but higher is better, see http://en.wikipedia.org/wiki/Pixel_shader to look up what PS version your video card supports. // For this shader to work correctly, the video width in pixels on screen has to be an even amount. sampler s0; float2 c0; float2 c1; static const float PI = acos(-1.); static const float4 wset = float4(1.25, .25, .75, 1.75)*PI; static const float4 wsets = wset*.5; static const float4 wp = sin(wset)*sin(wsets)/(wset*wsets); static const float2 wc = (1.-dot(1., wp))*float2(.75, .25);// compensate truncated window factor by bilinear factoring on the two nearest samples static const float4 w = wp+float4(0., wc, 0.); float4 main(float2 tex : TEXCOORD0) : COLOR { float ox = tex.x*c0.x-.5;// video-relative x position // detect half of the even or odd coordinates ox = ox*.5+.25;// the two images are half-width, compensate for that float n = frac(ox); float dx = (n > .5)? -c1.x : c1.x;// even x positive, odd x negative float pixeloffset = n-ox;// round half-pixel offsets down // adjust the x coordinate of the source position to the correct side of the video image using the pixel offset we just calculated tex.x += pixeloffset*c1.x; float center = .5; float texr = tex.x+center-c1.x;// adjust the pixel offset to the video frame on the right side of the video data // sample from the left and right images and only pass-trough the red channel for the left, and the green and blue channels for the right view float3 Q0 = float3(tex2D(s0, float2(tex.x-dx, tex.y)).r, tex2D(s0, float2(texr-dx, tex.y)).gb); float3 Q1 = float3(tex2D(s0, tex).r, tex2D(s0, float2(texr, tex.y)).gb); float3 Q2 = float3(tex2D(s0, float2(tex.x+dx, tex.y)).r, tex2D(s0, float2(texr+dx, tex.y)).gb); float3 Q3 = float3(tex2D(s0, float2(tex.x+dx+dx, tex.y)).r, tex2D(s0, float2(texr+dx+dx, tex.y)).gb); return (w.x*Q0+w.y*Q1+w.z*Q2+w.w*Q3).rgbb;// interpolate and output } Τους έχω δοκιμάσει με Media Player Classic Home Cinema (Enhanced Video Renderer - Custom Presenter) και λειτουργούν. Δεν τους έχω γράψει εγώ, τους έχω πάρει από το φορουμ του mpc-hc στο doom9.org. Το ιδανικό θα ήταν να χρησιμοποιηθεί ο dubois αλγόριθμος. Ακόμα καλύτερα να υπάρχει ένας shader για κάθε anaglyph μορφή. Π.χ. υπάρχουν 4 μορφές red-cyan anaglyph: gray, half-colored, full-colored & dubois. Αν μιλάμε για πηγαία ταινία side-by-side 3d (που είναι και η πιο διαδεδομένη), τότε για τις 4 προαναφερθείσες anaglyph red-cyan μορφές για το output θα έχουμε συνολικά 8 shaders: 4 για fullscreen SBS πηγή και 4 για half-width SBS πηγή (HSBS). Και αν θέλουμε να το ψειρίσουμε ακόμα περισσότερο, τους διπλασιάζουμε σε πλήθος, ώστε ο καθένας τους να έχει και εκδοχή με swapped left/right εικόνες σε κάθε frame. Όλα αυτά υποστηρίζονται ήδη από άλλους players (π.χ. potplayer, mpv, bino3d) αλλά όχι στον mpc-hc. Το screenshot που ακολουθεί σε spoiler δείχνει οπτικά αυτά που γράφω στην προηγούμενη παράγραφο (τα έχω μαρκάρει με πράσινο χρώμα): Στον MPC-HC δεν υπάρχει εγγενής υποστήριξη (ή δεν την έχω βρει) οπότε η λύση είναι είτε με shaders, είτε με avisynth scripts, αλλά το avisynth serving τρώει πολύ cpu συγκριτικά με τους shaders (κι έχει και μανούρα να το συσχετίσεις με τον mpc-hc). Τους shaders απλά τους βάζεις σε έναν φάκελο (υπάρχει ήδη στο installation folder του mpc-hc, με διάφορους shaders), μετά φτιάχνεις συσχετίσεις μέσα από τον mpc-hc (Options->Playback->Shadders) και τέλος τους διαλέγεις on-the-fly την ώρα που παίζει η ταινία. Ακολουθεί σχετικό screenshot σε spoiler)... Άσχετο: το logo και τη toolbar τα έχω φτιάξει εγώ Η αλήθεια είναι πως όλα αυτά τα κάνει κανείς μονάχα αν έχει χρόνο & διάθεση, και είναι fun του mpc-hc και θέλει να τον χρησιμοποιεί ως default player σε όσο το δυνατόν περισσότερες περιπτώσεις. Πάντως 4 shaders για (h)sbs -> redcyan & (h)sbs -> redcyan dubois θα κάλυπταν πολύ μεγάλη γκάμα σύγχρονων 3d ταινιών για όσους δεν έχουν 3d monitors και δεν έχουν πρόβλημα να δώσουν 3 ευρώ για ένα ζευγάρι red-cyan γυαλιών. Χώρια ότι η δημιουργία shaders και για (h)Top/Bottom πηγές θα ήταν trivial μετά. Ελπίζω να βρεθεί κάποιος με όρεξη, χρόνο και γνώσεις να φτιάξει έστω ένα redcyan dubois (γκουχ-γκουχ, πάπι ακούει; ) PS. Παρεμπιπτόντως, όσοι έχουν nvidia κάρτες, ενεργοποιώντας το 3d vision στους drivers μπορούν να παίξουν πολύ μεγάλη γκάμα παιχνιδιών σε anaglyph 3d. Το anaglyph 3d έχει μειονεκτήματα (κυρίως η απαλοιφή των χρωμάτων των φακών από την ταινία) αλλά είναι κυριολεκτικά τσάμπα για το wow-effect που προσφέρει.
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα