Shaders: Prefer arithmetic conditionals to branching
This commit is contained in:
		
							parent
							
								
									373b90af00
								
							
						
					
					
						commit
						2f95c0613a
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -18,8 +18,9 @@ const float atAniOffset = 32.0*3.0;
 | 
			
		|||
void main()
 | 
			
		||||
{
 | 
			
		||||
	vec2 tex = texCoord;
 | 
			
		||||
	if (tex.x <= atAreaW && tex.y <= atAreaH)
 | 
			
		||||
		tex.x += aniIndex * atAniOffset;
 | 
			
		||||
 | 
			
		||||
	lowp float pred = float(tex.x <= atAreaW && tex.y <= atAreaH);
 | 
			
		||||
	tex.x += aniIndex * atAniOffset * pred;
 | 
			
		||||
 | 
			
		||||
	gl_Position = projMat * vec4(position + translation, 0, 1);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,14 +18,15 @@ const float atAreaCW = 4.0*32.0;
 | 
			
		|||
void main()
 | 
			
		||||
{
 | 
			
		||||
	vec2 tex = texCoord;
 | 
			
		||||
	lowp float pred;
 | 
			
		||||
 | 
			
		||||
	/* Type A autotiles shift horizontally */
 | 
			
		||||
	if (tex.x <= atAreaA.x && tex.y <= atAreaA.y)
 | 
			
		||||
		tex.x += aniOffset.x;
 | 
			
		||||
	pred = float(tex.x <= atAreaA.x && tex.y <= atAreaA.y);
 | 
			
		||||
	tex.x += aniOffset.x * pred;
 | 
			
		||||
 | 
			
		||||
	/* Type C autotiles shift vertically */
 | 
			
		||||
	if (tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y)
 | 
			
		||||
		tex.y += aniOffset.y;
 | 
			
		||||
	pred = float(tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y);
 | 
			
		||||
	tex.y += aniOffset.y * pred;
 | 
			
		||||
 | 
			
		||||
	gl_Position = projMat * vec4(position + translation, 0, 1);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue