[Bf-blender-cvs] [5c1f9c5] cycles-ptex-08: WIP GPU stuff
Nicholas Bishop
noreply at git.blender.org
Tue Jan 20 13:57:14 CET 2015
Commit: 5c1f9c5c9f3776a60d653b0ecd45e5c4ba6cb6fc
Author: Nicholas Bishop
Date: Mon Jan 19 20:03:59 2015 +0100
Branches: cycles-ptex-08
https://developer.blender.org/rB5c1f9c5c9f3776a60d653b0ecd45e5c4ba6cb6fc
WIP GPU stuff
===================================================================
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_codegen.c
M source/blender/gpu/intern/gpu_extensions.c
M source/blender/gpu/shaders/gpu_shader_material.glsl
===================================================================
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index bb0cf2d..100a78a 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -107,6 +107,8 @@ int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver);
* - if created with from_blender, will not free the texture
*/
+GPUTexture *GPU_texture_create_1D_float(int size, float *src, char err_out[256]);
+
GPUTexture *GPU_texture_create_1D(int w, float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, float *fpixels);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 1f9efdc..89c2b19 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -964,10 +964,17 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->textype = type;
//input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL);
- input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, NULL);
- input->textarget = GL_TEXTURE_2D;
+ // TODO
+ if (link->texturesize >= 0) {
+ input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, NULL);
+ input->textarget = GL_TEXTURE_2D;
+ MEM_freeN(link->ptr1);
+ } else {
+ input->tex = GPU_texture_create_1D_float(-link->texturesize, link->ptr1, NULL);
+ input->textarget = GL_TEXTURE_2D;
+ }
- MEM_freeN(link->ptr1);
+
MEM_freeN(link);
}
else if (link->image) {
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index a6b711f..061fc43 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -698,6 +698,23 @@ GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
return tex;
}
+// Very TODO, the code in this file could use a bit of a scrub
+GPUTexture *GPU_texture_create_1D_float(int size, float *src, char err_out[256])
+{
+ GPUTexture *tex = GPU_texture_create_nD(size, 1, 2, NULL, 0, err_out);
+
+ if (tex) {
+ /* Now we tweak some of the settings */
+ /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); */
+ /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); */
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, size, 1, 0, GL_RGBA, GL_FLOAT, src);
+
+ GPU_texture_unbind(tex);
+ }
+
+ return tex;
+}
+
void GPU_invalid_tex_init(void)
{
float color[4] = {1.0f, 0.0f, 1.0f, 1.0};
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index a79bb23..781b043 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2369,13 +2369,15 @@ void node_geometry(vec3 I, vec3 N, mat4 toworld,
}
void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat,
- vec3 attr_orco, vec3 attr_uv,
+ vec3 attr_orco, vec3 attr_uv, vec3 attr_ptex,
out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
- out vec3 camera, out vec3 window, out vec3 reflection)
+ out vec3 camera, out vec3 window, out vec3 reflection,
+ out vec3 ptex)
{
generated = attr_orco * 0.5 + vec3(0.5);
normal = normalize((obinvmat*(viewinvmat*vec4(N, 0.0))).xyz);
uv = attr_uv;
+ ptex = attr_ptex;
object = (obinvmat*(viewinvmat*vec4(I, 1.0))).xyz;
camera = vec3(I.xy, -I.z);
vec4 projvec = gl_ProjectionMatrix * vec4(I, 1.0);
@@ -2467,9 +2469,23 @@ void node_tex_environment_empty(vec3 co, out vec4 color)
color = vec4(1.0, 0.0, 1.0, 1.0);
}
-void node_tex_image(vec3 co, sampler2D ima, out vec4 color, out float alpha)
+void node_tex_image(vec3 co, sampler2D ima, sampler2D ptex_map, out vec4 color, out float alpha)
{
- color = texture2D(ima, co.xy);
+ //color = texture2D(ima, co.xy);
+
+ // TODO :)
+ color = vec4(0, 0, 0, 1);
+ ivec2 offset = ivec2(int(co.z + 0.5), 0);
+ vec4 pm = texelFetch(ptex_map, offset, 0);
+ vec2 rect_xy = pm.xy;
+ vec2 rect_wh = pm.zw;
+
+ vec2 tex_size = vec2(textureSize(ima, 0));
+
+ vec2 uv = (co.xy * rect_wh + rect_xy) / tex_size;
+
+ color = texture2D(ima, uv);
+
alpha = color.a;
}
More information about the Bf-blender-cvs
mailing list