Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_material.glsl')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl138
1 files changed, 132 insertions, 6 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 311fcb8ead2..18468c1674f 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -1,3 +1,13 @@
+/* Converters */
+
+float convert_rgba_to_float(vec4 color)
+{
+#ifdef USE_NEW_SHADING
+ return color.r*0.2126 + color.g*0.7152 + color.b*0.0722;
+#else
+ return (color.r + color.g + color.b) / 3.0;
+#endif
+}
float exp_blender(float f)
{
@@ -166,6 +176,21 @@ void particle_info(vec4 sprops, vec3 loc, vec3 vel, vec3 avel, out float index,
angular_velocity = avel;
}
+void vect_normalize(vec3 vin, out vec3 vout)
+{
+ vout = normalize(vin);
+}
+
+void direction_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout)
+{
+ vout = (mat*vec4(vin, 0.0)).xyz;
+}
+
+void point_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout)
+{
+ vout = (mat*vec4(vin, 1.0)).xyz;
+}
+
void mapping(vec3 vec, mat4 mat, vec3 minvec, vec3 maxvec, float domin, float domax, out vec3 outvec)
{
outvec = (mat * vec4(vec, 1.0)).xyz;
@@ -369,6 +394,12 @@ void vec_math_negate(vec3 v, out vec3 outv)
outv = -v;
}
+void invert_z(vec3 v, out vec3 outv)
+{
+ v.z = -v.z;
+ outv = v;
+}
+
void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
{
outnor = nor;
@@ -722,7 +753,11 @@ void valtorgb(float fac, sampler2D colormap, out vec4 outcol, out float outalpha
void rgbtobw(vec4 color, out float outval)
{
+#ifdef USE_NEW_SHADING
+ outval = color.r*0.2126 + color.g*0.7152 + color.b*0.0722;
+#else
outval = color.r*0.35 + color.g*0.45 + color.b*0.2; /* keep these factors in sync with texture.h:RGBTOBW */
+#endif
}
void invert(float fac, vec4 col, out vec4 outcol)
@@ -888,6 +923,11 @@ void shade_norm(vec3 normal, out vec3 outnormal)
outnormal = -normalize(normal);
}
+void mtex_mirror(vec3 tcol, vec4 refcol, float tin, float colmirfac, out vec4 outrefcol)
+{
+ outrefcol = mix(refcol, vec4(1.0, tcol), tin*colmirfac);
+}
+
void mtex_rgb_blend(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
{
float facm;
@@ -1189,6 +1229,11 @@ void mtex_alpha_to_col(vec4 col, float alpha, out vec4 outcol)
outcol = vec4(col.rgb, alpha);
}
+void mtex_alpha_multiply_value(vec4 col, float value, out vec4 outcol)
+{
+ outcol = vec4(col.rgb, col.a * value);
+}
+
void mtex_rgbtoint(vec4 rgb, out float intensity)
{
intensity = dot(vec3(0.35, 0.45, 0.2), rgb.rgb);
@@ -1238,6 +1283,21 @@ vec3 mtex_2d_mapping(vec3 vec)
return vec3(vec.xy*0.5 + vec2(0.5), vec.z);
}
+void mtex_cube_map(vec3 co, samplerCube ima, out float value, out vec4 color)
+{
+ color = textureCube(ima, co);
+ value = 1.0;
+}
+
+void mtex_cube_map_refl(samplerCube ima, vec3 vp, vec3 vn, mat4 viewmatrixinverse, mat4 viewmatrix, out float value, out vec4 color)
+{
+ vec3 viewdirection = vec3(viewmatrixinverse * vec4(vp, 0.0));
+ vec3 normaldirection = normalize(vec3(vec4(vn, 0.0) * viewmatrix));
+ vec3 reflecteddirection = reflect(viewdirection, normaldirection);
+ color = textureCube(ima, reflecteddirection);
+ value = 1.0;
+}
+
void mtex_image(vec3 texco, sampler2D ima, out float value, out vec4 color)
{
color = texture2D(ima, texco.xy);
@@ -1572,6 +1632,17 @@ void lamp_falloff_sliders(float lampdist, float ld1, float ld2, float dist, out
visifac *= lampdistkw/(lampdistkw + ld2*dist*dist);
}
+void lamp_falloff_invcoefficients(float coeff_const, float coeff_lin, float coeff_quad, float dist, out float visifac)
+{
+ vec3 coeff = vec3(coeff_const, coeff_lin, coeff_quad);
+ vec3 d_coeff = vec3(1.0, dist, dist*dist);
+ float visifac_r = dot(coeff, d_coeff);
+ if (visifac_r > 0.0)
+ visifac = 1.0 / visifac_r;
+ else
+ visifac = 0.0;
+}
+
void lamp_falloff_curve(float lampdist, sampler2D curvemap, float dist, out float visifac)
{
visifac = texture2D(curvemap, vec2(dist/lampdist, 0.0)).x;
@@ -1584,11 +1655,13 @@ void lamp_visibility_sphere(float lampdist, float dist, float visifac, out float
outvisifac= visifac*max(t, 0.0)/lampdist;
}
-void lamp_visibility_spot_square(vec3 lampvec, mat4 lampimat, vec3 lv, out float inpr)
+void lamp_visibility_spot_square(vec3 lampvec, mat4 lampimat, vec2 scale, vec3 lv, out float inpr)
{
if(dot(lv, lampvec) > 0.0) {
vec3 lvrot = (lampimat*vec4(lv, 0.0)).xyz;
- float x = max(abs(lvrot.x/lvrot.z), abs(lvrot.y/lvrot.z));
+ /* without clever non-uniform scale, we could do: */
+ // float x = max(abs(lvrot.x / lvrot.z), abs(lvrot.y / lvrot.z));
+ float x = max(abs((lvrot.x / scale.x) / lvrot.z), abs((lvrot.y / scale.y) / lvrot.z));
inpr = 1.0/sqrt(1.0 + x*x);
}
@@ -1596,9 +1669,21 @@ void lamp_visibility_spot_square(vec3 lampvec, mat4 lampimat, vec3 lv, out float
inpr = 0.0;
}
-void lamp_visibility_spot_circle(vec3 lampvec, vec3 lv, out float inpr)
+void lamp_visibility_spot_circle(vec3 lampvec, mat4 lampimat, vec2 scale, vec3 lv, out float inpr)
{
- inpr = dot(lv, lampvec);
+ /* without clever non-uniform scale, we could do: */
+ // inpr = dot(lv, lampvec);
+ if (dot(lv, lampvec) > 0.0) {
+ vec3 lvrot = (lampimat * vec4(lv, 0.0)).xyz;
+ float x = abs(lvrot.x / lvrot.z);
+ float y = abs(lvrot.y / lvrot.z);
+
+ float ellipse = abs((x * x) / (scale.x * scale.x) + (y * y) / (scale.y * scale.y));
+
+ inpr = 1.0 / sqrt(1.0 + ellipse);
+ }
+ else
+ inpr = 0.0;
}
void lamp_visibility_spot(float spotsi, float spotbl, float inpr, float visifac, out float outvisifac)
@@ -1624,6 +1709,40 @@ void lamp_visibility_clamp(float visifac, out float outvisifac)
outvisifac = (visifac < 0.001)? 0.0: visifac;
}
+void world_paper_view(vec3 vec, out vec3 outvec)
+{
+ vec3 nvec = normalize(vec);
+ outvec = (gl_ProjectionMatrix[3][3] == 0.0) ? vec3(nvec.x, 0.0, nvec.y) : vec3(0.0, 0.0, -1.0);
+}
+
+void world_zen_mapping(vec3 view, float zenup, float zendown, out float zenfac)
+{
+ if (view.z >= 0.0)
+ zenfac = zenup;
+ else
+ zenfac = zendown;
+}
+
+void world_blend_paper_real(vec3 vec, out float blend)
+{
+ blend = abs(vec.y);
+}
+
+void world_blend_paper(vec3 vec, out float blend)
+{
+ blend = (vec.y + 1.0) * 0.5;
+}
+
+void world_blend_real(vec3 vec, out float blend)
+{
+ blend = abs(normalize(vec).z);
+}
+
+void world_blend(vec3 vec, out float blend)
+{
+ blend = (normalize(vec).z + 1) * 0.5;
+}
+
void shade_view(vec3 co, out vec3 view)
{
/* handle perspective/orthographic */
@@ -1944,6 +2063,11 @@ void shade_add_spec(float t, vec3 lampcol, vec3 speccol, out vec3 outcol)
outcol = t*lampcol*speccol;
}
+void shade_add_mirror(vec3 mir, vec4 refcol, vec3 combined, out vec3 result)
+{
+ result = mir*refcol.gba + (vec3(1.0) - mir*refcol.rrr)*combined;
+}
+
void alpha_spec_correction(vec3 spec, float spectra, float alpha, out float outalpha)
{
if (spectra > 0.0) {
@@ -2258,7 +2382,7 @@ void node_subsurface_scattering(vec4 color, float scale, vec3 radius, float shar
node_bsdf_diffuse(color, 0.0, N, result);
}
-void node_bsdf_hair(vec4 color, float offset, float roughnessu, float roughnessv, out vec4 result)
+void node_bsdf_hair(vec4 color, float offset, float roughnessu, float roughnessv, vec3 tangent, out vec4 result)
{
result = color;
}
@@ -2546,7 +2670,8 @@ void node_light_path(
out float is_transmission_ray,
out float ray_length,
out float ray_depth,
- out float transparent_depth)
+ out float transparent_depth,
+ out float transmission_depth)
{
is_camera_ray = 1.0;
is_shadow_ray = 0.0;
@@ -2558,6 +2683,7 @@ void node_light_path(
ray_length = 1.0;
ray_depth = 1.0;
transparent_depth = 1.0;
+ transmission_depth = 1.0;
}
void node_light_falloff(float strength, float tsmooth, out float quadratic, out float linear, out float constant)