diff options
author | Norbert Preining <norbert@preining.info> | 2021-12-28 03:01:00 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-12-28 03:01:00 +0000 |
commit | ecdf859b6ce481abfd530425dcf6f0f764bd0001 (patch) | |
tree | 13bc161dc046876ac6c92fce5f9f5034ba9aa573 /graphics/asymptote/webgl/vertex.glsl | |
parent | 790995b7e79697514364450bf9c04f1b8d500838 (diff) |
CTAN sync 202112280300
Diffstat (limited to 'graphics/asymptote/webgl/vertex.glsl')
-rw-r--r-- | graphics/asymptote/webgl/vertex.glsl | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/graphics/asymptote/webgl/vertex.glsl b/graphics/asymptote/webgl/vertex.glsl index bf55fc0042..91b15463f1 100644 --- a/graphics/asymptote/webgl/vertex.glsl +++ b/graphics/asymptote/webgl/vertex.glsl @@ -1,13 +1,43 @@ -attribute vec3 position; +#ifdef WEBGL2 +#define IN in +#define OUT out +#else +#define IN attribute +#define OUT varying +#endif + +IN vec3 position; #ifdef WIDTH -attribute float width; +IN float width; #endif #ifdef NORMAL -attribute vec3 normal; +IN vec3 normal; #endif -attribute float materialIndex; + +IN float materialIndex; + +#ifdef WEBGL2 +flat out int MaterialIndex; #ifdef COLOR -attribute vec4 color; +OUT vec4 Color; +#endif + +#else +OUT vec4 diffuse; +OUT vec3 specular; +OUT float roughness,metallic,fresnel0; +OUT vec4 emissive; + +struct Material { + vec4 diffuse,emissive,specular; + vec4 parameters; +}; + +uniform Material Materials[Nmaterials]; +#endif + +#ifdef COLOR +IN vec4 color; #endif uniform mat3 normMat; @@ -16,39 +46,37 @@ uniform mat4 projViewMat; #ifdef NORMAL #ifndef ORTHOGRAPHIC -varying vec3 ViewPosition; +OUT vec3 ViewPosition; #endif -varying vec3 Normal; +OUT vec3 Normal; #endif -varying vec4 diffuse; -varying vec3 specular; -varying float roughness,metallic,fresnel0; -varying vec4 emissive; - -struct Material { - vec4 diffuse,emissive,specular; - vec4 parameters; -}; - -uniform Material Materials[Nmaterials]; void main(void) { vec4 v=vec4(position,1.0); gl_Position=projViewMat*v; + #ifdef NORMAL #ifndef ORTHOGRAPHIC ViewPosition=(viewMat*v).xyz; -#endif +#endif Normal=normalize(normal*normMat); - +#endif + +#ifdef WEBGL2 + MaterialIndex=int(materialIndex); +#ifdef COLOR + Color=color; +#endif +#else +#ifdef NORMAL Material m; #ifdef TRANSPARENT m=Materials[int(abs(materialIndex))-1]; emissive=m.emissive; - if(materialIndex >= 0.0) { + if(materialIndex >= 0.0) diffuse=m.diffuse; - } else { + else { diffuse=color; #if nlights == 0 emissive += color; @@ -64,8 +92,8 @@ void main(void) #endif #else diffuse=m.diffuse; -#endif -#endif +#endif // COLOR +#endif // TRANSPARENT specular=m.specular.rgb; vec4 parameters=m.parameters; roughness=1.0-parameters[0]; @@ -73,7 +101,9 @@ void main(void) fresnel0=parameters[2]; #else emissive=Materials[int(materialIndex)].emissive; -#endif +#endif // NORMAL +#endif // WEBGL2 + #ifdef WIDTH gl_PointSize=width; #endif |