1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Shaders Why does GMS2 leave the shader code exposed in the final export?

Discussion in 'Programming' started by Tyler D. Anderson, Jan 10, 2020.

  1. Tyler D. Anderson

    Tyler D. Anderson Member

    Joined:
    Jan 9, 2020
    Posts:
    9
    If I have an empty project with a simple shader:
    Code:
    //
    // Simple passthrough fragment shader
    //
    varying vec2 v_vTexcoord;
    varying vec4 v_vColour;
    
    void main()
    {
        float two = 2.;
        gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ) * two;
    }
    
    And I then compile it to a zip - I get a folder with the game.exe file and a data.win file. Now if I right-click and edit the data.win file in notepad I can find the following completely exposed:
    Code:
    precision mediump float;
    #define LOWPREC lowp
    // Uniforms look like they're shared between vertex and fragment shaders in GLSL, so we have to be careful to avoid name clashes
    
    uniform sampler2D gm_BaseTexture;
    
    uniform bool gm_PS_FogEnabled;
    uniform vec4 gm_FogColour;
    uniform bool gm_AlphaTestEnabled;
    uniform float gm_AlphaRefValue;
    
    void DoAlphaTest(vec4 SrcColour)
    {
        if (gm_AlphaTestEnabled)
        {
            if (SrcColour.a <= gm_AlphaRefValue)
            {
                discard;
            }
        }
    }
    
    void DoFog(inout vec4 SrcColour, float fogval)
    {
        if (gm_PS_FogEnabled)
        {
            SrcColour = mix(SrcColour, gm_FogColour, clamp(fogval, 0.0, 1.0));
        }
    }
    
    #define _YY_GLSLES_ 1
    //
    // Simple passthrough fragment shader
    //
    varying vec2 v_vTexcoord;
    varying vec4 v_vColour;
    
    void main()
    {
        float two = 2.;
        gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ) * two;
    }
    Can someone explain to me YYG's reasons for leaving the shader code so easily accessible like this?
     
    RujiK and matharoo like this.
  2. Tyler D. Anderson

    Tyler D. Anderson Member

    Joined:
    Jan 9, 2020
    Posts:
    9
    Oh, btw, I may have a solution to this problem writing a c++ extension. I simply don't understand the reasoning behind leaving it so easily exposed like this esp. since strings used to generate shader byte code are easily concealed within directx applications.
     
  3. gengo

    gengo Member

    Joined:
    Jan 23, 2020
    Posts:
    8

Share This Page