diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -2457,9 +2457,13 @@
                                 rel_param0.param_str, reg->idx[0].offset, shader->limits->constant_float,
                                 prefix, rel_param0.param_str, reg->idx[0].offset);
                     else if (reg->idx[0].offset)
-                        sprintf(register_name, "%s_c[%s + %u]", prefix, rel_param0.param_str, reg->idx[0].offset);
+                        sprintf(register_name, "(%s + %u >= 0 && %s + %u < %u ? %s_c[%s + %u] : vec4(0.0))",
+                                rel_param0.param_str, reg->idx[0].offset, rel_param0.param_str, reg->idx[0].offset,
+                                shader->limits->constant_float, prefix, rel_param0.param_str, reg->idx[0].offset);
                     else
-                        sprintf(register_name, "%s_c[%s]", prefix, rel_param0.param_str);
+                        sprintf(register_name, "(%s >= 0 && %s < %u ? %s_c[%s] : vec4(0.0))",
+                                rel_param0.param_str, rel_param0.param_str, shader->limits->constant_float,
+                                prefix, rel_param0.param_str);
                 }
                 else
                 {
