[windows] project SoC GLSL

This is great!

please make a real time cavity shader too, they are great for sculpting :slight_smile:

thanks for doing this :slight_smile:

wow, i didnt know that blender can do this, iā€™ve checked with the 2.44 and its true.
im having the same problems with the O2/july/2OO7 release as beforeā€¦too bad, that means pretty much that i cant use this awesome looking glsl feature :frowning:

This is the console output I get. I marked what is displayed everytime I start Blender and what is displayed when I try to enable GLSL in the user preferences. Just look for the first mentioning of " GLSL MaterialTree created."

Already written in a previous post but for convinienceā€™s sake:

Windows XP SP2
ATI radeon 9600
1 giga of RAM
some AMD processor around 2,3 Ghz

, diff3, spec1, spec2, spec3, amb_fac, emit, hard); gl_FragColor = vec4(result,
alpha);}

END OF CODE

varying vec3 normal, pos;
varying vec3 vert_color;
varying vec4 realcolor;
attribute vec3 v_col;

void main(){
        normal = normalize(gl_NormalMatrix * gl_Normal);
        vert_color = v_col;
        realcolor = gl_Color;
        gl_Position = ftransform();
        pos = vec3(gl_ModelViewMatrix * gl_Vertex

GLSL Shader Compile Error
Memoryblock GLSL Node Code: end corrupt

 GLSL Material removed.

 GLSL MaterialTree removed.

GLSL Light removed.

 GLSL MaterialTree removed.

GLSL deactivated.

 GLSL MaterialTree created.          ; everything up to this line displays when blender starts

GLSL Light created.

 GLSL Material created.

GLSL DefMaterial created.

 GLSL Material created.

GLSL Program created.

GLSL Shader code writing...
Memoryblock GLSL Node Code: end corrupt

Code:
struct light{
        vec3 loc;
        vec3 vec;
        vec3 color;
        float dist;
        float energy;
        float att1;
        float att2;
        float att3;
        float att4;
        float gamma;
        float area_x;
        float area_y;
        int sphere;
        int square;
        int area_type;
        int layer;
        mat4 mat;
        float areasize;
        float k;
        float spotsize;
        float spotblend;
};
varying vec3 vert_color;
varying vec3 normal, pos;
varying vec4 realcolor;
uniform vec3 eye;
uniform vec3 amb_color;
uniform float amb_exp, amb_range;uniform vec3 u_mat_0_diff_color;
uniform vec3 u_mat_0_spec_color;
uniform vec3 u_mat_0_normal;
uniform float u_mat_0_alpha;
uniform float u_mat_0_diff1;
uniform float u_mat_0_diff2;
uniform float u_mat_0_diff3;
uniform float u_mat_0_spec1;
uniform float u_mat_0_spec2;
uniform float u_mat_0_spec3;
uniform float u_mat_0_amb_fac;
uniform float u_mat_0_emit;
uniform int u_mat_0_hard;
uniform light lights[3];
vec3 lambertdef(light l, vec3 vnormal, vec3 diff_color, float ref, float unused1
, float unused2){
        vec3 lightVec = normalize(l.loc - pos);
        return(max(dot(lightVec, vnormal), 0.0) * ref * vec3(l.color + vert_colo
r) * diff_color);
}
vec3 lambertsun(light l, vec3 vnormal, vec3 diff_color, float ref, float unused1
, float unused2){
        vec3 lightVec = normalize(l.vec);
        return(max(dot(lightVec, vnormal) * ref * vec3(l.color + vert_color) * d
iff_color, 0.0));
}vec3 lamberthemi(light l, vec3 vnormal, vec3 diff_color, float ref){
        vec3 lightVec = normalize(l.vec);
        return((0.5 * dot(lightVec, vnormal) + 0.5) * ref * vec3(l.color + vert_
color) * diff_color);
}vec3 lambertarea(light l, vec3 vnormal, vec3 diff_color, float ref, float unuse
d1, float unused2){
        vec3 lightVec = normalize(l.loc - pos);
        vec3 vect1, vect2, vect3, vect4;
        vec3 cross1, cross2, cross3, cross4;
        float rad[4];

        float fac;

        vect1 = normalize(pos - vec3(l.mat[0][0], l.mat[0][1], l.mat[0][2]));
        vect2 = normalize(pos - vec3(l.mat[1][0], l.mat[1][1], l.mat[1][2]));
        vect3 = normalize(pos - vec3(l.mat[2][0], l.mat[2][1], l.mat[2][2]));
        vect4 = normalize(pos - vec3(l.mat[3][0], l.mat[3][1], l.mat[3][2]));

        cross1 = normalize(cross(vect1, vect2));
        cross2 = normalize(cross(vect2, vect3));
        cross3 = normalize(cross(vect3, vect4));
        cross4 = normalize(cross(vect4, vect1));

        rad[0] = dot(vect1, vect2);
        rad[1] = dot(vect2, vect3);
        rad[2] = dot(vect3, vect4);
        rad[3] = dot(vect4, vect1);

        rad[0] = acos(clamp(rad[0], -1.0, 1.0)) * (1 - floor(clamp(rad[0], 0.1,
1.0) + 0.00001));
        rad[1] = acos(clamp(rad[1], -1.0, 1.0)) * (1 - floor(clamp(rad[1], 0.1,
1.0) + 0.00001));
        rad[2] = acos(clamp(rad[2], -1.0, 1.0)) * (1 - floor(clamp(rad[2], 0.1,
1.0) + 0.00001));
        rad[3] = acos(clamp(rad[3], -1.0, 1.0)) * (1 - floor(clamp(rad[3], 0.1,
1.0) + 0.00001));

        fac  = rad[0] * dot(vnormal, cross1);
        fac += rad[1] * dot(vnormal, cross2);
        fac += rad[2] * dot(vnormal, cross3);
        fac += rad[3] * dot(vnormal, cross4);

        fac = max(pow(-fac * l.areasize, l.k), 0.0);
        return(fac * ref * vec3(l.color + vert_color) * diff_color);
}
vec3 cooktorrdef(light l, vec3 vnormal, vec3 spec_color, float spec, float hard,
 float unused){
        vec3 view = normalize(eye - pos);
        vec3 h = normalize((eye - pos) + (l.loc - pos));
        float nh = max(dot(vnormal, h), 0.0);
        float nv = max(dot(vnormal, view), 0.0);
        return((spec * pow(nh, hard) * spec_color / (0.1 + nv)) * vec3(l.color +
 vert_color));
}
vec3 cooktorrsun(light l, vec3 vnormal, vec3 spec_color, float spec, float hard,
 float unused){
        vec3 view = normalize(eye - pos);
        vec3 h = normalize((eye - pos) + l.vec);
        float nh = max(dot(vnormal, h), 0.0);
        float nv = max(dot(vnormal, view), 0.0);
        return(spec * pow(nh, hard) * vec3(l.color + vert_color) * spec_color /
(0.1 + nv));
}
vec3 cooktorrhemi(light l, vec3 vnormal, vec3 spec_color, float spec, float hard
){
        vec3 view = normalize(eye - pos);
        vec3 h = normalize((eye - pos) + l.vec);
        float nh = 0.5 * (max(dot(vnormal, h), 0.0)) + 0.5;
        return(spec * nh * pow(nh, hard) * vec3(l.color + vert_color) * spec_col
or);
}
vec3 cooktorrarea(light l, vec3 vnormal, vec3 spec_color, float spec, float hard
, float unused){
        vec3 view = normalize(eye - pos);
        vec3 h = normalize((eye - pos) + (l.loc - pos));
        float nh = max(dot(vnormal, h), 0.0);
        float nv = max(dot(vnormal, view), 0.0);
        return((spec * pow(nh, hard) * spec_color / (0.1 + nv)) * vec3(l.color +
 vert_color));
}
float visibility_lamp(light l){
        float visifac = 1.0;
        vec3 lv = (pos - l.loc);
        float dist = sqrt(dot(lv, lv));
        visifac = l.dist / (l.dist + (l.att1 * dist));
        visifac *= (l.dist * l.dist) / ( l.dist * l.dist + (l.att2 * dist * dist
));
        visifac = max(visifac * l.att3, l.dist / (l.dist + dist) * l.att4);
        float m = max(l.dist - dist, 0.0);
        return(visifac * max(m / l.dist, l.sphere));
}

#define MATERIAL_ID 0

#define MATERIAL_FUNC material_ ## 0
vec3 MATERIAL_FUNC(inout vec3 diff_color, inout vec3 spec_color, inout vec3 norm
al, inout float alpha, float diff1, float diff2, float diff3, float spec1, float
 spec2, float spec3, float amb_fac, float emit, int hard){
  vec3 diff_rslt = vec3(0.0, 0.0, 0.0);
  vec3 spec_rslt = vec3(0.0, 0.0, 0.0);
  vec3 amb_rslt = amb_color * amb_fac;
  float vis = 0.0;

#define LIGHT_CALCULATIONS 1

#define LIGHT_ID 0

#define VISIBILITY visibility_ ##  lamp

#define CALC_DIFFUSE 1

#define DIFF_SHADER_ID lambert ## def

#define CALC_SPECULAR 1

#define SPEC_SHADER_ID cooktorr ## def
#ifdef LIGHT_ID
vis = VISIBILITY(lights[LIGHT_ID]);
#endif

#ifdef CALC_DIFFUSE
#ifdef LIGHT_ID
#ifdef HEMI
diff_rslt+= amb_exp * (1.0 - exp(DIFF_SHADER_ID(lights[LIGHT_ID], normal, diff_c
olor, diff1) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis * amb_rang
e));
#else
diff_rslt+= DIFF_SHADER_ID(lights[LIGHT_ID], normal, diff_color, diff1, diff2, d
iff3) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#endif
#endif
#endif

#ifdef CALC_SPECULAR
#ifdef LIGHT_ID
#ifdef HEMI
spec_rslt+= SPEC_SHADER_ID(lights[LIGHT_ID], normal, spec_color, spec1, hard) *
lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#else
spec_rslt+= SPEC_SHADER_ID(lights[LIGHT_ID], normal, spec_color, spec1, spec2, s
pec3) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#endif
#endif
#endif

#undef VISIBILITY
#undef LIGHT_ID
#undef CALC_DIFFUSE
#undef CALC_SPECULAR
#undef DIFF_SHADER_ID
#undef SPEC_SHADER_ID
#undef HEMI
#ifdef LIGHT_CALCULATIONS
  return(amb_exp * (1.0 - exp(diff_rslt * amb_range)) + spec_rslt + amb_rslt);
#else
  return(vec3(0.0, 0.0, 0.0));
#endif
}

#undef MATERIAL_ID
#undef MATERIAL_FUNC
void main(void){  vec3 norm = normalize(normal); vec3 diff_color = realcolor.xyz
; vec3 spec_color = u_mat_0_spec_color; float alpha = realcolor.a; float diff1 =
 u_mat_0_diff1; float diff2 = u_mat_0_diff2; float diff3 = u_mat_0_diff3; float
spec1 = u_mat_0_spec1; float spec2 = u_mat_0_spec2; float spec3 = u_mat_0_spec3;
 float amb_fac = u_mat_0_amb_fac; float emit = u_mat_0_emit; int hard = u_mat_0_
hard; vec3 result = material_0(diff_color, spec_color, norm, alpha, diff1, diff2
, diff3, spec1, spec2, spec3, amb_fac, emit, hard); gl_FragColor = vec4(result,
alpha);}

END OF CODE

varying vec3 normal, pos;
varying vec3 vert_color;
varying vec4 realcolor;
attribute vec3 v_col;

void main(){
        normal = normalize(gl_NormalMatrix * gl_Normal);
        vert_color = v_col;
        realcolor = gl_Color;
        gl_Position = ftransform();
        pos = vec3(gl_ModelViewMatrix * gl_Vertex

GLSL Shader Compile Error
Memoryblock GLSL Node Code: end corrupt

 GLSL Material removed.

 GLSL MaterialTree removed.

GLSL Light removed.

 GLSL MaterialTree removed.

GLSL deactivated.

 GLSL MaterialTree created.

GLSL activated.

Edit: Aha, I take back what I just wrote, it does seem to be working here (Windows XP here, using a GeForce 8600 GTS). I just didnā€™t notice it since the specular highlight is quite wrong, and I didnā€™t even see it. It seems it will only use one lamp at the moment, and itā€™s quite unstable - when I do things like duplicate and delete lamps, Blender crashes.

Iā€™m still quite hopeful and excited though! :slight_smile:

Looks cool. It goes crazy slow if thereā€™s UVMaps involved.

Good for you,
I cannot see my UVmaps ,

turned on texface 'n everythingā€¦

Dangā€¦ ā€œGLSL not supportedā€.:frowning:
Is this because of my computerā€™s ā€˜integratedā€™ graphics?:o

also on my macbook pro it does not work
;(

It works on a quadro FX540ā€¦
And it looks gooood.
One crash, when changing an area lamp into a sun, but havenā€™t been able to reproduce.

this is awesome, cant wait until it work with textures and procedurals, itll be awesome.

this is one of the best things ive seen in blender recently, congrats :slight_smile:

Build updated : removed int variables and preprocessor concatenation symbol for ATI cards.

For ati card user, says if blender fails, Miguel Torres Lima made a test for ati card, and the test fails on linux.

Downloads for windows : http://graphicall.org/builds/builds/showbuild.php?action=show&id=450

Which trunk is it at SVN ?
https://svn.blender.org/svnroot/bf-blender/branches/

Aww, too bad my card doesnā€™t support it.

(but will that Not supported pop-up thingy keep showing up forever? :stuck_out_tongue: )

soc-2007-maike

Iā€™m getting a new pc soon, so which card would support this?:smiley:

Update :Glsl colorband blending functions

download at http://graphicall.org/builds/builds/showbuild.php?action=show&id=450

wow, this is going very fast, do you plan to have support for procedural texture and texture blending?

With the latest build, the pink bar still shows up, but blender is much faster. Then a popup says, ā€œGLSL Shaders: Supportedā€ When I activate the GLSL preview in the User Preferences Window, a popup says: ā€œGLSL fragment Shader compile error: GLSL support disabled,ā€ but in the command window, it says the the GLSL was activated. I tried out some color ramped, image textured, complex material and it showed up in the 3D Window (although the image texture was unrecognizable; at least it made some sort of difference. For reference, I run Windows XP Home SP 2 with ATI Mobility Randeon X1300.

Here is what I got in the command window:

  GLSL Material created.

GLSL DefMaterial created.
Compiled with Python version 2.5.
Checking for installed Python... got it!

GLSL Supported

 GLSL MaterialTree removed.

GLSL Light created.

 GLSL Material created.

GLSL DefMaterial created.

 GLSL Material created.

GLSL Program created.

GLSL Shader code writing...


#define MATERIAL_ID 0

#define MATERIAL_FUNC material_0
vec3 MATERIAL_FUNC(inout vec3 diff_color, inout vec3 spec_color, inout vec3 norm
al, inout float alpha, float diff1, float diff2, float diff3, float spec1, float
 spec2, float spec3, float amb_fac, float emit, int hard){
  vec3 diff_rslt = vec3(0.0, 0.0, 0.0);
  vec3 spec_rslt = vec3(0.0, 0.0, 0.0);
  vec3 amb_rslt = amb_color * amb_fac;
  float vis = 0.0;

#define LIGHT_CALCULATIONS 1

#define LIGHT_ID 0

#define VISIBILITY visibility_lamp

#define CALC_DIFFUSE 1

#define DIFF_SHADER_ID lambertdef

#define CALC_SPECULAR 1

#define SPEC_SHADER_ID cooktorrdef
#ifdef LIGHT_ID
vis = VISIBILITY(lights[LIGHT_ID]);
#endif

#ifdef CALC_DIFFUSE
#ifdef LIGHT_ID
#ifdef HEMI
diff_rslt+= amb_exp * (1.0 - exp(DIFF_SHADER_ID(lights[LIGHT_ID], normal, diff_c
olor, diff1) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis * amb_rang
e));
#else
diff_rslt+= DIFF_SHADER_ID(lights[LIGHT_ID], normal, diff_color, diff1, diff2, d
iff3) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#endif
#endif
#endif

#ifdef CALC_SPECULAR
#ifdef LIGHT_ID
#ifdef HEMI
spec_rslt+= SPEC_SHADER_ID(lights[LIGHT_ID], normal, spec_color, spec1, hard) *
lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#else
spec_rslt+= SPEC_SHADER_ID(lights[LIGHT_ID], normal, spec_color, spec1, spec2, s
pec3) * lights[LIGHT_ID].layer * lights[LIGHT_ID].energy * vis;
#endif
#endif
#endif

#undef VISIBILITY
#undef LIGHT_ID
#undef CALC_DIFFUSE
#undef CALC_SPECULAR
#undef DIFF_SHADER_ID
#undef SPEC_SHADER_ID
#undef HEMI
#ifdef LIGHT_CALCULATIONS
  return(amb_exp * (1.0 - exp(diff_rslt * amb_range)) + spec_rslt + amb_rslt);
#else
  return(vec3(0.0, 0.0, 0.0));
#endif
}

#undef MATERIAL_ID
#undef MATERIAL_FUNC


GLSL Shader Compile Error

 GLSL Material removed.

 GLSL MaterialTree removed.

GLSL Light removed.

 GLSL MaterialTree removed.

GLSL deactivated.

 GLSL MaterialTree created.
GLSL activated

Not nearly as much goings ons in the command window as last time, and less errors, no crashingā€¦ itā€™s doing much better.

this doesnt run on my laptop :frowning:

ive got an intel 945IGP, im guessing it doesnt support GLSL shaders :frowning:

when i click on blender it starts the CLI and then quits straight away, any ideas?

945 IGP does not support GLSL, sorry Daniel. Time to get a new laptop :smiley:
Below are the family of GPUs that supports GLSL:
Radeon 9500 or higher
Geforce 5 or higher.