- Home /
Simple Blinn Phong Surface Shader
Hi All, I'm trying to write a very simple surface shader using BlinnPhong that doesn't use any textures. It's supposed to represent gloss paint. I'm new to surface shaders and can't find any reference texts or examples that use the BlinnPhong surf keyword apart from those that also use a normal map..
Here's what I have so far:
Shader "Custom/BP" {
Properties {
_Color ("Color", color) = (1,1,1,1)
_SpecColor ("Spec color", color) = (0.5,0.5,0.5,0.5)
_Glossiness("Shininess", Range(0, 255)) = 10
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf BlinnPhong
#pragma target 3.0
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct Input {
float3 normal : NORMAL;
};
float _Glossiness;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = _Color.rgb;
o.Specular = _Glossiness;
o.Gloss = 1;
o.Normal = IN.normal;
}
ENDCG
}
FallBack "Diffuse"
}
The results are not as I expected. I'm not sure what the values in the output represent or if I need to do any calculations to generate the output.
Any help appreciated. If anyone has a link to a tutorial that covers this I'd be extremely grateful.
Answer by Namey5 · Jul 17, 2020 at 12:19 AM
Don't assign anything to o.Normal. This output is specifically for normal maps, and if you assign into it the normals will be taken in tangent space rather than world space, which would mess with the lighting here.
Your answer
Follow this Question
Related Questions
Change custom shader color where vertex is displaced 0 Answers
Surface Shader vertex displacement, shadows not moving 1 Answer
How to convert surface shader to Vertex/Fragment code? 0 Answers
Shading is visible through object using surface shader 0 Answers
Referencing the current pixel's world coordinates in the SURF block of a shader 1 Answer