Skip to content

Commit

Permalink
MatCap Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Jun 17, 2019
1 parent 0a64681 commit 8fb0a35
Show file tree
Hide file tree
Showing 119 changed files with 1,610 additions and 336 deletions.
Binary file added Resources/matcap/00ShinyWhite.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/01_fuzzy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/02_red_velvet.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/03_blue_velvet.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/04_taupe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/06_clay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/07_blue.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/12_red.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/15_titanium.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/16_dull_gold.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/17_glossy_red.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/18_wet_blue.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/19_shiny_silver.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/20_shiny_gold.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/Burgundy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/Cortex.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/Fubax.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/LightBulb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/MetalDull.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/MetalRough.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/MetalShiny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/RedPlastic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/carpaint.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/extras/clay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/matcap/extras/green.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Resources/matcap/extras/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from https://stephaneginier.com/archive/testperf/resources/matcaps/
Binary file added Resources/matcap/extras/matcapFV.jpg
Binary file added Resources/matcap/extras/pearl.jpg
Binary file added Resources/matcap/extras/redClay.jpg
Binary file added Resources/matcap/extras/skin.jpg
Binary file added Resources/matcap/extras/skinHazardousarts.jpg
Binary file added Resources/matcap/extras/skinHazardousarts2.jpg
Binary file added Resources/matcap/extras/white.jpg
16 changes: 16 additions & 0 deletions Resources/matcap/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with regards to mc01.jpg...mc24.jpg
https://github.com/martijnberger/blender/tree/master/release/datafiles/matcaps
These matcap images are licensed as GNU GPL 2 or later, like the rest of Blender's code.
Thanks to Kent Trammell, Aidy Burrows, John Herreno , Terry Wallwork and David Silverman for making the pictures.

carpaint from
https://blog.mikepan.com/post/137759885931/realistic-car-paint-brdf-material

with regards to fubax.jpg
https://github.com/Fubaxiusz/fubax-shaders/blob/master/Textures/matcap.png

cortex and red plastic matcaps from
http://www.alecjacobson.com/weblog/?p=4827

remaining matcaps from
https://devtalk.blender.org/t/call-for-content-matcaps/737/203
1 change: 1 addition & 0 deletions Resources/matcap/orange/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://polycount.com/discussion/64453/tf2-and-toon-realtime-viewport-shader-3ds-max
Binary file added Resources/matcap/orange/orange.jpg
Binary file added Resources/matcap/unused/05_gray.jpg
Binary file added Resources/matcap/unused/09_black_velvet.jpg
Binary file added Resources/matcap/unused/10.jpg
Binary file added Resources/matcap/unused/24_toon.jpg
Binary file added Resources/matcap/unused/ShinyGold.jpg
Binary file added Resources/matcap/unused/mc08_black.jpg
Binary file added Resources/matcap/unused/mc11.jpg
Binary file added Resources/matcap/unused/mc13.jpg
Binary file added Resources/matcap/unused/mc14.jpg
Binary file added Resources/matcap/unused/mc21.jpg
Binary file added Resources/matcap/unused/mc22.jpg
Binary file added Resources/matcap/unused/mc23.jpg
57 changes: 57 additions & 0 deletions Resources/shaders/MatCap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//pref
Brighten|float|0.5|1.5|2.5
SurfaceColor|float|0.0|1.0|1.0
Edge|float|0|0.2|1.0
PenWidth|float|0.01|1|1
MatCap|set|1|1|1
Material Capture Shader http://www.alecjacobson.com/weblog/?p=4827l|note
//vert
#version 330
layout(location = 0) in vec3 Vert;
layout(location = 3) in vec3 Norm;
layout(location = 6) in vec4 Clr;
out vec3 vN, vV;
out vec4 vClr, vP;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
void main() {
vN = normalize((NormalMatrix * Norm));
vP = vec4(Vert, 1.0);
gl_Position = ModelViewProjectionMatrix * vec4(Vert, 1.0);
vV = -vec3(ModelViewMatrix*vec4(Vert,1.0));
vClr = Clr;
}
//frag
#version 330
in vec4 vClr, vP;
in vec3 vN, vV;
out vec4 color;
uniform float Brighten = 0.2;
uniform float SurfaceColor = 0.5;
uniform float Edge = 0.1;
uniform float PenWidth = 0.75;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);
uniform sampler2D MatCap;

vec3 desaturate(vec3 color, float amount) {
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
return vec3(mix(color, gray, amount));
}

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 n = normalize(vN);
vec3 v = normalize(vV);
float lightNormDot = abs(dot(n,v)); //with respect to viewer
if (PenWidth < lightNormDot) discard;
vec2 uv = n.xy * 0.5 + 0.5;
vec3 clr = texture(MatCap,uv.xy).rgb;
vec3 surf = mix(vec3(0.67, 0.67, 0.67), vClr.rgb, SurfaceColor); //0.67 as default Brighten is 1.5
clr = clr * surf * Brighten;
vec3 backclr = desaturate(clr, 0.75);
clr *= min((lightNormDot - 0.5) * Edge, 0.0) + 1.0;
//clr *= min((max(dot(n,normalize(v)), 0.0) - 0.5) * Edge, 0.0) + 1.0;
float backface = step(0.0, n.z);
color = vec4(mix(backclr, clr, backface), 1.0);
}
49 changes: 49 additions & 0 deletions Resources/shaders/MatCap2Side.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//pref
Brighten|float|0.5|1.5|2.5
SurfaceColor|float|0.0|1.0|1.0
Edge|float|0|0.2|1.0
PenWidth|float|0.01|1|1
MatCap|set|1|1|1
Material Capture Shader http://www.alecjacobson.com/weblog/?p=4827l|note
//vert
#version 330
layout(location = 0) in vec3 Vert;
layout(location = 3) in vec3 Norm;
layout(location = 6) in vec4 Clr;
out vec3 vN, vV;
out vec4 vClr, vP;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
void main() {
vN = normalize((NormalMatrix * Norm));
vP = vec4(Vert, 1.0);
gl_Position = ModelViewProjectionMatrix * vec4(Vert, 1.0);
vV = -vec3(ModelViewMatrix*vec4(Vert,1.0));
vClr = Clr;
}
//frag
#version 330
in vec4 vClr, vP;
in vec3 vN, vV;
out vec4 color;
uniform float Brighten = 0.2;
uniform float SurfaceColor = 0.5;
uniform float Edge = 0.1;
uniform float PenWidth = 0.75;
uniform vec4 ClipPlane = vec4(2.0, 0.0, 0.0, 0.0);
uniform sampler2D MatCap;

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 n = normalize(vN);
vec3 v = normalize(vV);
float lightNormDot = abs(dot(n,v)); //with respect to viewer
if (PenWidth < lightNormDot) discard;
vec2 uv = n.xy * 0.5 + 0.5;
vec3 clr = texture(MatCap,uv.xy).rgb;
vec3 surf = mix(vec3(0.67, 0.67, 0.67), vClr.rgb, SurfaceColor); //0.67 as default Brighten is 1.5
clr = clr * surf * Brighten;
clr *= min((lightNormDot - 0.5) * Edge, 0.0) + 1.0;
color = vec4(clr, 1.0);
}
47 changes: 47 additions & 0 deletions Resources/shadersOld/MatCap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//pref
Brighten|float|0.5|1.5|2.5
SurfaceColor|float|0.0|1.0|1.0
Edge|float|0|0.2|1.0
PenWidth|float|0.01|1|1
MatCap|set|1|1|1
Material Capture Shader http://www.alecjacobson.com/weblog/?p=4827l|note
//vert
varying vec3 vN, vV;
varying vec4 vP, vClr;

void main() {
vN = normalize(gl_NormalMatrix * gl_Normal);
vV = -vec3(gl_ModelViewMatrix*gl_Vertex);
vP = gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vClr = gl_Color;
}
//frag
uniform vec4 ClipPlane;
uniform sampler2D MatCap;
uniform float Brighten, SurfaceColor, Edge, PenWidth;
varying vec3 vN, vV;
varying vec4 vP, vClr;

vec3 desaturate(vec3 color, float amount) {
vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
return vec3(mix(color, gray, amount));
}

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 n = normalize(vN);
vec3 v = normalize(vV);
float lightNormDot = abs(dot(n,v)); //with respect to viewer
if (PenWidth < lightNormDot) discard;
vec2 uv = n.xy * 0.5 + 0.5;
vec3 clr = texture2D(MatCap,uv.xy).rgb;
vec3 surf = mix(gl_FrontMaterial.ambient.rgb, vClr.rgb, vClr.a);
surf = mix(vec3(0.67, 0.67, 0.67), surf, SurfaceColor); //0.67 as default Brighten is 1.5
clr = clr * surf * Brighten;
vec3 backclr = desaturate(clr, 0.75);
//clr *= min((max(dot(n,normalize(v)), 0.0) - 0.5) * Edge, 0.0) + 1.0;
clr *= min((lightNormDot - 0.5) * Edge, 0.0) + 1.0;
float backface = step(0.0, n.z);
gl_FragColor = vec4(mix(backclr.rgb, clr.rgb, backface), 1.0);
}
39 changes: 39 additions & 0 deletions Resources/shadersOld/MatCap2Side.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//pref
Brighten|float|0.5|1.5|2.5
SurfaceColor|float|0.0|1.0|1.0
Edge|float|0|0.2|1.0
PenWidth|float|0.01|1|1
MatCap|set|1|1|1
Material Capture Shader http://www.alecjacobson.com/weblog/?p=4827l|note
//vert
varying vec3 vN, vV;
varying vec4 vP, vClr;

void main() {
vN = normalize(gl_NormalMatrix * gl_Normal);
vV = -vec3(gl_ModelViewMatrix*gl_Vertex);
vP = gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vClr = gl_Color;
}
//frag
uniform vec4 ClipPlane;
uniform sampler2D MatCap;
uniform float Brighten, SurfaceColor, Edge, PenWidth;
varying vec3 vN, vV;
varying vec4 vP, vClr;

void main() {
if ((ClipPlane[0] < 1.5) && (dot( ClipPlane, vP) > 0.0)) discard;
vec3 n = normalize(vN);
vec3 v = normalize(vV);
float lightNormDot = abs(dot(n,v)); //with respect to viewer
if (PenWidth < lightNormDot) discard;
vec2 uv = n.xy * 0.5 + 0.5;
vec3 clr = texture2D(MatCap,uv.xy).rgb;
vec3 surf = mix(gl_FrontMaterial.ambient.rgb, vClr.rgb, vClr.a);
surf = mix(vec3(0.67, 0.67, 0.67), surf, SurfaceColor); //0.67 as default Brighten is 1.5
clr = clr * surf * Brighten;
clr *= min((lightNormDot - 0.5) * Edge, 0.0) + 1.0;
gl_FragColor = vec4(clr.rgb, 1.0);
}
2 changes: 2 additions & 0 deletions _windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ REM del .\glext.pp
copy /Y .\optsCompat.inc .\opts.inc
rmdir /S /Q lib

c:\Progra~1\7-Zip\7z a -tzip d:\surfice_windows.zip d:\neuro\Surf_Ice


22 changes: 21 additions & 1 deletion commandsu.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ procedure SHADERAMBIENTOCCLUSION(lVal: single);
procedure SHADERFORBACKGROUNDONLY(BGONLY: boolean);
procedure SHADERLIGHTAZIMUTHELEVATION (AZI, ELEV: integer);
procedure SHADERNAME(lFilename: string);
procedure SHADERMATCAP(lFilename: string);
procedure SHADERXRAY(lObject, lOverlay: single);
procedure TRACKLOAD(lFilename: string);
procedure TRACKPREFS(lLength,lWidth,lDither: single);
Expand All @@ -86,7 +87,7 @@ procedure WAIT (MSEC: integer);
(Ptr:@VERSION;Decl:'VERSION';Vars:'(): string')
);

knProc = 66;
knProc = 67;
kProcRA : array [1..knProc] of TScriptRec = (
(Ptr:@ATLASSTATMAP;Decl:'ATLASSTATMAP';Vars:'(ATLASNAME, STATNAME: string; const Intensities: array of integer; const Intensities: array of single)'),
(Ptr:@ATLASSATURATIONALPHA;Decl:'ATLASSATURATIONALPHA';Vars:'(lSaturation, lTransparency: single)'),
Expand Down Expand Up @@ -145,6 +146,7 @@ procedure WAIT (MSEC: integer);
(Ptr:@SHADERADJUST;Decl:'SHADERADJUST';Vars:'(lProperty: string; lVal: single)'),
(Ptr:@SHADERAMBIENTOCCLUSION;Decl:'SHADERAMBIENTOCCLUSION';Vars:'(lVal: single)'),
(Ptr:@SHADERFORBACKGROUNDONLY;Decl:'SHADERFORBACKGROUNDONLY';Vars:'(BGONLY: boolean)'),
(Ptr:@SHADERMATCAP;Decl:'SHADERMATCAP';Vars:'(lFilename: string)'),
(Ptr:@SHADERNAME;Decl:'SHADERNAME';Vars:'(lFilename: string)'),
(Ptr:@SHADERLIGHTAZIMUTHELEVATION;Decl:'SHADERLIGHTAZIMUTHELEVATION';Vars:'(AZI, ELEV: integer)'),
(Ptr:@SHADERXRAY;Decl:'SHADERXRAY';Vars:'(lObject, lOverlay: single)'),
Expand Down Expand Up @@ -520,6 +522,24 @@ procedure SHADERNAME(lFilename: string);
SetShaderAndDrop(lFilename);
end;

procedure SHADERMATCAP(lFilename: string);
var
i: integer;
begin
i := GLForm1.MatCapDrop.Items.IndexOf(lFilename);
if i < 0 then begin
if GLForm1.MatCapDrop.Items.Count < 1 then
GLForm1.ScriptOutputMemo.Lines.Add('No matcap images available: reinstall Surfice.')
else
GLForm1.ScriptOutputMemo.Lines.Add('Unable to find matcap named '+lFilename+'. Solution: choose an available matcap, e.g. "'+GLForm1.MatCapDrop.Items[0]+'"');
exit;
end;
GLForm1.MatCapDrop.ItemIndex := i;
GLForm1.MatCapDropChange(nil);
if not GLForm1.MatCapDrop.visible then
GLForm1.ScriptOutputMemo.Lines.Add('Hint: shadermatcap() requires using a shader that supports matcaps (use shadername() to select a new shader).')
end;

procedure SHADERFORBACKGROUNDONLY(BGONLY: boolean);
begin
gPrefs.ShaderForBackgroundOnly:= BGONLY;
Expand Down
25 changes: 23 additions & 2 deletions define_types.pas
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
unit define_types;
interface


{$ifndef isTerminalApp}
uses graphics;
uses graphics;
{$endif}

const
kVers = 'v1.0.20190518';
NaN : double = 1/0;
Expand Down Expand Up @@ -86,6 +89,8 @@ function ChangeFileExtX( lFilename: string; lExt: string): string;
function ReadNumBin(var f: TFByte): string; //read next ASCII number in binary file
function float2str(Avalue:double; ADigits:integer):string; //e.g x:single=2.6; floattostrf(x,8,4);
function DefaultToHomeDir(FileName: string; Force: boolean = false): string; //set path to home if not provided
function UpCaseExt(lFileName: string): string; // "file.gii.dset" -> ".DSET"
function UpCaseExt2(lFileName: string): string; // "file.gii.dset" -> ".GII.DSET"
{$ifdef isTerminalApp}
function RGBToColor(R, G, B: Byte): TColor;
procedure ShowMessage(msg: string);
Expand All @@ -100,7 +105,23 @@ implementation

uses
{$IFDEF UNIX} BaseUnix, {$ELSE} windows, shlobj, {$ENDIF}
sysutils, math;
fileutil, sysutils, math;
function UpCaseExt(lFileName: string): string; // "file.gii.dset" -> ".GII.DSET"
var
fnm : string;
begin
result := UpperCase(ExtractFileExt(lFileName));
end;


function UpCaseExt2(lFileName: string): string; // "file.gii.dset" -> ".GII.DSET"
var
fnm : string;
begin
result := UpperCase(ExtractFileExt(lFileName));
fnm := ExtractFileNameWithoutExt(lFileName);
result := UpperCase(ExtractFileExt(fnm))+ result;
end;

function StrToFloatX(Const S : String) : Extended;
//like StrToFloat but accepts either decimal separator: '1.23' or '1,23'
Expand Down
17 changes: 13 additions & 4 deletions gl_core_3d.pas
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,18 @@ procedure SetCoreUniforms (lProg: GLuint);
clr : TRGBA;
end;



function Float2Int16(fv: single): int16;
function Float2Int16(f: single): int16;
begin
if f > 1 then
exit(32767);
if f < -1 then
exit(-32768);
if f > 0 then
result := round(f * 32767)
else
result := round(f * 32768);
end;
(*function Float2Int16(fv: single): int16;
var
f: single;
begin
Expand All @@ -463,7 +472,7 @@ function Float2Int16(fv: single): int16;
result := round(f * 32767)
else
result := round(f * 32768);
end;
end;*)

function AsGL_INT_2_10_10_10_REV(f: TPoint3f): int32;
//pack 3 32-bit floats as 10 bit signed integers, assumes floats normalized to -1..1
Expand Down
Loading

0 comments on commit 8fb0a35

Please sign in to comment.