Revision: 37369 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37369 Author: blendix Date: 2011-06-10 13:22:55 +0000 (Fri, 10 Jun 2011) Log Message: ----------- Cycles: quick GLSL stubs for new material nodes, so they show something.
BSDFs and procedural textures show mostly as diffuse and white, geometry and texture coordinates are incomplete. Modified Paths: -------------- branches/cycles/source/blender/blenkernel/intern/node.c branches/cycles/source/blender/gpu/intern/gpu_draw.c branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_add_closure.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_anisotropic.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_diffuse.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_glass.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_glossy.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_translucent.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_transparent.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_bsdf_velvet.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_emission.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_fresnel.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_geometry.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_light_path.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_mix_closure.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_output_material.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_blend.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_clouds.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_coord.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_distnoise.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_environment.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_image.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_magic.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_marble.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_musgrave.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_noise.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_sky.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_stucci.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_voronoi.c branches/cycles/source/blender/nodes/intern/SHD_nodes/SHD_tex_wood.c Modified: branches/cycles/source/blender/blenkernel/intern/node.c =================================================================== --- branches/cycles/source/blender/blenkernel/intern/node.c 2011-06-10 13:06:51 UTC (rev 37368) +++ branches/cycles/source/blender/blenkernel/intern/node.c 2011-06-10 13:22:55 UTC (rev 37369) @@ -3114,6 +3114,8 @@ gs[i].type= GPU_VEC3; else if (sock->type == SOCK_RGBA) gs[i].type= GPU_VEC4; + else if (sock->type == SOCK_CLOSURE) + gs[i].type= GPU_VEC4; else gs[i].type= GPU_NONE; Modified: branches/cycles/source/blender/gpu/intern/gpu_draw.c =================================================================== --- branches/cycles/source/blender/gpu/intern/gpu_draw.c 2011-06-10 13:06:51 UTC (rev 37368) +++ branches/cycles/source/blender/gpu/intern/gpu_draw.c 2011-06-10 13:22:55 UTC (rev 37369) @@ -1189,6 +1189,7 @@ int GPU_default_lights(void) { + float zero[3] = {0.0f, 0.0f, 0.0f}; int a, count = 0; /* initialize */ @@ -1214,27 +1215,25 @@ glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); - glLightfv(GL_LIGHT0, GL_POSITION, U.light[0].vec); - glLightfv(GL_LIGHT0, GL_DIFFUSE, U.light[0].col); - glLightfv(GL_LIGHT0, GL_SPECULAR, U.light[0].spec); - - glLightfv(GL_LIGHT1, GL_POSITION, U.light[1].vec); - glLightfv(GL_LIGHT1, GL_DIFFUSE, U.light[1].col); - glLightfv(GL_LIGHT1, GL_SPECULAR, U.light[1].spec); - - glLightfv(GL_LIGHT2, GL_POSITION, U.light[2].vec); - glLightfv(GL_LIGHT2, GL_DIFFUSE, U.light[2].col); - glLightfv(GL_LIGHT2, GL_SPECULAR, U.light[2].spec); - for(a=0; a<8; a++) { if(a<3) { if(U.light[a].flag) { glEnable(GL_LIGHT0+a); + + glLightfv(GL_LIGHT0+a, GL_POSITION, U.light[a].vec); + glLightfv(GL_LIGHT0+a, GL_DIFFUSE, U.light[a].col); + glLightfv(GL_LIGHT0+a, GL_SPECULAR, U.light[a].spec); + count++; } - else + else { glDisable(GL_LIGHT0+a); - + + glLightfv(GL_LIGHT0+a, GL_POSITION, zero); + glLightfv(GL_LIGHT0+a, GL_DIFFUSE, zero); + glLightfv(GL_LIGHT0+a, GL_SPECULAR, zero); + } + // clear stuff from other opengl lamp usage glLightf(GL_LIGHT0+a, GL_SPOT_CUTOFF, 180.0); glLightf(GL_LIGHT0+a, GL_CONSTANT_ATTENUATION, 1.0); Modified: branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl =================================================================== --- branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl 2011-06-10 13:06:51 UTC (rev 37368) +++ branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl 2011-06-10 13:22:55 UTC (rev 37369) @@ -108,6 +108,7 @@ } #define M_PI 3.14159265358979323846 +#define M_1_PI 0.31830988618379069 /*********** SHADER NODES ***************/ @@ -1786,3 +1787,312 @@ outcol = vec4(col.rgb, col.a*obcol.a); } +/*********** NEW SHADER UTILITIES **************/ + +float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta) +{ + /* compute fresnel reflectance without explicitly computing + the refracted direction */ + float c = abs(dot(Incoming, Normal)); + float g = eta * eta - 1.0 + c * c; + float result; + + if(g > 0.0) { + g = sqrt(g); + float A =(g - c)/(g + c); + float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0); + result = 0.5 * A * A *(1.0 + B * B); + } + else + result = 1.0; /* TIR (no refracted component) */ + + return result; +} + +float hypot(float x, float y) +{ + return sqrt(x*x + y*y); +} + +/*********** NEW SHADER NODES ***************/ + +#define NUM_LIGHTS 3 + +/* bsdfs */ + +void node_bsdf_diffuse(vec4 color, vec3 N, out vec4 result) +{ + result = vec4(0.0); + + for(int i = 0; i < NUM_LIGHTS; i++) { + vec3 L = gl_LightSource[i].position.xyz; + vec4 Ldiffuse = gl_LightSource[i].diffuse; + + float bsdf = abs(dot(N, L)) * M_1_PI; + result += Ldiffuse*color*bsdf; + } +} + +void node_bsdf_glossy(vec4 color, float roughness, float fresnel, vec3 N, vec3 I, out vec4 result) +{ + result = vec4(0.0); + + for(int i = 0; i < NUM_LIGHTS; i++) { + vec3 H = gl_LightSource[i].halfVector.xyz; + vec4 Lspecular = gl_LightSource[i].specular; + + float bsdf = pow(abs(dot(N, H)), 1.0/roughness) * M_1_PI; + result += Lspecular*color*bsdf; + } +} + +void node_bsdf_anisotropic(vec4 color, float roughnessU, float roughnessV, vec3 N, vec3 I, out vec4 result) +{ + node_bsdf_diffuse(color, N, result); +} + +void node_bsdf_glass(vec4 color, float roughness, float fresnel, vec3 N, vec3 I, out vec4 result) +{ + node_bsdf_diffuse(color, N, result); +} + +void node_bsdf_translucent(vec4 color, vec3 N, out vec4 result) +{ + node_bsdf_diffuse(color, N, result); +} + +void node_bsdf_transparent(vec4 color, out vec4 result) +{ + /* this isn't right */ + result.r = color.r; + result.g = color.g; + result.b = color.b; + result.a = 0.0; +} + +void node_bsdf_velvet(vec4 color, float sigma, float fresnel, vec3 N, out vec4 result) +{ + node_bsdf_diffuse(color, N, result); +} + +/* emission */ + +void node_emission(vec4 color, float strength, vec3 N, out vec4 result) +{ + result = color*strength * M_1_PI; +} + +/* closures */ + +void node_mix_closure(float fac, vec4 closure1, vec4 closure2, out vec4 closure) +{ + closure = mix(closure1, closure2, fac); +} + +void node_add_closure(vec4 closure1, vec4 closure2, out vec4 closure) +{ + closure = closure1 + closure2; +} + +/* fresnel */ + +void node_fresnel(float f, vec3 N, vec3 I, out float result) +{ + f = max(1.0 - f, 0.00001); + result = fresnel_dielectric(I, N, 1.0/f); //backfacing()? f: 1.0/f); +} + +/* geometry */ + +void node_geometry(vec3 I, vec3 N, mat4 toworld, + out vec3 position, out vec3 normal, out vec3 tangent, + out vec3 true_normal, out vec3 incoming, out vec3 parametric, + out float backfacing) +{ + position = (toworld*vec4(I, 1.0)).xyz; + normal = N; + tangent = vec3(0.0); + true_normal = N; + incoming = I; + parametric = vec3(0.0); + backfacing = 0.0; +} + +void node_tex_coord(vec3 I, vec3 N, mat4 toworld, + vec3 attr_orco, vec3 attr_uv, + out vec3 generated, out vec3 uv, out vec3 object, + out vec3 camera, out vec3 window, out vec3 reflection) +{ + generated = attr_orco; + uv = attr_uv; + object = I; + camera = I; + window = gl_FragCoord.xyz; + reflection = reflect(N, I); + +} + +/* textures */ + +void node_tex_blend(vec3 co, out float fac) +{ + fac = 1.0; +} + +void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac) +{ + color = vec4(1.0); + fac = 1.0; +} + +void node_tex_distnoise(vec3 co, float size, float distortion, out float fac) +{ + fac = 1.0; +} + +void node_tex_environment(vec3 co, sampler2D ima, out vec4 color) +{ + float u = (atan(co.y, co.x) + M_PI)/(2.0*M_PI); + float v = atan(co.z, hypot(co.x, co.y))/M_PI + 0.5; + + color = texture2D(ima, vec2(u, v)); +} + +void node_tex_image(vec3 co, sampler2D ima, out vec4 color) +{ + color = texture2D(ima, co.xy); +} + +void node_tex_magic(vec3 p, float turbulence, float n, out vec4 color) +{ + float turb = turbulence/5.0; + + float x = sin((p.x + p.y + p.z)*5.0); + float y = cos((-p.x + p.y - p.z)*5.0); + float z = -cos((-p.x - p.y + p.z)*5.0); + + if(n > 0.0) { + x *= turb; + y *= turb; + z *= turb; + y = -cos(x-y+z); + y *= turb; + + if(n > 1.0) { + x= cos(x-y-z); + x *= turb; + + if(n > 2.0) { + z= sin(-x-y-z); + z *= turb; + + if(n > 3.0) { + x= -cos(-x+y-z); + x *= turb; + + if(n > 4.0) { + y= -sin(-x+y+z); + y *= turb; + + if(n > 5.0) { + y= -cos(-x+y+z); + y *= turb; + + if(n > 6.0) { + x= cos(x+y+z); + x *= turb; + + if(n > 7.0) { + z= sin(x+y-z); + z *= turb; + + if(n > 8.0) { + x= -cos(-x-y+z); + x *= turb; + + if(n > 9.0) { + y= -sin(x-y+z); + y *= turb; + } + } + } + } + } + } + } + } + } + } + + if(turb != 0.0) { + turb *= 2.0; + x /= turb; + y /= turb; + z /= turb; + } + + color = vec4(0.5 - x, 0.5 - y, 0.5 - z, 1.0); +} + +void node_tex_marble(vec3 co, float size, float turbulence, out float fac) +{ + fac = 1.0; +} + +void node_tex_musgrave(vec3 co, float size, float dimension, float lacunarity, float octaves, float offset, float gain, out float fac) +{ + fac = 1.0; +} + +void node_tex_noise(vec3 co, out vec4 color, out float fac) +{ + color = vec4(1.0); + fac = 1.0; +} + +void node_tex_sky(vec3 co, out vec4 color) +{ + color = vec4(1.0); +} + +void node_tex_stucci(vec3 co, float size, float turbulence, out float fac) +{ + fac = 1.0; +} + +void node_tex_voronoi(vec3 co, float size, float weight1, float weight2, float weight3, float weight4, float exponent, out vec4 color, out float fac) +{ + color = vec4(1.0); + fac = 1.0; +} + +void node_tex_wood(vec3 co, float size, float turbulence, out float fac) +{ + fac = 1.0; +} + +/* light path */ + +void node_light_path( + out float is_camera_ray, + out float is_shadow_ray, + out float is_diffuse_ray, + out float is_glossy_ray, + out float is_reflection_ray, + out float is_transmission_ray) +{ + is_camera_ray = 1.0; + is_shadow_ray = 0.0; + is_diffuse_ray = 0.0; + is_glossy_ray = 0.0; + is_reflection_ray = 0.0; + is_transmission_ray = 0.0; +} + +/* output */ + +void node_output_material(vec4 surface, vec4 volume, float displacement, out vec4 result) +{ + result = surface * M_PI; +} + Modified: branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl.c =================================================================== --- branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl.c 2011-06-10 13:06:51 UTC (rev 37368) +++ branches/cycles/source/blender/gpu/intern/gpu_shader_material.glsl.c 2011-06-10 13:22:55 UTC (rev 37369) @@ -1,1232 +1,1428 @@ /* DataToC output of file <gpu_shader_material_glsl> */ -int datatoc_gpu_shader_material_glsl_size= 39207; +int datatoc_gpu_shader_material_glsl_size= 45475; char datatoc_gpu_shader_material_glsl[]= { - 10,102,108,111, 97,116, 32, -101,120,112, 95, 98,108,101,110,100,101,114, 40,102,108,111, 97,116, 32,102, 41, 10,123, 10, 9,114,101,116,117,114,110, 32,112, -111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 50, 56, 52, 54, 44, 32,102, 41, 59, 10,125, 10, 10,118,111,105,100, 32,114,103, - 98, 95,116,111, 95,104,115,118, 40,118,101, 99, 52, 32,114,103, 98, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99, -111,108, 41, 10,123, 10, 9,102,108,111, 97,116, 32, 99,109, 97,120, 44, 32, 99,109,105,110, 44, 32,104, 44, 32,115, 44, 32,118, - 44, 32, 99,100,101,108,116, 97, 59, 10, 9,118,101, 99, 51, 32, 99, 59, 10, 10, 9, 99,109, 97,120, 32, 61, 32,109, 97,120, 40, @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs