About Monkey 2 › Forums › General Programming Discussion › Would this help make a unlit shader?
This topic contains 7 replies, has 4 voices, and was last updated by
Ethernaut
1 year, 3 months ago.
-
AuthorPosts
-
December 7, 2017 at 7:34 pm #12196Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273Shader "Unlit/SpecialFX/Cool Hologram"{Properties{_MainTex ("Albedo Texture", 2D) = "white" {}_TintColor("Tint Color", Color) = (1,1,1,1)_Transparency("Transparency", Range(0.0,0.5)) = 0.25_CutoutThresh("Cutout Threshold", Range(0.0,1.0)) = 0.2_Distance("Distance", Float) = 1_Amplitude("Amplitude", Float) = 1_Speed ("Speed", Float) = 1_Amount("Amount", Range(0.0,1.0)) = 1}SubShader{Tags {"Queue"="Transparent" "RenderType"="Transparent" }LOD 100ZWrite OffBlend SrcAlpha OneMinusSrcAlphaPass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};sampler2D _MainTex;float4 _MainTex_ST;float4 _TintColor;float _Transparency;float _CutoutThresh;float _Distance;float _Amplitude;float _Speed;float _Amount;v2f vert (appdata v){v2f o;v.vertex.x += sin(_Time.y * _Speed + v.vertex.y * _Amplitude) * _Distance * _Amount;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = TRANSFORM_TEX(v.uv, _MainTex);return o;}fixed4 frag (v2f i) : SV_Target{// sample the texturefixed4 col = tex2D(_MainTex, i.uv) + _TintColor;col.a = _Transparency;clip(col.r - _CutoutThresh);return col;}ENDCG}}}
I want to make it for a game I’m working on.
I borrowed this from the Unity website
December 7, 2017 at 9:36 pm #12197Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879Shader "Somian/Unlit/Transparent" {Properties {_Color ("Main Color (A=Opacity)", Color) = (1,1,1,1)_MainTex ("Base (A=Opacity)", 2D) = ""}Category {Tags {"Queue"="Transparent" "IgnoreProjector"="True"}ZWrite OffBlend SrcAlpha OneMinusSrcAlphaSubShader {Pass {GLSLPROGRAMvarying mediump vec2 uv;#ifdef VERTEXuniform mediump vec4 _MainTex_ST;void main() {gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;}#endif#ifdef FRAGMENTuniform lowp sampler2D _MainTex;uniform lowp vec4 _Color;void main() {gl_FragColor = texture2D(_MainTex, uv) * _Color;}#endifENDGLSL}}SubShader {Pass {SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]}}}}}probably nearer to the shader, also borrowed from the Unity forum
December 11, 2017 at 10:46 pm #12239This shader is from some old code where I was learning about GLSL with OpenTK, it renders flat textures.
Monkey12345678910111213141516171819202122232425262728293031var vertexSource = @"#version 330uniform mat4 MVPMatrix;layout (location = 0) in vec3 Position;layout (location = 1) in vec2 Texture;out vec2 InTexture;void main(){gl_Position = MVPMatrix * vec4(Position, 1);InTexture = Texture;}";var fragmentSource = @"#version 330uniform sampler2D Sampler;in vec2 InTexture;out vec4 OutFragColor;void main(){//OutFragColor = vec4(InTexture.x, InTexture.y, 0, 1);//vec4(1);OutFragColor = texture(Sampler, InTexture);}";December 13, 2017 at 7:27 pm #12265Thanks cocon im just looking at unlit textures but to be honest Shaders arent my thing, im used to EntityFX and TextureFX but now it all seems to be shaders for everything :/
December 13, 2017 at 7:59 pm #12266What exactly are you trying to achieve?
If you don’t want lighting on a surface can you just zero diffuse and specular?
December 13, 2017 at 9:06 pm #12268I’m not upto speed on diffuse and specular would this basically be just putting black textures in the PBR directory for the specular and diffuse files?
January 5, 2018 at 4:40 am #12662The name “unlit” is a little misleading!
It actually means that the texture is displayed at 100% of its original values, without any lighting applied (hence “unlit”), not that it’s 100% dark.
Those shaders tend to be super fast, are are super useful for stylized looks where all your shading/detail is built into the texture, like a “cartoon shader” minus the lighting.
Rendering a pure texture through the shader in Mojo is super easy for a 2D surface, but I still couldn’t get any custom shader to actually work with the 3D renderer… the Unity shader doesn’t really help in this case, but thanks!
Cheers!
January 5, 2018 at 4:48 am #12663You can get an unlit look with the PbrShader by:
– Turning off the EnvTexture (i.e. “_scene.EnvColor = Color.Black”, this will create a black texture for the environment )
– Setting the ambient light to Color.White (“_scene.AmbientLight = Color.White”)
– Making sure the material has 0 Metalness and 1.0 roughness, if you want no specular hilights.
– Don’t add any lights.
This will look like an unlit shader, but it won’t render as fast as one!
-
AuthorPosts
You must be logged in to reply to this topic.