New answers tagged

1

I found the solution, which is as obnoxious as opengl can get. While some time ago precision specifiers were still accepted but useless on desktop, for compatibility with opengl-es that still supports and needs these specifiers. So they decided to make it impossible to include a precision specifier on desktop glsl which means I spent two hours looking for a ...


2

Changing shader properties for each camera You can accomplish this with a script on the camera. In my example I change the color but you can extend this idea to any property in the shader. [ExecuteInEditMode] public class CameraMaterialChanger : MonoBehaviour { public Color myColor; // color you want the camera to render it as public Material ...


1

(Not 5 minutes after posting this I found a solution. Might as well share it here if someone else is curious about this in the future.) It's possible to set the texture using Shader.SetGlobalTexture. For this to work properly I also had to remove the texture as a property of the shader. I have the following script attached to an object in the scene and it'...


2

If I'm reading this right, the answer seems to be right there in the continuation of that line: metallic - the metallic-ness (0 = dielectric, 1 = metallic). This is a linear blend between two different models. The metallic model has no diffuse component and also has a tinted incident specular, equal to the base color. (With the implication that ...


0

You're stuck in a bit of a predicament using an older engine like DarkBasic. The problem as you've already described yourself, is that you can't afford to make the skydome bigger. The reason the trees are popping, you already know, is that they are clipping through the geometry of the skydome. If you cannot make the skydome bigger, there's not much you can ...


4

I have little experience using Unity directly, but I've been a level designer for years and a much easier approach rather than worrying about cutting holes into your terrain is to simply build up a C shaped ridge in your terrain for the size of your cave and then cover it with rock meshes to give it the illusion of a cave. Another approach is that you ...


5

I don't think this is going to be quite as easy as you'd like, that said you should be able to copy/paste the code below to get something going. There might be a better way to approach this, but as I see it you'll need 2 render passes. The first to render the scene to a low resolution to introduce pixelation, and a second to resample the low resolution ...


1

BTW, I ended up solving this using a lightmap. My process was as follows: Generate a UV map for the mesh by packing all the triangles together using a simple scanline algorithm. Render the scene directly to the UV map instead of to the screen. This way, pixels are 1:1 related to texels. Render the scene again to the screen, this time using the generated UV ...


0

My guess was right. I just had to pass in the MVP matrix with respect to my target camera. So in unity: void LateUpdate () { _TargetRenderer.sharedMaterial.SetMatrix("_MVPTargetCam", _TargetCam.projectionMatrix *_TargetCam.worldToCameraMatrix * _TargetRenderer.localToWorldMatrix); }


1

First you need to get your shader's output into a Texture2D, so create one of the appropriate size. You'll commonly want ARGB32 format and no mipmaps: Texture2D outputTex = new Texture2D(width, height, TextureFormat.ARGB32, false) If the content you want to save has already been rendered by a camera in the scene, you can skip ahead (although in this case ...


-1

Your shader is more than likely bound to a Material. Grab the texture from that Material: https://docs.unity3d.com/ScriptReference/Material.GetTexture.html So something like this: Texture2D texture = renderer.material.mainTexture; Then you can dump this to file easily: byte[] bytes = texture.EncodeToPNG(); System.IO.File.WriteAllBytes("filename.png",...


0

As far as I know, you need to use 5.4 Beta in order to do this at the moment. Take a look at: http://docs.unity3d.com/540/Documentation/ScriptReference/Material.SetFloatArray.html Or the other SetArray methods of the Material class, starting from 5.4. http://docs.unity3d.com/540/Documentation/ScriptReference/Material.html


0

If you already have a reference to the material and the shader then you just need to do this: myMaterial.shader = myShader; There's nothing more to it than that. The Unity Material API says that the shader property is public so you can just use = instead of finding some "set" method. There is an explicit "set" and "get" function for textures on materials ...


2

The lowest-effort way to get what you describe: far away objects are completely grey and close objects are in full color ...is to use fog, either directly through the Lighting settings for your scene (see the Fog entries at this link, no custom shaders required) or by using the legacy shader paths. Here's an example of what it looks like with ...


3

The effect you're going for is less of a pure hue shift and looks more like old-school palette shifting effect. On old hardware this was implemented by arranging the color palette used for the image such that there was a run of similar colors (for example, a series of blues increasing in saturation, in the case of your first image) and then shifting and ...


2

It looks like you're trying to draw a 40x40 pixel aqua colored square at (0.0, 0.0, 0.5), is that right? OpenGL producing no output is probably the most common symptom you'll run into. I immediately see several things that look a little off: Your shaders are requiring OpenGL 4.5. Are you sure your current OS/drivers/etc. implement OpenGL 4.5? You set the ...


1

I am also looking for some code to make this conversion but..Only God knows why the code above is using that array indexes lol... Maybe he meant something like this? (in case other people wants to use the code too) PVector [] tUV = new PVector[3]; // 2d uv coordinates of the triangle vertices PVector [] t3D = new PVector[3]; // 3d space ...



Top 50 recent answers are included