Darkyenus / glsl4idea

A GLSL language plugin for IntelliJ IDEA
GNU Lesser General Public License v3.0
101 stars 31 forks source link

Plugin does not recognize kivy shader separators. #136

Closed DaytonaJohn closed 6 years ago

DaytonaJohn commented 6 years ago

I am using Pycharm to do some glsl programming for Python/Kivy. The Kivy documentation states that:

To simplify shader management, the vertex and fragment shaders can be loaded automatically from a single glsl source file (plain text). The file should contain sections identified by a line starting with ‘—vertex’ and ‘—fragment’ respectively (case insensitive),

However, The plugin tags any such lines as errors. Would it be possible to have the plugin at least ignore such lines? Here is a sample glsl file that takes advantage of the Kivy capability:

/* simple.glsl

simple diffuse lighting based on laberts cosine law; see e.g.:
    http://en.wikipedia.org/wiki/Lambertian_reflectance
    http://en.wikipedia.org/wiki/Lambert%27s_cosine_law
*/
---VERTEX SHADER-------------------------------------------------------
#ifdef GL_ES
    precision highp float;
#endif

attribute vec3  v_pos;
attribute vec3  v_normal;

uniform mat4 modelview_mat;
uniform mat4 projection_mat;

varying vec4 normal_vec;
varying vec4 vertex_pos;

void main (void) {
    //compute vertex position in eye_space and normalize normal vector
    vec4 pos = modelview_mat * vec4(v_pos,1.0);
    vertex_pos = pos;
    normal_vec = vec4(v_normal,0.0);
    gl_Position = projection_mat * pos;
}

---FRAGMENT SHADER-----------------------------------------------------
#ifdef GL_ES
    precision highp float;
#endif

varying vec4 normal_vec;
varying vec4 vertex_pos;

uniform mat4 normal_mat;

void main (void){
    //correct normal, and compute light vector (assume light at the eye)
    vec4 v_normal = normalize( normal_mat * normal_vec ) ;
    vec4 v_light = normalize( vec4(0,0,0,1) - vertex_pos );
    //reflectance based on lamberts law of cosine
    float theta = clamp(dot(v_normal, v_light), 0.0, 1.0);
    gl_FragColor = vec4(theta, theta, theta, 1.0);
}
Darkyenus commented 6 years ago

It would be possible, but it would needlessly complicate the parsing grammar - and Kivy does not seem to be so widely used to be worth it. Additionally, if we ever get to it, it will mess up things like duplicate procedure/variable detection and other "smart" stuff.

I suspect that other GLSL editors will have the same problem, I'd try to persuade Kivy developers to make this prefix configurable, for example to something like: //---fragment, so that it is still valid GLSL. (If they accept PR's you could even add it yourself, the relevant parsing logic seems to be here.)