Rimlight | Customizable rimlight shader for Unity | Game Engine library
kandi X-RAY | Rimlight Summary
kandi X-RAY | Rimlight Summary
Rim lighting is a light that usually comes from beside or behind a subject, and enhances its silhouette. This shader fakes this by making use of the Fresnel effect. This can be used to stylize or highlight objects, and it greatly favors certain artstyles. It is especially pleasing when applied to smooth curvy models.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Rimlight
Rimlight Key Features
Rimlight Examples and Code Snippets
Community Discussions
Trending Discussions on Rimlight
QUESTION
I'm having problems compiling the example code provided with the OpenGL Superbible, 6th ed. I'm using Ubuntu 19.04 and CMake 3.13.4. I have all the necessary dependencies. CMake executes with no problems ("cmake ."), but when I enter the make command it fails.
I'm under the impression it has to do with GLFW but I don't know how to change CMake for it to work.
Here's a link to the example code. https://github.com/openglsuperbible/sb6code
I've already fixed the issue in line 13 of the CMakeLists.txt file but its still not compiling.
From:
...ANSWER
Answered 2019-Apr-23 at 08:05I have changed the code and the cmake file to work with GLFW3. Now the project compiles and runs. I uploaded it to github here: https://github.com/mlioz/sb6code_fixed
QUESTION
Shader "Custom/Selected Object" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Emission ("EmissionColor", Color) = (0.5, 0.5, 0.5, 1)
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_Mode ("Blend Mode", Range(0,3)) = 0
_ZWrite ("ZWrite", Int) = 0
_SrcBlend ("SrcBlend", Int) = 0
_DstBlend ("DstBlend", Int) = 0
_Cutoff ("Alpha Cutoff", Float) = 0.05
}
SubShader{
//Behind other geometry
Pass
{
ZTest GEqual
ZWrite [_ZWrite]
Blend [_SrcBlend] [_DstBlend]
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float2 uv : TEXCOORD0;
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : SV_POSITION;
float3 viewDir : TEXCOORD1;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
o.viewDir = normalize(UnityWorldSpaceViewDir(o.pos));
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag(v2f i) : SV_Target
{
//Note you have to normalize these again since they are being interpolated between vertices
float rim = 1 - dot(normalize(i.normal), normalize(i.viewDir));
fixed4 rimLight = lerp(half4(.95, .95, .95, 1), half4(0.65, 0.65, .95, 1), rim);
fixed4 t = tex2D(_MainTex, i.uv);
clip(t.a < 0.2);
return t * rimLight;
}
ENDCG
}
ZTest Less
ZWrite On
Blend [_SrcBlend][_DstBlend]
//Front geometry
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
// And generate the shadow pass with instancing support
#pragma surface surf Standard fullforwardshadows addshadow alphatest:_Cutoff //alpha:blend //keepalpha
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
#pragma multi_compile __ EMISSIVE_ON
sampler2D _MainTex;
fixed4 _Emission;
fixed4 _Color;
//float _Mode;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
void surf(Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
#if EMISSIVE_ON //Glowing
o.Emission = _Emission;
#endif
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Instanced/InstancedSurfaceShader"
}
...ANSWER
Answered 2018-Jun-11 at 12:29Before answering the actual issue here I need to point out this:
If you have more than two passes for multi-pass Shaders, only the first passes can be instanced. This is because Unity forces the later passes to be rendered together for each object, forcing Material changes.
https://docs.unity3d.com/Manual/GPUInstancing.html
So in essence, with your current implementation using Passes, you won't be able to use GPU instancing anyway.
now, the problem with your shader is that all your passes are opaque, so there is no guarantee in the draw order of the meshes. If the occluders are rendered after the occludee, there won't be any information in the Zbuffer to test against. The solution is simply to increase the render order of the material, for it the be drawn right after all other opaque (ZWrite On) pixels.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Rimlight
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page