yglukhov / nimsl

Shaders in Nim language
MIT License
100 stars 8 forks source link

Supporting layout #4

Open abisxir opened 4 years ago

abisxir commented 4 years ago

Is it possible to support something like this:

#version 300 es
precision mediump float;

layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_normal;
layout(location = 2) in vec2 in_uv;
layout(location = 3) in vec3 in_tangent;
layout(location = 4) in vec3 in_binormal;
layout(location = 5) in mat4 in_model_matrix;

#define MAX_POINT_LIGHTS $MAX_POINT_LIGHTS$  
#define MAX_DIRECT_LIGHTS $MAX_DIRECT_LIGHTS$
#define MAX_INSTANCE $MAX_INSTANCE$

struct Material {
    vec3 diffuse_color;
    vec3 specular_color;
    bool has_diffuse_texture;
    bool has_specular_texture;
    bool has_normal_texture;
    bool cast_light;
    float shininess;
};

struct PointLight {    
    vec4 position;
    vec3 color;

    float constant;
    float linear;
    float quadratic;  
};  

struct DirectLight {
    vec3 direction;
    vec3 color;
};  

struct Fog
{
    int enabled;
    vec4 color;
    float density;
    float gradient;
};

uniform PointLight u_point_lights[MAX_POINT_LIGHTS];
uniform int u_point_light_count;
uniform DirectLight u_direct_lights[MAX_DIRECT_LIGHTS];
uniform int u_direct_light_count;
uniform Fog u_fog;
uniform Material u_material;
uniform vec3 u_ambient_color;

uniform mat4 u_view_matrix;
uniform mat4 u_projection_matrix;
uniform vec3 u_camera_position;
uniform sampler2D normal_texture;

I looked inside code but could not find a way, maybe it is possible but just it is not documented.

yglukhov commented 4 years ago

Sorry, not possible at the moment. PRs are welcome though :)

heysokam commented 1 year ago

Started learning nimsl yesterday, but lack of this feature is probably enough for me to stop using nimsl entirely.

How could one implement this feature, to be able to send that mentioned PR? Also, how extensive is this change? Are you sending us to PRs because of your lack of time due to external reasons, or because the feature could take a big amount of time to develop and you don't see its benefit?

Sorry if I sounded abrasive, I really like this library and want to use it for all my shader code, but this is a showstopper for me. So trying to see if there are any ways to navigate around it in a sensible way.

yglukhov commented 1 year ago

@heysokam at the moment I'm not interested in putting more effort into nimsl apart from keeping it working with newer nim versions, and maybe reviewing PRs. That might change anytime, but now it is what it is.

As for the feature I don't see it overly complex. On the nim side locations could be defined with pragmas, and then it has to be passed along to codegen.