• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Ty Typhoon
      So me and my co try to do a game.
      It should be in unity couse my co do everything in this engine.
       
      We got the rpg package from evila for inventor, but it only runs on pc right now.
       
      I like to make a online store for guns in the game and a multiplayer open world that runs on pc, android, mobile, ps4, xbox one. 
      Somebody told me that you "only" need to program it like so and that its possible in every engine...
       
      So if you are one of the lucky guys who could help me out or programm that, or even if you know a newer better package for maybe unreal which offers that - please let me know now.
       
      And yes, this is no recruitment post.
      But if youre interested to join my team as a programmer you are very welcome.
       
      Also discord:
      Joerg Federmann Composing#2898
    • By Ty Typhoon
      ...if you got time to read and answer i would be happy . 
       
      So me and my co try to do a game.
      It should be in unity couse my co do everything in this engine.
       
      We got the rpg package from evila for inventor, but it only runs on pc right now.
       
      I like to make a online store for guns in the game and a multiplayer open world that runs on pc, android, mobile, ps4, xbox one. 
      Somebody told me that you "only" need to program it like so and that its possible in every engine...
       
      So if you are one of the lucky guys who could help me out or programm that, or even if you know a newer better package for maybe unreal which offers that - please let me know now.
    • By ethancodes
      I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console. 
      This is my current code for this part of the program, it is attached to the bricks:
      void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags. 
       
      Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
  • Advertisement
  • Advertisement
Sign in to follow this  

Any Unity screen effects really slow on mobile.

Recommended Posts

So I am trying to learn how to do screen effects in Unity. The problem is that ANY effect is slow on mobile. At first I thought it was the complexity of my shader, so I tried it with a much simpler shader:

Spoiler

 


Shader "Hidden/NewImageEffectShader"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_Amount ("Effect Amount", Range (0, 1)) = 0
	}
	SubShader
	{
		// No culling or depth
		Cull Off ZWrite Off ZTest Always

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				return o;
			}
			
			sampler2D _MainTex;
			uniform float _Amount;

			fixed4 frag (v2f i) : SV_Target
			{
				fixed4 col = tex2D(_MainTex, i.uv);
				//Make it white
				col = col + _Amount;
				return col;
			}
			ENDCG
		}
	}
}

 

 

 

It's a very basic adaption of the shader Unity provides as default. All it does is add 1 to the color

The script to run the shader looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TurnThingsWhite : MonoBehaviour {
	
	public float _Amount;
	public Material material;

	float Timer = 2f;

	void Update(){
		if (Timer > 0.1f) {
			Timer -= 1f * Time.deltaTime;
		} else {
			Timer = 2f;
			_Amount = ((_Amount * -1f) + 1f);//toggle binary
		}
	}

	// Postprocess the image
	void OnRenderImage (RenderTexture source, RenderTexture destination){
		material.SetFloat("_Amount", _Amount);
		Graphics.Blit (source, destination, material);
	}
}

On Desktop this has almost no impact on performance, on mobile this is dropping even new mobiles down to 30fps-40fps. With nothing else in the scene except a 3D text object to see the fps.

Is this a problem with my script? Is there some other way mobile screen shaders should be made?

Edited by Scouting Ninja

Share this post


Link to post
Share on other sites
Advertisement

What mobile device are you testing on? I've made live games on mobile with post processing just fine. I didn't use OnRenderImage though, I manually did Graphics.SetRenderTarget, but you should be fine if targeting anything somewhat recent, (I was doing an approximation of shadow mapping on Samsung Galaxy S4). Maybe it's something to do with OnRenderImage?

Share this post


Link to post
Share on other sites
5 minutes ago, Seabolt said:

OnRenderImage though, I manually did Graphics.SetRenderTarget,

This looks like my problem. It's running above 60fps now. Strange that this one thing had such a huge difference between desktop and mobile. Even works with my shader on old mobiles.

Share this post


Link to post
Share on other sites

Maybe it was allocating a render texture for you under the hood each frame or something silly like that. I'm glad it helped!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement