Jump to content

havenphillip

Members
  • Posts

    550
  • Joined

  • Last visited

Posts posted by havenphillip

  1. I did a high-pass filter:

     

     

    VERTEX:

     

    #version 400

    uniform mat4 projectionmatrix;
    uniform mat4 drawmatrix;
    uniform vec2 offset;
    uniform vec2 position[4];

    in vec3 vertex_position;

    void main(void)
    {
        gl_Position = projectionmatrix * (drawmatrix * vec4(position[gl_VertexID]+offset, 0.0, 1.0));
    }

     

    FRAGMENT:

     

     

    //from https://learnopengl.com/Advanced-OpenGL/Framebuffers

    #version 400

    //Variables
    float pass_mix = 0.5;
    float spread = 1000.0;
    float brightness = 1.3;

    //Uniforms
    uniform sampler2D texture1;
    uniform bool isbackbuffer;
    uniform vec2 buffersize;

    //Outputs
    out vec4 fragData0;

    float offset = 1.0 / spread;  

    vec3 blendMultiply(vec3 base, vec3 blend) {
        return base*blend;
    }

    vec3 blendMultiply(vec3 base, vec3 blend, float opacity) {
        return (blendMultiply(base, blend) * opacity + base * (1.0 - opacity));
    }

    void main(void)
    {
        vec2 coord = vec2(gl_FragCoord.xy/buffersize);
        if (isbackbuffer) coord.y = 1.0 - coord.y;
        
        vec4 outcol = texture(texture1,coord);

        vec2 offsets[9] = vec2[](
            vec2(-offset,  offset), // top-left
            vec2( 0.0f,    offset), // top-center
            vec2( offset,  offset), // top-right
            vec2(-offset,  0.0f),   // center-left
            vec2( 0.0f,    0.0f),   // center-center
            vec2( offset,  0.0f),   // center-right
            vec2(-offset, -offset), // bottom-left
            vec2( 0.0f,   -offset), // bottom-center
            vec2( offset, -offset)  // bottom-right    
        );
        
        //Blur
        float kernel[9] = float[](
            1.0 / 16, 2.0 / 16, 1.0 / 16,
            2.0 / 16, 4.0 / 16, 2.0 / 16,
            1.0 / 16, 2.0 / 16, 1.0 / 16  
        );
        
        vec3 sampleTex[9];
        for(int i = 0; i < 9; i++)
        {
            sampleTex[i] = vec3(texture(texture1, coord + offsets[i]));
        }
        vec3 col = vec3(0.0);
        for(int i = 0; i < 9; i++)
            col += sampleTex[i] * kernel[i];
            
        //High Pass
        vec3 high_pass = 0.5 - 8.0 * (col - outcol.xyz);

        //Output
        fragData0.xyz = blendMultiply(outcol.xyz,high_pass,0.5);
        //fragData0 = vec4(high_pass,1); //pure high pass
    }

     

     

     

    • Like 1
  2. You can try changing the bottom of the shader like this. This works in the material editor for me.

     

    #if BFN_ENABLED==1
        //Best-fit normals
        fragData1 = texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z)));
        fragData1.a = fragData0.a;
    #else
        //Low-res normals
        fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a);
    #endif
        int materialflags=1;
        if (ex_selectionstate>0.0) materialflags += 2;
        fragData1.a = materialflags/255.0;

     

        float specular = color_specular.r * 0.299 + color_specular.g * 0.587 + color_specular.b * 0.114;

        fragData2 = vec4(0.0,0.0,0.0,specular);

        vec3 dissolve_col = vec3(0,1,0);
        if (NoiseV<InvAlpha+0.03) fragData2 = vec4(dissolve_col,specular);

    }

     

    • Thanks 1
  3. I'm snowed in I have limited power/internet. I'll get back to you on it but it looks like the specular affects it because he made the specular channel and the normals alpha channel the same. I tend to think Shadmar knows what he's doing and I'm not sure why he did it this way but I'm sure the fix will be pretty easy.

  4. Is it red in the Material Editor? If so it could be your normals alpha channel.

    Edit: I just saw the picture it looks like it is. The first thing I would do is check your fragData1 lines in the Fragment shader. They should look like:

        //Normals Output
        fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a);
        fragData1.a = 1/255.0;

  5. 11 hours ago, klepto2 said:

    How do you create the reflection texture? And how do you assign it? I am very sure that this will not work from within the editor as the scripts are not updated (except postprocessing).

    Just using the shader from above.  That's why I'm wondering if I need to use a script like a Render function or something. It does look like that in game too. The one I was using has a similar problem it looks ok until I look down then I get this. I dont' know what it is but it looks like maybe it has to do with the buffer not fitting to the screen?

    reflectionprob.jpg

  6. This is what I have:

    VERTEX:

    void main()
    {
        //entity matrix
        mat4 entitymatrix = entity.matrix[gl_InstanceID];
        mat4 entitymatrix_ = entitymatrix;
        entitymatrix_[0][3]=0.0;
        entitymatrix_[1][3]=0.0;
        entitymatrix_[2][3]=0.0;
        entitymatrix_[3][3]=1.0;
        
        //model position
        ex_vertexposition = entitymatrix_ * vec4(vertex_position,1);
        gl_Position = projectioncameramatrix * ex_vertexposition;

        //clip
        float cam = cameraposition.y;
        float c = 2 * (cam - ex_vertexposition.y);    
        vec4 e = ex_vertexposition;
        e.y += c;
        clipspace = projectioncameramatrix * e;

        //normals
        mat3 nmat = mat3(entitymatrix_);
        ex_normal = normalize(nmat * vertex_normal);
        ex_binormal = normalize(nmat * vertex_binormal);    
        ex_tangent = normalize(nmat * vertex_tangent);

        ex_texcoords0 = vertex_texcoords0;
    }

     

    FRAGMENT:

     

    void main()
    {

        //Normal
        vec3 normal = ex_normal;
        normal = normalize(texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0);
        normal = ex_tangent * normal.x + ex_binormal * normal.y + ex_normal * normal.z;    
        normal = normalize(normal);

        vec4 clip = clipspace;
        clip.xyz *= vec3(1,-1,1);
        clip.x = (clip.x / clip.w) * 0.5 + 0.5;
        clip.y = (clip.y / clip.w) * 0.5 + 0.5;

        //Reflection
        vec4 reflection = texture(texture10,clip.xy)*0.8;

        //Diffuse Output
        fragData0 = reflection;
    }

     

     

  7. This is an interesting idea. I'm thinking maybe somehow use a PostEffect fog then thin it out or thicken it based on the distance of the cameraposition to the "center" of it. I'm going to try this. Something like:

    output = mix(regular screen, foggy screen, distance(cameraposition , self.entity:GetPosition())))

  8. I'm not that good at scripting but I think maybe put the self.Updatecamera() line in the UpdatePhysics() function? I think the Start() function would only update the camera once at the beginning and that's all. You want it to keep updating. Something like that

    • Upvote 1
  9. If the problem's in the shader I can probably figure it out. If you get stuck you can send it to me and I'll fiddle with it. But my best guess - assuming it's not a bug, is that either the shader is not compiling or maybe you made a change and forgot to hit save somewhere so the changes didn't update.

    • Like 1
  10. Hey Josh how did you get the planar reflections to stop following the camera on the water? Seems like no matter what I do if I nod the cam "yes" the reflection wont' stay put. This is what I have. I'm stuck here:


    vec2 coord = gl_FragCoord.xy/buffersize;

    if (isbackbuffer) coord.y = 1-coord.y;

    vec4 reflectcol = texture(texture10,coord);

    fragData0 = reflectcol;

×
×
  • Create New...