So I am basically trying to do this http://answers.unity3d.com/questions/998203/mask-3d-objects-inside-ui-scrollrect.html....i have scrollrect with buttons and each button has a different 3d object on it to represent what the button do. But so far I have not been successful in masking out the 3d objects. I have messed around with render texture, but i have not found a good solution. I dont want to set up a stage where i film the 3d object in the right size and to project them on to the buttons with a render texture. Is there away to mask out the object with a shader? The objects i am using aare just using the standard shader, can i modify it to support stenciling ( dont have a full grasp on what stenciling is or does, I have just come across the term alot in my googling on the subject)
Hi.
You need to do a tiny big of scripting for this to work. Basically create a UI element that uses this mesh.
Something like this:
using UnityEngine;
using System.Collections.Generic;
[RequireComponent(typeof(CanvasRenderer))]
[ExecuteInEditMode]
public class SetMeshMaterials : MonoBehaviour
{
public Mesh TheMesh;
public List<Material> Materials;
void ResetData ()
{
var cr = GetComponent<CanvasRenderer>();
cr.SetMesh (TheMesh);
cr.materialCount = Materials.Count;
for (int i = 0; i < Materials.Count; i++)
cr.SetMaterial (Materials[i], i);
}
void OnEnable()
{
ResetData();
}
void OnValidate()
{
ResetData();
}
}
This will not work for screen space overlay canvas with the standard shader as no lighting happens. You need either a screen space overlay or world canvas.
Thx for the answer, but i cant get it to work. TheMesh and Materials are never asigned with the objects mesh or materials. Do i have to add som code that refers to the current object?
something like
Void Start(){
TheMesh = this.GetComponent<Meshfilter>().mesh;
}
But i could not get that to work either so i guess i am doing something wrong
So i created a empty game object, added yout script and then draged the mesh from assets folder and the materials from them on to i, but it still dont mask them. So i i am pretty lost here now
Ohhh yeah a shader modification is also needed… On phone right now will get back to you
I think I just had a lightbulb moment on what that actually means @Tim-C with the update to use meshes with the new UI.
Basically, any mesh would be hostable on a UI canvas, by either reading it’s mesh data, or manipulating with with techniques such as the above. Interesting…
Looking forward to your shader update.
Im so freaking excited now! I havet been messing around with the standard shader, trying to add stenceling to it…but shaders is not my strong suite
Any news on this issue?
Did this ever get worked out? I’ve tried using the scripts in this thread along with using a UI shader, but no luck. Masking is ignored for a cube, for example, placed in the content area of a scrollrect.
Yo @Tim-C any thoughts on the shader?
Just put a proposal in the UI Extensions project for this. Might whip up the basic control quickly myself using the above example, if you could provide your shader godness
Just realised as @Tim-C has moved off the project, he might not be the right person to ask.
@phil-Unity any chance you can fill in the gap here as it seems a very useful approach?
Unfortunately at this time i’m not 100% sure let me talk with Tim and figure something out as i dont know what he had in mind for this.
Thanks @phil-Unity Eagerly waiting a response on this as it would be very useful.
Quick poke for the new year @phil-Unity any further thoughts on advancing this?
Tried a few combinations to manipulate / display the mesh but it does seem some shader magic is required.
Need to get a hold of Tim which didnt happen yet i’ll poke him now but hes away till the 11th.
No worries, thanks for the update Phil
Happy new year team, any update on this request @phil-Unity ?
Hoping we can get through this quickly now in the new year as this would be an awesome boost to the UI system if we can get it working with the mesh data.
Did you manage to get hold of @Tim-C 's brain and dissect his ideas ?
Well it’s been a few months
Any update on the shader fix needed to make this possible? @phil-Unity / @Tim-C
Did see (and comment) in this post which seems to indicate their approach works in worldspace but not screenspace, so wondered if it was related?