I am trying to save a scalar signal value for future use as a texture with the Spark AR software.
Basically, using the camera texture on a material is scripted like this:
const texture = Textures.get('CameraTexture').signal;
const material = Materials.get('defaultMaterial0');
material.setTexture(texture, {textureSlotName: "diffuseTexture"})
It is not clear to me what class is the texture const, but I am guessing this is a ScalarSignal.
That means that it is a stream, not a value. How would I go about snapshotting that value? lastValue does not work, and when trying valueOf(), I get
JavaScript error: Exception in native code while calling a function: valueOf() called on a Signal. This probably means that you are trying to perform an arithmetic operation on a signal like +, -, *, etc. Use functions .add, .sub(), etc on the signal instead or .subscribeWithSnapshot() on an EventSource to get the signal's current value on a callback.
And subscribeWithSnapshot() is not a function..
If anyone has any idea how I could do this, or the specific reason why I can't, help would be appreciated!
Thanks!
You can't. Currently in SparkAr is not allowed to save a texture. And I think the data type should be a texture buffer (eventually...)
EDIT: Also, the camera texture signal it's not a scalarSignal but a ShaderSignal.
you can check this:
Diagnostics.log(Textures.get('CameraTexture').signal);
Related
I'm trying to create a shader that tiles a texture on an object, But I am Running into an issue. When trying to tile with this Shader Graph, It looks good from the front but looks wrong from the side. this is a 3x3x1 object and all of the squares should be the same size. Thanks in advance
I think it's because you're trying to input a Vector3 into a UV input node, which only takes a Vector2, so it's not using the Z component, which is the dimension that isn't working for you.
I haven't looked too deeply into it, but maybe this script will let you accomplish tiling in all three dimensions? https://github.com/Dsphar/Cube_Texture_Auto_Repeat_Unity/blob/master/ReCalcCubeTexture.cs
I have material with Shader in unity.
How to get a value in code?
For example, i need change value EdgeWidth in code, how can i do it?
According to the Unity documentation, you need to find your material or your shader, in your script, and you have a lot of functions to change the value of a material, like .SetFloat().
Renderer rend = GetComponent<Renderer> ();
rend.material.SetFloat("EdgeWidth", -1.18f);
There are some ideas I would like to do in shader that require me to make a weird texture topology, texture atlas packing for example. They could not be wrapped with common wrap mode, there would be glitch or bleeding on the edge of UV seam
And so I think, what if I just use tex2D() or tex2Dlod() for texture lookup with point filtering, and then rewrite all sampling and blending logic in the shader itself, look up for many points with custom wrapper and blend them with shader code
Is it possible and what could be a problem or disadvantage about this method?
Yes, this is possible and common. You will need to set the filter and/or wrap mode of the texture asset itself, in the project. (if using shader graph, you have the option to specify a custom sample state inside the shader itself). You can certainly modify the UV coordinates passed to your shader, and use those modified values to sample the texture(s).
Each frame unity generate an image. I want that it will also create an additional arrays of int's and every time it decide to write a new color on the generated image it will write the id of the object on the correspond place in the array of int's.
In OpenGL I know that it’s pretty common and I found a lot of tutorials for this kind of things, basically based on the depth map you decide which id should be written at each pixel of the helper array. but in unity i using a given Shader and i didn't find a proper way to do just that. i think there should be any build in functions for this kind of common problem.
my goal is to know for every pixel on the screen which object it belongs to.
Thanks.
In forward rendering if you don't use it for another purpose you could store the ID into the alpha channel of the back buffer (and it would only be valid for opaque objects), up to 256 IDs without HDR. In deferred you could edit the unused channel of the gbuffer potentially.
This is if you want to minimize overhead, otherwise you could have a more generic system that re-renders specific objects into a texture in screenspace, whith a very simple shader that just outputs ID, into whatever format you need, using command buffers.
You'll want to make a custom shader that renders the default textures and colors to the mainCamera and renders an ID color to a renderTexture trough another camera.
Here's an example of how it works Implementing Watering in my Farming Game!
I am trying to access a depth texture, that I have created with FBO but I don't know how. I have tried to use texture2D, but I am not sure in which component the values are stored or if these values are split up and stored in more than one component.
The Definition of the texture:
glTexImage(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,480,360,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_SHORT,0);
Needless to say, that i am new to iPhone and OpenGL ES programming.
Thanks in advance
Lars
ok, i was hasty. The value can be accessed from each component (except the fourth one of course).