[Bf-blender-cvs] [4c08c5b1924] blender2.8: OpenGL: use new matrix names in GLSL

Mike Erwin noreply at git.blender.org
Mon Mar 27 07:18:21 CEST 2017


Commit: 4c08c5b192415190ab8b11637d8dc4f2a66c2ddf
Author: Mike Erwin
Date:   Sun Mar 26 21:19:23 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB4c08c5b192415190ab8b11637d8dc4f2a66c2ddf

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

===================================================================

M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/shaders/gpu_shader_2D_line_dashed_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_geometry.glsl
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_vertex.glsl
M	source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl

===================================================================

diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index fb86211d596..fed928b53ba 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -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",
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_vert.glsl
index e89b3262fab..7b4207142e6 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_vert.glsl
@@ -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);
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
index a0141f1ab2c..5f7455582cd 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
@@ -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++) {
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
index 42fbdadf1d1..dbf6c267f14 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
@@ -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;
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
index 71a43d1b7ae..fb1d0aafe05 100644
--- a/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
@@ -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;
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_geometry.glsl b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
index fe630dbeddb..545910d39ca 100644
--- a/source/blender/gpu/shaders/gpu_shader_geometry.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
@@ -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();
 }
 
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 0f3ffa8244b..67f1b45701c 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -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 + 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list