Jump to content
  • Advertisement

Unity Daily Update #6 - Dynamically colored decals

jb-dev

1023 views

Today was kind of a slow day too. I've haven't got a lot of sleep lately (thanks little hamster wheel in my head)

But at last, I was still able to add (and also fix) some graphical components here and there.

In short, I've made the first and last rooms of the level more distinct from every other room.

For example, I've added a room flow on these rooms to properly align props and, in the case of the starting room. the spawning rotation.

I've also added a little decal-like plane that tells the player what to do (take it as a little tutorial, if you may)

298144197_startingtutorial.thumb.png.bded69770f8abc8819b0f3d617a1033d.png

The important thing is that this decal is, not unlike my palette shader, dynamic in terms of colours.

What I've done is quite simple: I've mapped each channel of a texture to a specific colour.

Here's the original texture:

tuto.thumb.png.b4f842c1fc600f2673cb98bc7235700c.png

After inputting this texture in my shader, it was just a matter of interpolating values and saturating them:

Shader "Custom/TriColorMaps" {
	Properties {
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_Metallic ("Metallic", Range(0,1)) = 0.0
		_RedMappedColor ("Mapped color (Red channel)", Color) = (1, 0, 0, 1) 
		_GreenMappedColor ("Mapped color (Green channel)", Color) = (0, 1, 0, 1) 
		_BlueMappedColor ("Mapped color (Blue channel)", Color) = (0, 0, 1, 1) 
	}
	SubShader {
		Tags {  "RenderType"="Transparent" }
		LOD 200

		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Standard fullforwardshadows vertex:vert decal:blend 

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _RedMappedColor;
		fixed4 _GreenMappedColor;
		fixed4 _BlueMappedColor;

		void vert (inout appdata_full v) {
			v.vertex.y += v.normal.y * 0.0125;
		}

		// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
		// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
		// #pragma instancing_options assumeuniformscaling
		UNITY_INSTANCING_BUFFER_START(Props)
			// put more per-instance properties here
		UNITY_INSTANCING_BUFFER_END(Props)

		void surf (Input IN, inout SurfaceOutputStandard o) {
			// Albedo comes from a texture tinted by color
			fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
			c.rgb = saturate((lerp(fixed4(0, 0, 0, 0), _RedMappedColor, c.r) + lerp(fixed4(0, 0, 0, 0), _GreenMappedColor, c.g) + lerp(fixed4(0, 0, 0, 0), _BlueMappedColor, c.b))).rgb;

			o.Albedo = c.rgb;
			// Metallic and smoothness come from slider variables
			o.Metallic = _Metallic;
			o.Smoothness = _Glossiness;
			o.Alpha = c.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}

Also, note that I've changed the vertices of the model. I needed a way to eliminate the Z-Fighting and just thought of offsetting the vertices by their normals.

In conclusion, It's nothing really special, really. But I'm still working hard on this.


EDIT:

After a little bit of searching, I've seen that you can give a Z-buffer offset in those Unity shaders by using the Offset state. 

So I've then tried to change a bit my previous shader to use that functionality rather than just offsetting the vertices:

SubShader {
	Tags { "RenderType"="Opaque" "Queue"="Geometry+1" "ForceNoShadowCasting"="True" }
	LOD 200

	Offset -1, -1
	CGPROGRAM
	// Physically based Standard lighting model, and enable shadows on all light types
	#pragma surface surf Lambert decal:blend 

	// Use shader model 3.0 target, to get nicer looking lighting
	#pragma target 3.0

	sampler2D _MainTex;

	struct Input {
		float2 uv_MainTex;
	};

	fixed4 _RedMappedColor;
	fixed4 _GreenMappedColor;
	fixed4 _BlueMappedColor;


	// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
	// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
	// #pragma instancing_options assumeuniformscaling
	UNITY_INSTANCING_BUFFER_START(Props)
		// put more per-instance properties here
	UNITY_INSTANCING_BUFFER_END(Props)

	void surf (Input IN, inout SurfaceOutput  o) {
		// Albedo comes from a texture tinted by color
		fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
		c.rgb = saturate((lerp(fixed4(0, 0, 0, 0), _RedMappedColor, c.r) + lerp(fixed4(0, 0, 0, 0), _GreenMappedColor, c.g) + lerp(fixed4(0, 0, 0, 0), _BlueMappedColor, c.b))).rgb;

		o.Albedo = c.rgb;
		// We keep the alpha: it's supposed to be a decal
		o.Alpha = c.a;
	}
	ENDCG
}
 



0 Comments


Recommended Comments

After thinking about it, I've could have gone with deferred decals, but I thought i didn't need that right now: most of my geometries are flat at the moment...

Share this comment


Link to comment

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
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By NeoRetro
      Hi -
      I'm a game designer, artist, and game content creator who's been working in the industry on/off for many years.  My work has been primarily on PC and mobile puzzle and action games (Here's an oooold article:  https://www.gamasutra.com/view/feature/130053/breaking_down_breakout_system_and_.php)
       
      I've decided to develop one of my prototypes into a game.  Closest description would be a mashup of Mario Brothers, Mount Your Friends and Cut the Rope.  Single or local multiplayer.  Unity 2D.   
       
      When I began this project in my spare time a few years ago, it was a series of paper and visual prototypes and there were many unknowns.  Since then I've been lucky enough to have pitched the design to a university game incubator in 2017 and have it accepted and developed as a capstone project through Fall/Spring semesters (won best-project award).  This has reduced the unknowns dramatically.  I've also refined and evolved the theme and art style.  Thus my decision to proceed with developing the prototype into a game. 
       
      I've done level scripting in Lua and Objective C, but I don't really have the coding chops to proceed on my own.  Thus I'm looking for an experienced developer with numerous games and prototypes under their belt (bonus points for "2D physics-thing" prototypes and games).  Ideally several years of Unity C# work.  Ideally based in the U.S. since I'm on the east coast. 
       
      This would be a variable amount of revenue share based on contribution (anything from: 4-16 hours per week for a ~12 month duration).  If you're local, there's the possibility of other types of compensation as well (free meals, computer test equipment, etc).  I estimate project completion Sep-Dec 2019. 
       
      I'll provide A TON of specifics for serious inquiries in the form of a brief screenshare walkthrough and short design pitchbook.
      Start would be in early September.
       
      ***Please message me on gamedev.net***
      ***Please include the usual details required to determine qualifications/experience***
      ***Please be over 18***
       
      THANKS FOR READING!
    • By MoreLion
      3D Artists And Unity Programmers For Doom Like Shooter
      Game:ROGUE
      Studio:Rebound Entertainment
      Current Team:3
      Payment:Rev-Share Or Kickstarter
      Programming Requirements:
      - Must Know And Have Experience With Unity And Know C#
      - Must Be Able To Spend 5 To 12 hours a week on the project
      - Must Be Older Than 15
      3D Artist Requirements:
      - Be Able To Model, Animate, Create 3D Monsters And Characters Or Rig (Must Have at least one of these)
      - Must Be Able To Spend 5 To 12 hours a week on the project
      - Must Be Older Than 15
      Project Description:
      You are on the ESL (The Elementary Space Lab). You wake not knowing what has happened, you soon learn that a experimental AI Has gone rogue and created beasts and monsters to kill anything in its path. Now, you know what your mission is.
      If You Are Interested DM Me on discord at thathuman44#4207 or email me at oneriot3@gmail.com
    • By Brandon Sharp
      This is a project I've been working on for awhile now. I'd save over all going on around a year. I did the Machbot 2.0 all from scratch including the textures. I spent countless hours trying to figure out how to get the models from Twisted Metal. I finally figured out how to manually extract the mesh. But the only problem was it was not UV mapped. So i pretty much had to go back in and remap everything. Which wasn't hard but the assembling of the model itself was a challenge. I did the best I could at placing stuff where it goes I'm sure there are things that are incorrect. All in all it was for this one render. Not sure if my models can be used as game assets but i do want to eventually make this into a fighting game. Both vehicles and bots. Let me know what you think and thank your for checking out my work. 
       

    • By ChenMo
      Hi, guys.
      I am developing a path tracing baking renderer now, which is based on OpenGL and OpenRL. It can bake some scenes e.g. the following, I am glad it can bake bleeding diffuse color. : )

      I store the irradiance directly, like this. Albedo * diffuse color has already come into irradiance calculation when baking, both direct and indirect together.

      After baking, In OpenGL fragment shader, I use the light map directly.

      I think I have got something wrong, due to most game engines don't do like this.
      Which kind of data should I choose to store into the light maps? I need diffuse only.
      Thanks in advance!
    • By jb-dev
      This is a picture of a yet to be completed bank. The idea is to generate simple geometries to fill the space between the floor and the ceiling. It's done like that because I can set the wall height of the generated level on the fly, so I need something generic and flexible.
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!