So I don’t normally ask questions on here (usually there already is a question with an appropriate answer to my question somewhere out there), but I couldn’t find the answer to my specific question so far.
So I’ll just keep it short and simple. I’ve got a vertex and fragment shader, I displace my model with a noise texture in my vertex shader and add two textures in my fragment shader (a main Texture, and a Overlay Texture), all pretty basic stuff. Now I’m sure what I want is very easy and simple to achieve aswell, but I couldn’t find an answer so far. I want to now take this output (displacement and the textures), and add some basic lighting to it. To my knowledge this is done using a surface shader, and I got it all mostly setup already, but how do I now take the output of vertex and fragment shader, and plug that into my surface shader for further computation?
So tl;dr, how do I take the output of a vertex and fragment shader, and further compute this in a surface shader?
I’ll attach my shader I got so far below:
Shader "Unlit/PlayerShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_SideTex ("Texture", 2D) = "white" {}
_OverlayTex ("Texture", 2D) = "black" {}
_TintColor("Tint Color", Color) = (1,1,1,1)
_NoiseSpeed ("Noise Speed", Float) = 0.25
_NoiseStrength ("Noise Strength", Float) = 0.25
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
sampler2D _SideTex;
sampler2D _OverlayTex;
float4 _MainTex_ST;
float4 _TintColor;
float _NoiseSpeed;
float _NoiseStrength;
v2f vert (appdata v)
{
v2f o;
float4 colVal = tex2Dlod(_SideTex, float4(v.uv + (_Time.y*_NoiseSpeed),0,0));
v.vertex.xyz *= 1+(colVal.x*_NoiseStrength-(_NoiseStrength/2));
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv) * _TintColor;
fixed4 overlayCol = tex2D(_OverlayTex, i.uv);
if(overlayCol.w > 0.1){
col = tex2D(_OverlayTex, i.uv);
}
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
}
ENDCG
}
}