Custom Phong shader written via Nodes

use this if you want a custom phong shader with colored Specular and to be able to understand how the ‘Lighting’ part of a Visual shader works

Shader code
shader_type spatial;
render_mode cull_disabled, specular_phong;

uniform float Hardness;
uniform float SpecularPower;
uniform vec4 Diffuse_Color : hint_color;
uniform sampler2D Texture4;
uniform sampler2D Texture3;
uniform sampler2D Texture2;
uniform sampler2D Texture1;
uniform vec4 Specular_Color : hint_color;
uniform float SpecularPower2;



void vertex() {
// Output:0

}

void fragment() {
// ScalarUniform:7
	float n_out7p0 = Hardness;

// Scalar:6
	float n_out6p0 = 1.000000;

// ScalarUniform:5
	float n_out5p0 = SpecularPower;

// ScalarOp:4
	float n_out4p0 = n_out6p0 / n_out5p0;

// ScalarOp:3
	float n_out3p0 = n_out7p0 * n_out4p0;

// ScalarOp:18
	float n_out18p0 = n_out7p0 * n_out3p0;

// Output:0
	SPECULAR = n_out18p0;

}

void light() {
// Input:86
	vec3 n_out86p0 = ALBEDO;

// Input:127
	vec3 n_out127p0 = ATTENUATION;

// VectorOp:128
	vec3 n_out128p0 = n_out86p0 * n_out127p0;

// ColorUniform:107
	vec3 n_out107p0 = Diffuse_Color.rgb;
	float n_out107p1 = Diffuse_Color.a;

// VectorOp:106
	vec3 n_out106p0 = n_out107p0 * vec3(n_out107p1);

// TextureUniform:126
	vec3 n_out126p0;
	float n_out126p1;
	{
		vec4 n_tex_read = texture(Texture4, UV.xy);
		n_out126p0 = n_tex_read.rgb;
		n_out126p1 = n_tex_read.a;
	}

// TextureUniform:125
	vec3 n_out125p0;
	float n_out125p1;
	{
		vec4 n_tex_read = texture(Texture3, UV.xy);
		n_out125p0 = n_tex_read.rgb;
		n_out125p1 = n_tex_read.a;
	}

// VectorOp:115
	vec3 n_out115p0 = n_out126p0 * n_out125p0;

// TextureUniform:124
	vec3 n_out124p0;
	float n_out124p1;
	{
		vec4 n_tex_read = texture(Texture2, UV.xy);
		n_out124p0 = n_tex_read.rgb;
		n_out124p1 = n_tex_read.a;
	}

// VectorOp:110
	vec3 n_out110p0 = n_out115p0 * n_out124p0;

// TextureUniform:123
	vec3 n_out123p0;
	float n_out123p1;
	{
		vec4 n_tex_read = texture(Texture1, UV.xy);
		n_out123p0 = n_tex_read.rgb;
		n_out123p1 = n_tex_read.a;
	}

// VectorOp:114
	vec3 n_out114p0 = n_out110p0 * n_out123p0;

// VectorOp:109
	vec3 n_out109p0 = n_out106p0 * n_out114p0;

// VectorOp:91
	vec3 n_out91p0 = n_out128p0 * n_out109p0;

// VectorOp:90
	vec3 n_in90p1 = vec3(0.00000, 0.00000, 0.00000);
	vec3 n_out90p0 = n_out91p0 + n_in90p1;

// Input:74
	vec3 n_out74p0 = LIGHT;

// Input:71
	vec3 n_out71p0 = NORMAL;

// DotProduct:68
	float n_out68p0 = dot(n_out74p0, n_out71p0);

// ScalarOp:69
	float n_in69p1 = 0.00000;
	float n_out69p0 = max(n_out68p0, n_in69p1);

// Input:76
	vec3 n_out76p0 = LIGHT_COLOR;

// VectorOp:77
	vec3 n_out77p0 = vec3(n_out69p0) * n_out76p0;

// VectorOp:75
	vec3 n_out75p0 = n_out90p0 * n_out77p0;

// Input:95
	vec3 n_out95p0 = DIFFUSE_LIGHT;

// VectorOp:96
	vec3 n_out96p0 = n_out75p0 + n_out95p0;

// Input:88
	vec3 n_out88p0 = VIEW;

// VectorFunc:93
	vec3 n_out93p0 = -(n_out88p0);

// VectorOp:79
	vec3 n_out79p0 = reflect(n_out93p0, n_out71p0);

// DotProduct:82
	float n_out82p0 = dot(n_out74p0, n_out79p0);

// ScalarOp:83
	float n_in83p1 = 0.00000;
	float n_out83p0 = max(n_out82p0, n_in83p1);

// ScalarOp:78
	float n_in78p1 = 40.00000;
	float n_out78p0 = pow(n_out83p0, n_in78p1);

// VectorOp:84
	vec3 n_out84p0 = n_out76p0 * vec3(n_out78p0);

// Input:98
	vec3 n_out98p0 = SPECULAR_LIGHT;

// VectorOp:97
	vec3 n_out97p0 = n_out84p0 + n_out98p0;

// ColorUniform:108
	vec3 n_out108p0 = Specular_Color.rgb;
	float n_out108p1 = Specular_Color.a;

// VectorOp:101
	vec3 n_out101p0 = n_out108p0 * vec3(n_out108p1);

// ScalarUniform:104
	float n_out104p0 = SpecularPower2;

// Scalar:105
	float n_out105p0 = 1.000000;

// VectorOp:103
	vec3 n_out103p0 = vec3(n_out104p0) / vec3(n_out105p0);

// VectorOp:102
	vec3 n_out102p0 = n_out101p0 + n_out103p0;

// VectorOp:100
	vec3 n_out100p0 = n_out97p0 * n_out102p0;

// Output:0
	DIFFUSE_LIGHT = n_out96p0;
	SPECULAR_LIGHT = n_out100p0;

}
Tags
phong lambert blinn old 90s
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Procedural Marble Shader

3D simple animated flag shader

Procedural Window Rain Drop Shader

guest

0 Comments
Inline Feedbacks
View all comments