OpenGL: use new matrix names in GLSL

Builtin names staring with gl_ will not be available in core profile. Same with the ftransform function. New matrix API provides the same names minus the gl_ prefix.

Part of T49450
This commit is contained in:
2017-03-26 21:19:23 -04:00
parent 2a7e4c3040
commit 4c08c5b192
10 changed files with 56 additions and 34 deletions

View File

@@ -788,7 +788,7 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
BLI_dynstr_appendf(ds, "#ifndef USE_OPENSUBDIV\n");
#endif
BLI_dynstr_appendf(
ds, "\tvar%d.xyz = normalize(gl_NormalMatrix * att%d.xyz);\n",
ds, "\tvar%d.xyz = normalize(NormalMatrix * att%d.xyz);\n",
input->attribid, input->attribid);
BLI_dynstr_appendf(
ds, "\tvar%d.w = att%d.w;\n",

View File

@@ -2,6 +2,8 @@
// Draw dashed lines, perforated in screen space.
// Based on a (3D) version by Mike Erwin.
uniform mat4 ModelViewProjectionMatrix;
#if __VERSION__ == 120
attribute vec2 pos;
attribute vec2 line_origin; // = pos for one vertex of the line
@@ -14,7 +16,7 @@
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
distance_along_line = distance(line_origin, pos);
}

View File

@@ -21,6 +21,10 @@
#define STIPPLE_DIAG_STRIPES 4
#define STIPPLE_DIAG_STRIPES_SWAP 5
#ifndef NO_SPECULAR
uniform mat4 ProjectionMatrix;
#endif
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if defined(USE_FLAT_NORMAL)
varying vec3 eyespace_vert_pos;
@@ -163,7 +167,7 @@ void main()
#ifndef NO_SPECULAR
/* view vector computation, depends on orthographics or perspective */
vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0);
vec3 V = (ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0);
#endif
for (int i = 0; i < NUM_SCENE_LIGHTS; i++) {

View File

@@ -1,4 +1,8 @@
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat3 NormalMatrix;
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if defined(USE_FLAT_NORMAL)
varying vec3 eyespace_vert_pos;
@@ -29,15 +33,15 @@ varying float gl_ClipDistance[6];
void main()
{
vec4 co = gl_ModelViewMatrix * gl_Vertex;
vec4 co = ModelViewMatrix * gl_Vertex;
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if !defined(USE_FLAT_NORMAL)
varying_normal = normalize(gl_NormalMatrix * gl_Normal);
varying_normal = normalize(NormalMatrix * gl_Normal);
#endif
#if defined(USE_FLAT_NORMAL)
/* transform vertex into eyespace */
eyespace_vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
eyespace_vert_pos = (ModelViewMatrix * gl_Vertex).xyz;
#endif
#ifndef USE_SOLID_LIGHTING
@@ -45,7 +49,7 @@ void main()
#endif
#endif
gl_Position = gl_ProjectionMatrix * co;
gl_Position = ProjectionMatrix * co;
#ifdef CLIP_WORKAROUND
int i;

View File

@@ -1,5 +1,5 @@
//mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewProjectionMatrix;
in vec3 pos;
in float edgeWidthModulator;
@@ -8,6 +8,6 @@ out vec4 pos_xformed;
out float widthModulator;
void main() {
pos_xformed = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
pos_xformed = ModelViewProjectionMatrix * vec4(pos, 1.0);
widthModulator = edgeWidthModulator;
}

View File

@@ -1,3 +1,6 @@
uniform mat4 ProjectionMatrix;
uniform int PrimitiveIdBase;
uniform int osd_active_uv_offset;
@@ -69,7 +72,7 @@ void emit_flat(int index, vec3 normal)
set_mtface_vertex_attrs(st);
gl_Position = gl_ProjectionMatrix * inpt[index].v.position;
gl_Position = ProjectionMatrix * inpt[index].v.position;
EmitVertex();
}
@@ -90,7 +93,7 @@ void emit_smooth(int index)
set_mtface_vertex_attrs(st);
gl_Position = gl_ProjectionMatrix * inpt[index].v.position;
gl_Position = ProjectionMatrix * inpt[index].v.position;
EmitVertex();
}

View File

@@ -177,7 +177,7 @@ void geom(
out vec3 normal, out vec4 vcol, out float vcol_alpha, out float frontback)
{
local = co;
view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(local) : vec3(0.0, 0.0, -1.0);
view = (ProjectionMatrix[3][3] == 0.0) ? normalize(local) : vec3(0.0, 0.0, -1.0);
global = (viewinvmat * vec4(local, 1.0)).xyz;
orco = attorco;
uv_attribute(attuv, uv);
@@ -1413,8 +1413,8 @@ void mtex_bump_init_objspace(
out float fPrevMagnitude_out, out vec3 vNacc_out,
out vec3 vR1, out vec3 vR2, out float fDet)
{
mat3 obj2view = to_mat3(gl_ModelViewMatrix);
mat3 view2obj = to_mat3(gl_ModelViewMatrixInverse);
mat3 obj2view = to_mat3(ModelViewMatrix);
mat3 view2obj = to_mat3(ModelViewMatrixInverse);
vec3 vSigmaS = view2obj * dFdx(surf_pos);
vec3 vSigmaT = view2obj * dFdy(surf_pos);
@@ -1670,7 +1670,7 @@ void mtex_nspace_world(mat4 viewmat, vec3 texnormal, out vec3 outnormal)
void mtex_nspace_object(vec3 texnormal, out vec3 outnormal)
{
outnormal = normalize(gl_NormalMatrix * texnormal);
outnormal = normalize(NormalMatrix * texnormal);
}
void mtex_blend_normal(float norfac, vec3 normal, vec3 newnormal, out vec3 outnormal)
@@ -1794,7 +1794,7 @@ void lamp_visibility_clamp(float visifac, out float outvisifac)
void world_paper_view(vec3 vec, out vec3 outvec)
{
vec3 nvec = normalize(vec);
outvec = (gl_ProjectionMatrix[3][3] == 0.0) ? vec3(nvec.x, 0.0, nvec.y) : vec3(0.0, 0.0, -1.0);
outvec = (ProjectionMatrix[3][3] == 0.0) ? vec3(nvec.x, 0.0, nvec.y) : vec3(0.0, 0.0, -1.0);
}
void world_zen_mapping(vec3 view, float zenup, float zendown, out float zenfac)
@@ -1828,7 +1828,7 @@ void world_blend(vec3 vec, out float blend)
void shade_view(vec3 co, out vec3 view)
{
/* handle perspective/orthographic */
view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(co) : vec3(0.0, 0.0, -1.0);
view = (ProjectionMatrix[3][3] == 0.0) ? normalize(co) : vec3(0.0, 0.0, -1.0);
}
void shade_tangent_v(vec3 lv, vec3 tang, out vec3 vn)
@@ -2346,7 +2346,7 @@ void shade_mist_factor(
if (enable == 1.0) {
float fac, zcor;
zcor = (gl_ProjectionMatrix[3][3] == 0.0) ? length(co) : -co[2];
zcor = (ProjectionMatrix[3][3] == 0.0) ? length(co) : -co[2];
fac = clamp((zcor - miststa) / mistdist, 0.0, 1.0);
if (misttype == 0.0) fac *= fac;
@@ -2605,11 +2605,11 @@ void node_emission(vec4 color, float strength, vec3 N, out vec4 result)
void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
{
vec4 v = (gl_ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
vec4 co_homogenous = (gl_ProjectionMatrixInverse * v);
vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
vec4 co_homogenous = (ProjectionMatrixInverse * v);
vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
worldvec = (gl_ModelViewMatrixInverse * co).xyz;
worldvec = (ModelViewMatrixInverse * co).xyz;
}
void node_background(vec4 color, float strength, vec3 N, out vec4 result)
@@ -2634,7 +2634,7 @@ void node_add_shader(vec4 shader1, vec4 shader2, out vec4 shader)
void node_fresnel(float ior, vec3 N, vec3 I, out float result)
{
/* handle perspective/orthographic */
vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
float eta = max(ior, 0.00001);
result = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? eta : 1.0 / eta);
@@ -2646,7 +2646,7 @@ void node_layer_weight(float blend, vec3 N, vec3 I, out float fresnel, out float
{
/* fresnel */
float eta = max(1.0 - blend, 0.00001);
vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? 1.0 / eta : eta);
@@ -2700,7 +2700,7 @@ void node_geometry(
true_normal = normal;
/* handle perspective/orthographic */
vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
incoming = -(toworld * vec4(I_view, 0.0)).xyz;
parametric = vec3(0.0);
@@ -2719,7 +2719,7 @@ void node_tex_coord(
uv = attr_uv;
object = (obinvmat * (viewinvmat * vec4(I, 1.0))).xyz;
camera = vec3(I.xy, -I.z);
vec4 projvec = gl_ProjectionMatrix * vec4(I, 1.0);
vec4 projvec = ProjectionMatrix * vec4(I, 1.0);
window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0);
vec3 shade_I;
@@ -2734,13 +2734,13 @@ void node_tex_coord_background(
out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
out vec3 camera, out vec3 window, out vec3 reflection)
{
vec4 v = (gl_ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
vec4 co_homogenous = (gl_ProjectionMatrixInverse * v);
vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
vec4 co_homogenous = (ProjectionMatrixInverse * v);
vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
co = normalize(co);
vec3 coords = (gl_ModelViewMatrixInverse * co).xyz;
vec3 coords = (ModelViewMatrixInverse * co).xyz;
generated = coords;
normal = -coords;
@@ -2748,7 +2748,7 @@ void node_tex_coord_background(
object = coords;
camera = vec3(co.xy, -co.z);
window = (gl_ProjectionMatrix[3][3] == 0.0) ?
window = (ProjectionMatrix[3][3] == 0.0) ?
vec3(mtex_2d_mapping(I).xy * camerafac.xy + camerafac.zw, 0.0) :
vec3(vec2(0.5) * camerafac.xy + camerafac.zw, 0.0);

View File

@@ -1,4 +1,6 @@
uniform mat4 ModelViewProjectionMatrix;
varying vec3 coords;
uniform vec3 min_location;
@@ -7,6 +9,6 @@ uniform vec3 ob_sizei;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
gl_Position = ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
coords = (gl_Vertex.xyz - min_location) * invsize;
}

View File

@@ -1,3 +1,8 @@
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat3 NormalMatrix;
#ifdef USE_OPENSUBDIV
in vec3 normal;
in vec4 position;
@@ -89,11 +94,11 @@ void main()
vec3 normal = gl_Normal;
#endif
vec4 co = gl_ModelViewMatrix * position;
vec4 co = ModelViewMatrix * position;
varposition = co.xyz;
varnormal = normalize(gl_NormalMatrix * normal);
gl_Position = gl_ProjectionMatrix * co;
varnormal = normalize(NormalMatrix * normal);
gl_Position = ProjectionMatrix * co;
#ifdef CLIP_WORKAROUND
int i;

View File

@@ -1,7 +1,9 @@
uniform mat4 ModelViewProjectionMatrix;
varying vec4 v_position;
void main()
{
gl_Position = ftransform();
gl_Position = ModelViewProjectionMatrix * v_position;
v_position = gl_Position;
}