diff options
Diffstat (limited to 'drivers/gles3/shaders/scene.glsl')
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index ffc41e611b..43a391631f 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -52,6 +52,10 @@ layout(location=9) in highp vec4 instance_xform1; layout(location=10) in highp vec4 instance_xform2; layout(location=11) in lowp vec4 instance_color; +#if defined(ENABLE_INSTANCE_CUSTOM) +layout(location=12) in highp vec4 instance_custom_data; +#endif + #endif layout(std140) uniform SceneData { //ubo:0 @@ -157,9 +161,21 @@ out highp vec4 position_interp; void main() { highp vec4 vertex = vertex_attrib; // vec4(vertex_attrib.xyz * data_attrib.x,1.0); - highp mat4 modelview = camera_inverse_matrix * world_transform; + + mat4 world_matrix = world_transform; + + +#ifdef USE_INSTANCING + + { + highp mat4 m=mat4(instance_xform0,instance_xform1,instance_xform2,vec4(0.0,0.0,0.0,1.0)); + world_matrix = world_matrix * transpose(m); + } +#endif + vec3 normal = normal_attrib * normal_mult; + #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) vec3 tangent = tangent_attrib.xyz; tangent*=normal_mult; @@ -168,6 +184,10 @@ void main() { #if defined(ENABLE_COLOR_INTERP) color_interp = color_attrib; +#if defined(USE_INSTANCING) + color_interp *= instance_color; +#endif + #endif #ifdef USE_SKELETON @@ -215,40 +235,12 @@ void main() { } #endif -#ifdef USE_INSTANCING - - { - highp mat3x4 m=mat3x4(instance_xform0,instance_xform1,instance_xform2); - vertex.xyz = vertex * m; - normal = vec4(normal,0.0) * m; #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) - tangent.xyz = vec4(tangent.xyz,0.0) * mn; -#endif -#if defined(ENABLE_COLOR_INTERP) - color_interp*=instance_color; -#endif - } -#endif //USE_INSTANCING - -#if !defined(SKIP_TRANSFORM_USED) - - vertex = modelview * vertex; - normal = normalize((modelview * vec4(normal,0.0)).xyz); -#endif - -#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) -# if !defined(SKIP_TRANSFORM_USED) - - tangent=normalize((modelview * vec4(tangent,0.0)).xyz); -# endif vec3 binormal = normalize( cross(normal,tangent) * binormalf ); #endif - - - #if defined(ENABLE_UV_INTERP) uv_interp = uv_attrib; #endif @@ -257,16 +249,45 @@ void main() { uv2_interp = uv2_attrib; #endif +#if defined(USE_INSTANCING) && defined(ENABLE_INSTANCE_CUSTOM) + vec4 instance_custom = instance_custom_data; +#else + vec4 instance_custom = vec4(0.0); +#endif + + highp mat4 modelview = camera_inverse_matrix * world_matrix; + highp mat4 local_projection = projection_matrix; + +//defines that make writing custom shaders easier +#define projection_matrix local_projection +#define world_transform world_matrix { VERTEX_SHADER_CODE } + + + +#if !defined(SKIP_TRANSFORM_USED) + + vertex = modelview * vertex; + normal = normalize((modelview * vec4(normal,0.0)).xyz); +#endif + + vertex_interp = vertex.xyz; normal_interp = normal; #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) + +#if !defined(SKIP_TRANSFORM_USED) + + tangent = normalize((modelview * vec4(tangent,0.0)).xyz); + binormal = normalize((modelview * vec4(binormal,0.0)).xyz); + +#endif tangent_interp = tangent; binormal_interp = binormal; #endif |