<commit_before>package ;

import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.Lib;
import gibber.God;

import h3d.scene.*;

#if debug
import com.sociodox.theminer.TheMiner;
#end

using gibber.Util;

class PostEffectsShader extends hxsl.Shader {

#if flash 
    static var SRC = {
        @input var input : {
            pos : Vec3,
            uv : Vec2,
        };

        @global var camera : {
            var proj : Mat4;
        };

        var output : {
            var position : Vec4;
            var color : Vec4;
        };

        var tuv : Vec2;
        @param var time : Float;
        var screenres : Vec2;
        @param var tex : Sampler2D;

        function vertex() {
            output.position = vec4( input.pos.xyz, 1 ) * camera.proj;
            tuv =  input.uv;
        }

        // apply fisheye/CRT screen warp to UV coords; at flatness ~= 0, it's a circle.
        function crtwarp( uv : Vec2, flatness : Float ): Vec2 {
            var coord = ( uv - 0.5 ) * 2.0; // shift coordsys to ( -0.5 , 0.5 )
            coord *= 1.1;

            coord.x *= 1.0 + pow( ( abs( coord.y ) / flatness ), 2.0 );
            coord.y *= 1.0 + pow( ( abs( coord.x ) / flatness ), 2.0 );

            coord = ( coord / 2.0 ) + 0.5; // back to ( 0, 1 )
            return coord;
        }

        // sampling trick to force a red-green shift on resulting texture
        function rgshift( tex : Sampler2D, uv : Vec2 ): Vec4 {
            var c : Vec4 = vec4( 0, 0, 0, 1 );
            c.r = tex.get( uv - vec2( 0.003, 0 ) ).r;
            c.g = tex.get( uv ).g;
            c.b = tex.get( uv + vec2( 0.003, 0 ) ).b;
            return c;
        }

        // make scanlines by subtracting from rgb
        function scanline( color : Vec4, screenspace : Vec2 ): Vec4 {
            color.rgb -= sin( ( screenspace.y + ( time * 29.0 ) ) ) * 0.02;
            return color;
        }

        // darken corners
        function darken( color : Vec4, screenspace : Vec2 ): Vec4 {
            var threshold : Vec2 = min( screenspace, screenres - screenspace );
            color.rgb -= pow( length( screenres ) / length( threshold ), 0.3 ) * vec3( 0.11, 0.11, 0.11 );
            return color;
        }

        function fragment() {
            var uv = crtwarp( tuv, 4.2 );
            var c = rgshift( tex, uv );

            // discard
            c *= uv.x > 0 ? 1 : 0;
            c *= uv.y > 0 ? 1 : 0;
            c *= uv.x < 1 ? 1 : 0;
            c *= uv.y < 1 ? 1 : 0;

            // using screenspace coords forcibly produces a moire pattern, neat!
            c = darken( c, uv * screenres );
            c = scanline( c, uv * screenres );
            output.color = c;
        }
    };

#else
    // do nothing
    static var VERTEX = "
        attribute vec3 pos;
        uniform mat4 mproj;
        attribute vec2 uv;

        varying vec2 tuv;

        void main(void) {
            gl_Position = vec4(pos,1)*mproj;
            tuv = uv;
        }";

    static var FRAGMENT = "
        uniform sampler2D tex;
        varying vec2 tuv;
        void main(void) {
            gl_FragColor = texture2D(tex, tuv);
            //gl_FragColor = vec4(1,1,1,1);
        }
    ";
#end
}

class PostEffectsMaterial extends h3d.mat.Material{
    public var tex : h3d.mat.Texture;
    var pshader : PostEffectsShader;

    public function new( tex ) {
        this.tex = tex;
        pshader = new PostEffectsShader();
        mainPass.culling = None;
        mainPass.blend(SrcAlpha, OneMinusSrcAlpha);
        super( pshader );<commit_msg>fix shader null MainPass problem - #46<commit_after>package ;

import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.Lib;
import gibber.God;

import h3d.scene.*;
import h3d.mat.Pass;

#if debug
import com.sociodox.theminer.TheMiner;
#end

using gibber.Util;

class PostEffectsShader extends hxsl.Shader {

#if flash 
    static var SRC = {
        @input var input : {
            pos : Vec3,
            uv : Vec2,
        };

        @global var camera : {
            var proj : Mat4;
        };

        var output : {
            var position : Vec4;
            var color : Vec4;
        };

        var tuv : Vec2;
        @param var time : Float;
        var screenres : Vec2;
        @param var tex : Sampler2D;

        function vertex() {
            output.position = vec4( input.pos.xyz, 1 ) * camera.proj;
            tuv =  input.uv;
        }

        // apply fisheye/CRT screen warp to UV coords; at flatness ~= 0, it's a circle.
        function crtwarp( uv : Vec2, flatness : Float ): Vec2 {
            var coord = ( uv - 0.5 ) * 2.0; // shift coordsys to ( -0.5 , 0.5 )
            coord *= 1.1;

            coord.x *= 1.0 + pow( ( abs( coord.y ) / flatness ), 2.0 );
            coord.y *= 1.0 + pow( ( abs( coord.x ) / flatness ), 2.0 );

            coord = ( coord / 2.0 ) + 0.5; // back to ( 0, 1 )
            return coord;
        }

        // sampling trick to force a red-green shift on resulting texture
        function rgshift( tex : Sampler2D, uv : Vec2 ): Vec4 {
            var c : Vec4 = vec4( 0, 0, 0, 1 );
            c.r = tex.get( uv - vec2( 0.003, 0 ) ).r;
            c.g = tex.get( uv ).g;
            c.b = tex.get( uv + vec2( 0.003, 0 ) ).b;
            return c;
        }

        // make scanlines by subtracting from rgb
        function scanline( color : Vec4, screenspace : Vec2 ): Vec4 {
            color.rgb -= sin( ( screenspace.y + ( time * 29.0 ) ) ) * 0.02;
            return color;
        }

        // darken corners
        function darken( color : Vec4, screenspace : Vec2 ): Vec4 {
            var threshold : Vec2 = min( screenspace, screenres - screenspace );
            color.rgb -= pow( length( screenres ) / length( threshold ), 0.3 ) * vec3( 0.11, 0.11, 0.11 );
            return color;
        }

        function fragment() {
            var uv = crtwarp( tuv, 4.2 );
            var c = rgshift( tex, uv );

            // discard
            c *= uv.x > 0 ? 1 : 0;
            c *= uv.y > 0 ? 1 : 0;
            c *= uv.x < 1 ? 1 : 0;
            c *= uv.y < 1 ? 1 : 0;

            // using screenspace coords forcibly produces a moire pattern, neat!
            c = darken( c, uv * screenres );
            c = scanline( c, uv * screenres );
            output.color = c;
        }
    };

#else
    // do nothing
    static var VERTEX = "
        attribute vec3 pos;
        uniform mat4 mproj;
        attribute vec2 uv;

        varying vec2 tuv;

        void main(void) {
            gl_Position = vec4(pos,1)*mproj;
            tuv = uv;
        }";

    static var FRAGMENT = "
        uniform sampler2D tex;
        varying vec2 tuv;
        void main(void) {
            gl_FragColor = texture2D(tex, tuv);
            //gl_FragColor = vec4(1,1,1,1);
        }
    ";
#end
}

class PostEffectsMaterial extends h3d.mat.Material{
    public var tex : h3d.mat.Texture;
    var pshader : PostEffectsShader;

    public function new( tex ) {
        this.tex = tex;
        pshader = new PostEffectsShader();
        addPass( new Pass( "default", null ) ).addShader( pshader );
        mainPass.culling = None;
        mainPass.blend(SrcAlpha, OneMinusSrcAlpha);
        super( pshader );
{'fraction_non_alphanumeric': 0.11929247223364871, 'fraction_numerical': 0.03167420814479638, 'mean_word_length': 1.4758995247793618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5140846', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2321, 'n_words': 700}