Shader Bug

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Mit Shadern habe ich mich ja schon immer schwer getan xD

    Vielleicht erinnert ihr euch ja noch an meine Probleme mit den Silhouetten. Die habe ich zwar behoben, aber mir ist ein anderer "Bug" aufgefallen: Der Bereich, indem die Silhouette vom Player gezeichnet wird, ist etwas größer als mein Objekt obj_tree (Bild). Das heißt, der Player wird schon grün eingezeichnet, selbst wenn er gar nicht wirklich hinter dem Baum steht.

    Mein Shader shd_silhouette Vertex:

    GML-Quellcode

    1. ​attribute vec3 in_Position;
    2. attribute vec4 in_Colour;
    3. attribute vec2 in_TextureCoord;
    4. varying vec2 v_vTexcoord;
    5. varying vec4 v_vColour;
    6. varying vec4 v_vPos; //The "real world" coordinates of this vertex
    7. void main() {
    8. vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    9. v_vPos = gm_Matrices[MATRIX_WORLD] * object_space_pos;
    10. gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    11. v_vColour = in_Colour;
    12. v_vTexcoord = in_TextureCoord;
    13. }
    Alles anzeigen


    Mein Shader shd_silhouette Fragment:

    GML-Quellcode

    1. ​varying vec2 v_vTexcoord;
    2. varying vec4 v_vColour;
    3. varying vec4 v_vPos; //The "real world" coordinates of this texel
    4. uniform float u_fSilhDepth;
    5. uniform vec4 u_vSilhView;
    6. uniform vec3 u_cSilhColour;
    7. uniform sampler2D u_sSilhSurface;
    8. void main() {
    9. vec2 samplePos = v_vPos.xy - u_vSilhView.xy; //Relative position of vertex in the view
    10. vec4 sampleColour = texture2D( u_sSilhSurface, samplePos / u_vSilhView.zw ); //Sample the mask surface
    11. float sampleDepth = samplePos.y + sampleColour.r * 256.0; //Calculate the depth of this texel by adding the offset from the mask surface
    12. float sprDepth = u_fSilhDepth - u_vSilhView.y; //Relative y-position of the sprite being drawn in the view
    13. if ( ( sampleDepth > sprDepth ) && ( sampleColour.a > 0.02 ) ) {
    14. gl_FragColor = vec4( u_cSilhColour, v_vColour.a * texture2D( gm_BaseTexture, v_vTexcoord ).a );
    15. }
    16. }
    Alles anzeigen


    Mein Shader shd_mask Vertex:

    GML-Quellcode

    1. attribute vec3 in_Position;
    2. attribute vec4 in_Colour;
    3. attribute vec2 in_TextureCoord;
    4. varying vec2 v_vTexcoord;
    5. varying vec4 v_vColour;
    6. void main() {
    7. vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    8. gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    9. v_vColour = in_Colour;
    10. v_vTexcoord = in_TextureCoord;
    11. }​
    Alles anzeigen


    Mein Shader shd_mask Fragment:

    GML-Quellcode

    1. varying vec2 v_vTexcoord;
    2. varying vec4 v_vColour;
    3. void main() {
    4. gl_FragColor = vec4( v_vColour.rgb, v_vColour.a * texture2D( gm_BaseTexture, v_vTexcoord ).a );
    5. }​


    Ich denke, der Fehler liegt irgendwo in einem dieser beiden Shader, ansonsten hier noch das Script:

    Script scr_silhouette_set:

    GML-Quellcode

    1. with( obj_silhouette ) {
    2. var shader = shd_silhouette;
    3. var surface = sur_silhouette;
    4. shader_set( shader );
    5. texture_set_stage( shader_get_sampler_index( shader, "u_sSilhSurface" ), surface_get_texture( surface ) );
    6. shader_set_uniform_f( shader_get_uniform( shader, "u_vSilhView" ), view_xview[0], view_yview[0], view_wview[0], view_hview[0] );
    7. shader_set_uniform_f( shader_get_uniform( shader, "u_cSilhColour" ), colour_get_red( argument1 ) / 255, colour_get_green( argument1 ) / 255, colour_get_blue( argument1 ) / 255 );
    8. shader_set_uniform_f( shader_get_uniform( shader, "u_fSilhDepth" ), argument0 );
    9. }​
    Alles anzeigen


    Ich möchte euch jetzt noch ungern mein ganzes obj_silhouette reinschreiben, da ich nicht weiß ob es notwendig ist, ich vermute der Fehler liegt irgendwo in einem der Shader oder im Script... Falls ihr das Objekt obj_silhouette aber braucht, schreibe ich es gerne rein ^^

    Sorry ist dieses mal sehr viel Text :(
    Bilder
    • Shader Bug.png

      577,21 kB, 1.920×1.080, 669 mal angesehen
    Es gibt 10 Arten von Menschen: Diejenigen, die Binärcode verstehen und die, die es nicht tun ^^
  • Bin eben erst nach Hause gekommen. Ich denke du solltest das Sprite auf ein Surface malen, den nähsten Baum finden, und wenn er damit kollidiert den Baum als Maske benutzen. GMs blend modes reichen aus um dann genau den Teil Grün erscheinen zu lassen.
    132 little bugs in the code. 132 little bugs. Fix a few, set the compiler to stew, 172 little bugs in the code... :vogel: