Coordinate and Distance Texture Nodes #17998

Closed
opened 2008-11-16 18:38:45 +01:00 by Mathias Panzenböck · 11 comments

%%%This patch adds a input node that gets the pixels coordinate as a vector and a node that calculates the distance between two points (given as vectors).

However, there seems to be a bug somewhere. The two nodes are very simple so I really can't figure what I did wrong.

See the attached screenshots for the bug. Both times the preview should be a blurry black sphere, but one time it's a bar. Both time the "other" input coordinate is (0, 0, 0).

Essentially the Coordinate Node does:
static void valuefn(float *out, float *coord, bNode *node, bNodeStack **in, short thread)
{
out- [x] = coord[0];
out- [x] = coord[1];
out- [x] = coord[2];
}

And the Distance Node does:
static void valuefn(float *out, float *coord, bNode *node, bNodeStack **in, short thread)
{
float coord1- [x], coord2[3];
float x, y, z;

tex_input_vec(coord1, in- [x], coord, thread);
tex_input_vec(coord2, in- [x], coord, thread);

x = coord2- [x] - coord1[0];
y = coord2- [x] - coord1[1];
z = coord2- [x] - coord1[2];

*out = sqrt(x * x + y * y + z * z);

}%%%

%%%This patch adds a input node that gets the pixels coordinate as a vector and a node that calculates the distance between two points (given as vectors). However, there seems to be a bug somewhere. The two nodes are very simple so I really can't figure what I did wrong. See the attached screenshots for the bug. Both times the preview should be a blurry black sphere, but one time it's a bar. Both time the "other" input coordinate is (0, 0, 0). Essentially the Coordinate Node does: static void valuefn(float *out, float *coord, bNode *node, bNodeStack **in, short thread) { out- [x] = coord[0]; out- [x] = coord[1]; out- [x] = coord[2]; } And the Distance Node does: static void valuefn(float *out, float *coord, bNode *node, bNodeStack **in, short thread) { float coord1- [x], coord2[3]; float x, y, z; tex_input_vec(coord1, in- [x], coord, thread); tex_input_vec(coord2, in- [x], coord, thread); x = coord2- [x] - coord1[0]; y = coord2- [x] - coord1[1]; z = coord2- [x] - coord1[2]; *out = sqrt(x * x + y * y + z * z); }%%%

Changed status to: 'Open'

Changed status to: 'Open'

%%%PS: Using this nodes (+displacement modifier + weight paint) you can build nice terrains (see appended screenshots).%%%

%%%PS: Using this nodes (+displacement modifier + weight paint) you can build nice terrains (see appended screenshots).%%%

%%%tex_input_vec expects a 4-vector as its first argument; could be what's causing it. Rewriting to use 3-vectors is on the todo list.%%%

%%%tex_input_vec expects a 4-vector as its first argument; could be what's causing it. Rewriting to use 3-vectors is on the todo list.%%%

%%%Oh, then this bug exists in TEX_translate.c too, because I copied this code from there.%%%

%%%Oh, then this bug exists in TEX_translate.c too, because I copied this code from there.%%%

%%%Added new bugfixed patch "tex_nodes_coord_dist_v2.patch".%%%

%%%Added new bugfixed patch "tex_nodes_coord_dist_v2.patch".%%%

%%%Committed this patch today. Thanks!%%%

%%%Committed this patch today. Thanks!%%%

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

%%%Very nice!
Cool, some code of mine ended up in blender. :)%%%

%%%Very nice! Cool, some code of mine ended up in blender. :)%%%
Member

%%%PS. There is also a function for finding distance in BLI_arithb.h : VecLenf(), which is probably better to use to keep things centralised, and to make the code a lot cleaner.

I also wonder whether it would be better to put that distance function as a mode within the math node, rather than making too many different nodes, or even if the mix node 'difference' can do the same thing?%%%

%%%PS. There is also a function for finding distance in BLI_arithb.h : VecLenf(), which is probably better to use to keep things centralised, and to make the code a lot cleaner. I also wonder whether it would be better to put that distance function as a mode within the math node, rather than making too many different nodes, or even if the mix node 'difference' can do the same thing?%%%

%%%I figured there have to be such an function somewhere but because I don't know blenders source well I did not find it. Someone with commit rights should change this.

I thought the math node only accepts "values", and not vectors?

The difference option of the mix nodes does a completely different thing.%%%

%%%I figured there have to be such an function somewhere but because I don't know blenders source well I did not find it. Someone with commit rights should change this. I thought the math node only accepts "values", and not vectors? The difference option of the mix nodes does a completely different thing.%%%

%%%Matt, the math node won't accept vectors, and the mix node clamps its values to colour range [0..1f]. Could generalize this to a 'vector math' node in the future though.

Thanks for the tip about BLI_arithb, I'll update the code to use that. (Some of my code could probably use it too...)%%%

%%%Matt, the math node won't accept vectors, and the mix node clamps its values to colour range [0..1f]. Could generalize this to a 'vector math' node in the future though. Thanks for the tip about BLI_arithb, I'll update the code to use that. (Some of my code could probably use it too...)%%%
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#17998
No description provided.