Hi All I currently use Blender to create fan art for EVE Online and I am looking into the realm of doing fan videos. Now I know I could do this all in Blender but I want to use Unity as its much easier and faster to script ships, weapons, turrets and visual effects to make battle videos. Now I have gotten most of it down apart from shaders for textures, which I just cant get the hang of and have no idea on how to program them, what I am looking for is any help with creating a shader that allows me to take an image with lets say, Black, White, Light Grey and Dark Grey and apply a colour individually to one of these, this would save me having to create images for every object via gimp. Is this possible? Cheers DJ
This isn't the most optimized shader but it should get you started. Here is an image I made with photoshop. Here are the results when the shader is applied with the following material settings The colors are hardcoded in the shader. You can tune them to whatever you want. Then specify what those colors should be mapped to in the material settings. The following is the shader code. Code (CSharp): Shader "Unlit/ColorMapper" { Properties { _MainTex ("Texture", 2D) = "white" {} _WhiteColor ("White Color", COLOR) = (1.0, 1.0, 1.0, 1.0) _BlackColor ("Black Color", COLOR) = (0.0, 0.0, 0.0, 1.0) _LightGreyColor ("Light Grey Color", COLOR) = (0.5, 0.5, 0.5, 1.0) _DarkGreyColor ("Dark Grey Color", COLOR) = (0.3, 0.3, 0.3, 1.0) } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; }; sampler2D _MainTex; float4 _MainTex_ST; float4 _WhiteColor; float4 _LightGreyColor; float4 _DarkGreyColor; float4 _BlackColor; v2f vert (appdata v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } float3 frag (v2f i) : SV_Target { // sample the texture float3 col = tex2D(_MainTex, i.uv); float cl = length(col); float wl = length(float3(1.0, 1.0, 1.0)); float lgl = length(float3(0.5, 0.5, 0.5)); float dgl = length(float3(0.3, 0.3, 0.3)); float bl = length(float3( 0.0, 0.0, 0.0 )); if( cl >= wl ) { return _WhiteColor.rgb; } if( cl >= lgl ) { return _LightGreyColor.rgb; } if( cl >= dgl ) { return _DarkGreyColor.rgb; } return _BlackColor.rgb; } ENDCG } } }
Hi, thanks for your shader example, it works as prescribed, unfortunately it doesn't do what I need, having pulled one of the images from a DDS file I checked out the colours and although it looks like 4 solid colours it isn't, they all have varying ranges within there colours although not easy to see, so instead of 4 colours there are many. Cheers DJ
Hi All On a side note what I am trying to achieve is to create a shader that is similar to the Blend File created by this user for Blender. https://forums.eveonline.com/default.aspx?g=posts&t=435376 If there are any Blender / Unity 3D shader gurus, maybe you could have a look, it may be impossible or there may already be a shader in Unity for purchase that does the same that I am not aware off. Cheers DJ
Hi All I have spent sometime with my limited knowledge on the Blender Cycles shader and pulled the material apart. The material does the following. Takes in 3 dds files, now the issue with these files is to save texture space each dds file contains up to 4 separate textures stored in the R,G,B and Alpha channel. So dds 1 texture might contain the Albedo stored on R,G,B and roughness on the Alpha channel. dds 2 texture contains the Normal map on the Green and Alpha channel and the occlusion on the Blue dds 3 texture contains Paint on the Red, Material on the Green, Dirt on the Blue and Glow on the Alpha. Now the thing with all the images are none of them are colour, all images are greyscale images. The Albedo, Material, Dirt and Paint images can be individually coloured then these are layered to produce what we would class as a final diffuse image for the model. Now I think the way it works is the Albedo is the base layer, then material, Paint then dirt, each one of them can be coloured based on a range of greyscale, but there is also Alphas for transparency for the layering and opacity levels for each image. So from my basic description above is it possible to create a shader that can do all of the above obviously still containg the basics like Glow, Spec, Normal, Roughness ect. Cheers DJ