OpenGL GLSL ES 3.10 – Referencing a uniform variable, causes the vertex shader to not draw anything

I have this project, that has a default shader, that just draws models and textures. Recently I decided to add a second shader that does a fancy effect, and is used only on some of the objects drawn.

After compiling the project for Linux or Windows, it all works as expected. When compiling the project to Android, only on specific devices, the new shader doesn’t work, while on other devices I tried, it all works.

My shaders

Below is my default vertex shader specifically made for Android devices, this one works on all devices and draws everything without any editing or effect. As far as I understand, the fragment shaders work, so I’ll omit them.

    #version 310 es      in vec4 position;     in vec3 colour;     in vec2 texCoord;      uniform mat4 matrix;     uniform mat4 matrixProjection;      out vec2 outTexCoord;     out vec4 outColour;      void main() {             gl_Position = matrixProjection *matrix *position;             outTexCoord  = texCoord;             outColour  = vec4(colour.rgb, 1);     } 

I hope this looks fairly straight-forward. matrixProjection is the projection matrix, and matrix is the model-view matrix. They both work as expected and I’m able to render a whole scene without issue.

Now here is a simplified version of my new shader:

    #version 310 es      in vec4 position;     in vec3 colour;     in vec2 texCoord;      uniform mat4 matrix;     uniform mat4 matrixProjection;     uniform float animationCurrent;      out vec2 outTexCoord;     out vec4 outColour;      void main() {             gl_Position = matrixProjection *matrix *position;              if (animationCurrent > 0.0) {                     gl_Position.y += 5.0;             }              outColour = vec4(colour.rgb, 1.0);             outTexCoord  = texCoord;     } 

The only difference of the new shader is the new uniform animationCurrent, and an extra if statement that will modify the gl_Position.y of some vertices. Any object that is using this shader, is not drawn at all on the screen on some devices.

What I’ve tried

From the new shader, if I remove the entire if statement, it all works and it displays objects as-is. If I replace the if statement with if (true) it still works, but it just displays all vertices of objects drawn with it slightly higher. If I replace it with if (false) it still works as expected.

So for some reason, just referencing animationCurrent causes the object to not be drawn.

I also tried replacing the if statement with if (matrix[0][0] > 0.0) and it still draws the object, it looks like there’s something specifically wrong with animationCurrent. I tried adding another matrix uniform variable, and set its value the same way as I do matrix, but it wouldn’t draw the object either.

This should mean that the value of animationCurrent is not relevant, and the fact that it’s a uniform float doesn’t matter either.

Hardware

The problem occurs on an android phone with this hardware:

Device: Moto E (4) Plus - 7.1.1 Vendor graphic card: ARM Renderer: Mali-T720 Version OpenGL: OpenGL ES 3.1 v1.r12p1-01alp0.62f282720426ab7712f1c6b996a6dc82 Version GLSL: OpenGL ES GLSL ES 3.10 

And this android tablet with similar hardware:

Device: Kindle Fire 8 Vendor graphic card: ARM Renderer: Mali-T720 Version GL: OpenGL ES 3.1 v1.r26p0-01rel0.526d936ea9da20486773a9aaceecd920 Version GLSL: OpenGL ES GLSL ES 3.10 

This is an android tablet where everything works as expected:

Device: Lenovo TB-X505F - 10 Vendor graphic card: Qualcomm Renderer: Adreno (TM) 504 Version GL: OpenGL ES 3.2 V@415.0 (GIT@f345350, I0760943699, 1580221225) (Date:01/28/20) Version GLSL: OpenGL ES GLSL ES 3.20 

And here is a slightly older device that works. I’ve modified the shader a bit to support an older glsl version, but the idea is the same:

Device: Kindle Fire 7 Vendor graphic card: ARM Renderer: Mali-450 MP Version GL: OpenGL ES 2.0 Version GLSL: OpenGL ES GLSL ES 1.00 

Question

My primary goal, is to understand what is causing this. Have I missed something very obvious? Is this a very edge-case bug related to the hardware?

I’m still learning how to support different devices with different versions of glsl, so it’s very likely I’ve missed something.

Any information you have, let me know. I’m willing to try a few things on different devices to find more about this issue.

Increase variable increments of one

The idea is to have image that when i click on it it makes the number below it go up by one. I will post a copy of my html and javascript below.

JAVASCRIPT
function increasedigit(digitnumber) {
var x = document.getElementById(digitnumber).innerHTML;
if (x > 9) {
x++;
}
else
{
x == 0;
}
document.getElementById.innerHTML = x;
}

HTML
<div class="two">
<img onclick="increasedigit(digitone)" class="arrowgeneral"…

Increase variable increments of one

Rename a variable in a pattern by an evaluation

I wish to take some expression containing instances of Pattern[], and rename the variables of those patterns based on evaluation featuring the variable.

Let’s say my renaming function is

f[s_Symbol] := Symbol[ SymbolName[s], "2" ] 

which just appends 2 to symbol names:

f[a] >>> a2 

If I try to replace Pattern variables with this function (or any expression), that expression remains unevaluated!

a_ /. a :> f[a] >>> Pattern[ f[a], _ ] 

I assume Pattern holds its first argument.

Naturally my example is strange since simplified; I really intend to replace any symbol (which may or may not be featured in a Pattern) which satisifes certain properties.

a_ /. s_Symbol /; someTest[s] :> f[s] >>> Pattern[ f[a], _ ] 

How can I force Pattern to evaluate its first argument after my substitution?

I cannot just insert an Evaluate into the RHS of my DelayedRule (though that solves my first example), since this just violates the rule delay, and invokes f[s].

For dynamically batched objects the `unity_ObjectToWorld` shader variable is always set to default?

I’m using the standard render pipeline and the unity_ObjectToWorld variable for some calculations in my shader. After I enabled dynamic batching these calculations got broken. It seems that unity_ObjectToWorld is set to default when the objects are being batched. Is it by design? I didn’t find anything in the documentation.

Assign function to a variable and solve it symbolically

I have a function such as y = sin(x) + c. I’d like to solve it symbolically for c (but first assign the function to a variable, so I don’t have to enter it multiple times in case I want to solve it for x as well. Any suggestions how I can do this?

I’ve tried this:

fn[x_, c_] := Sin[x] + c Solve[fn, c] 

but getting an error ‘fn is not a quantified system of equations’.

Any help is appreciated.

widget() method can’t access $instance variable WordPress

I followed a guide to create a WordPress plugin, which shows a youtube sub button on your page.

In the guide it works perfectly, but for some reason it doesn’t work for me.

This is my problem: When I var_dump($ instance) in widget() it prints out an empty array, but when I try to print_r($ instance) inside of my form() it prints out the correct information

Here is the widget file:

<?php  /**   * Adds Youtube_Subs widget.   */  class Youtube_Subs_Widget extends WP_Widget {    /**   * Register widget with WordPress.   */  function __construct() {    parent::__construct(      'youtubesubs_widget', // Base ID      esc_html__( 'YouTube Subs', 'mp_domain' ), // Name      array( 'description' => esc_html__( 'Widget to display YouTube subs', 'mp_domain' ), ) // Args    );  }    /**   * Front-end display of widget.   *   * @see WP_Widget::widget()   *   * @param array $  args     Widget arguments.   * @param array $  instance Saved values from database.   */  public function widget( $  args, $  instance ) {    echo $  args['before_widget']; // Whatever you want to display before widget (<div>, etc)    if ( ! empty( $  instance['title'] ) ) {      echo $  args['before_title'] . apply_filters( 'widget_title', $  instance['title'] ) . $  args['after_title'];    }     // Widget Content Output    var_dump($  instance);    // echo '<div class="g-ytsubscribe" data-channel="'.$  instance['channel'].'" data-layout="'.$  instance['layout'].'" data-count="'.$  instance['count'].'"></div>';      echo $  args['after_widget']; // Whatever you want to display after widget (</div>, etc)  }    /**   * Back-end widget form.   *   * @see WP_Widget::form()   *   * @param array $  instance Previously saved values from database.   */  public function form( $  instance ) {    $  title = (! empty( $  instance['title'] ) ? $  instance['title'] : esc_attr( 'YouTube Subs', 'mp_domain' ));      $  channel = (! empty( $  instance['channel'] ) ? $  instance['channel'] : esc_attr( 'techguyweb', 'mp_domain' ));      $  layout = (! empty( $  instance['layout'] ) ? $  instance['layout'] : esc_attr( 'default', 'mp_domain' ));      $  count = (! empty( $  instance['count'] ) ? $  instance['count'] : esc_attr( 'default', 'mp_domain' ));      ?>        <!-- TITLE -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>">        <?php esc_attr_e( 'Title:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'title' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  title ); ?>">    </p>      <!-- CHANNEL -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>">        <?php esc_attr_e( 'Channel:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'channel' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  channel ); ?>">    </p>      <!-- LAYOUT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>">        <?php esc_attr_e( 'Layout:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'layout' ) ); ?>">        <option value="default" <?php echo ($  layout == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="full" <?php echo ($  layout == 'full') ? 'selected' : ''; ?>>          Full        </option>      </select>    </p>      <!-- COUNT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>">        <?php esc_attr_e( 'Count:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'count' ) ); ?>">        <option value="default" <?php echo ($  count == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="hidden" <?php echo ($  count == 'hidden') ? 'selected' : ''; ?>>          Hidden        </option>      </select>    </p>    <?php       print_r($  instance);  }    /**   * Sanitize widget form values as they are saved.   *   * @see WP_Widget::update()   *   * @param array $  new_instance Values just sent to be saved.   * @param array $  old_instance Previously saved values from database.   *  * @return array Updated safe values to be saved.  */ public function update( $  new_instance, $  old_instance ) {   $  instance = $  old_instance;    $  instance['title'] = ( ! empty( $  new_instance['title'] ) ) ? strip_tags( $  new_instance['title'] ) : '';   $  instance['channel'] = ( ! empty( $  new_instance['channel'] ) ) ? strip_tags( $  new_instance['channel'] ) : '';   $  instance['layout'] = ( ! empty( $  new_instance['layout'] ) ) ? strip_tags( $  new_instance['layout'] ) : '';   $  instance['count'] = ( ! empty( $  new_instance['count'] ) ) ? strip_tags( $  new_instance['count'] ) :      '';         return $  instance;  } } 

I have this hooked up with my plugin file in where I register the widget:

 // Register Widget  function register_myplugin() {      register_widget('Youtube_Subs_Widget');  }   // Hook in function  add_action('widgets_init', 'register_myplugin'); 

I hope someone knows what is wrong and can help me correct my mistake, thanks in advance

Isolate variable in inequality

I’m having the most stupid of problems. Suppose I have a simple inequality like $ $ |2-x|>2.$ $

The solution to this is

$ $ x<0 , \,x>4.$ $

This is pretty obvious, though mathematica insists on spitting back the input:

Reduce[Abs[2 - x] > 2] 

outputs

Abs[2 - x] > 2 

How can I tell Mathematica I want a series of expression with only $ x$ on the LHS? Trying to solve for $ x$ only makes Mathematica complain that the solution is full-dimensional, I assume this means that Solve can only output single points and not intervals. I also suspect this has to do with the fact that Mathematica doesn’t really know $ x$ is real, but

FullSimplify[Reduce[Abs[2-x] > 2], Assumptions -> x \[Element] Reals] 

produces the same result.

Is it possible to not differentiate through an undefined variable?

Suppose I have some $ \lambda$ that is a function of $ x$ , and I don’t know exactly what it is yet.

Then, doing the following differentiation D[lamb, x] gives zero. But what I really want is to not have Mathematica evaluate the expression, i.e., just leave it as it is until I know $ \lambda$ later.

Is there a way to achieve this? Thanks!

Update variable value via add_filter

I have this apply filter in my plugin.

$  pre_html = apply_filters( 'events_views_html', null, $  view_slug, $  query, $  context ); 

I want to change $ view_slug value dynamically because I do not want to modify plugin files. Can I do this using add_filter in my child theme ?

It is a basic question but I have limited knowledge of WordPress filters and hooks. Some guidelines regarding this will be appreciated.