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

svm_attribute.h « svm « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f9dc4af0072ed30c0da5cee8bd04e4c8ed9cdb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

CCL_NAMESPACE_BEGIN

/* Attribute Node */

__device void svm_node_attr_init(KernelGlobals *kg, ShaderData *sd,
	uint4 node, NodeAttributeType *type,
	NodeAttributeType *mesh_type, AttributeElement *elem, int *offset, uint *out_offset)
{
	if(sd->object != ~0) {
		/* find attribute by unique id */
		uint id = node.y;
		uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride;
		uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);

		while(attr_map.x != id)
			attr_map = kernel_tex_fetch(__attributes_map, ++attr_offset);

		/* return result */
		*elem = (AttributeElement)attr_map.y;
		*offset = as_int(attr_map.z);
		*mesh_type = (NodeAttributeType)attr_map.w;
	}
	else {
		/* background */
		*elem = ATTR_ELEMENT_NONE;
		*offset = 0;
		*mesh_type = (NodeAttributeType)node.w;
	}

	*out_offset = node.z;
	*type = (NodeAttributeType)node.w;
}

__device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
{
	NodeAttributeType type, mesh_type;
	AttributeElement elem;
	uint out_offset;
	int offset;

	svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);

#ifdef __HAIR__
	if (sd->curve_seg != ~0) {
		/*currently strand attributes aren't enabled - only exports stored uvs*/
		if(type == NODE_ATTR_FLOAT)
			stack_store_float(stack, out_offset, 0.0f);
		else {
			float4 sd2 = kernel_tex_fetch(__tri_woop, sd->prim*3+2);
			float3 uv =  make_float3(sd2.z,sd2.w,0.0f);
			stack_store_float3(stack, out_offset, uv);
		}
	}
	else
	{
#endif

		/* fetch and store attribute */
		if(type == NODE_ATTR_FLOAT) {
			if(mesh_type == NODE_ATTR_FLOAT) {
				float f = triangle_attribute_float(kg, sd, elem, offset, NULL, NULL);
				stack_store_float(stack, out_offset, f);
			}
			else {
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, NULL, NULL);
				stack_store_float(stack, out_offset, average(f));
			}
		}
		else {
			if(mesh_type == NODE_ATTR_FLOAT3) {
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, NULL, NULL);
				stack_store_float3(stack, out_offset, f);
			}
			else {
				float f = triangle_attribute_float(kg, sd, elem, offset, NULL, NULL);
				stack_store_float3(stack, out_offset, make_float3(f, f, f));
			}
		}
#ifdef __HAIR__
	}
#endif
}

__device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
{
	NodeAttributeType type, mesh_type;
	AttributeElement elem;
	uint out_offset;
	int offset;

	svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);

	/* fetch and store attribute */
#ifdef __HAIR__
	if (sd->curve_seg != ~0) {
		/*currently strand attributes aren't enabled*/
		if(type == NODE_ATTR_FLOAT)
			stack_store_float(stack, out_offset, 0.0f);
		else
			stack_store_float3(stack, out_offset,  make_float3(0.0f, 0.0f, 0.0f));
	}
	else {
#endif
		if(type == NODE_ATTR_FLOAT) {
			if(mesh_type == NODE_ATTR_FLOAT) {
				float dx;
				float f = triangle_attribute_float(kg, sd, elem, offset, &dx, NULL);
				stack_store_float(stack, out_offset, f+dx);
			}
			else {
				float3 dx;
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, &dx, NULL);
				stack_store_float(stack, out_offset, average(f+dx));
			}
		}
		else {
			if(mesh_type == NODE_ATTR_FLOAT3) {
				float3 dx;
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, &dx, NULL);
				stack_store_float3(stack, out_offset, f+dx);
			}
			else {
				float dx;
				float f = triangle_attribute_float(kg, sd, elem, offset, &dx, NULL);
				stack_store_float3(stack, out_offset, make_float3(f+dx, f+dx, f+dx));
			}
		}
#ifdef __HAIR__
	}
#endif
}

__device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
{
	NodeAttributeType type, mesh_type;
	AttributeElement elem;
	uint out_offset;
	int offset;

	svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);

	/* fetch and store attribute */
#ifdef __HAIR__
	if (sd->curve_seg != ~0) {
		/*currently strand attributes aren't enabled*/
		if(type == NODE_ATTR_FLOAT)
			stack_store_float(stack, out_offset, 0.0f);
		else 
			stack_store_float3(stack, out_offset,  make_float3(0.0f, 0.0f, 0.0f));
	}
	else {
#endif
		if(type == NODE_ATTR_FLOAT) {
			if(mesh_type == NODE_ATTR_FLOAT) {
				float dy;
				float f = triangle_attribute_float(kg, sd, elem, offset, NULL, &dy);
				stack_store_float(stack, out_offset, f+dy);
			}
			else {
				float3 dy;
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, NULL, &dy);
				stack_store_float(stack, out_offset, average(f+dy));
			}
		}
		else {
			if(mesh_type == NODE_ATTR_FLOAT3) {
				float3 dy;
				float3 f = triangle_attribute_float3(kg, sd, elem, offset, NULL, &dy);
				stack_store_float3(stack, out_offset, f+dy);
			}
			else {
				float dy;
				float f = triangle_attribute_float(kg, sd, elem, offset, NULL, &dy);
				stack_store_float3(stack, out_offset, make_float3(f+dy, f+dy, f+dy));
			}
		}
#ifdef __HAIR__
	}
#endif
}

CCL_NAMESPACE_END