LuxCoreRender / LuxCore

LuxCore source repository
Apache License 2.0
1.15k stars 144 forks source link

Additional Math Texture Operations? #118

Open novacrazy opened 6 years ago

novacrazy commented 6 years ago

It would be great to have a full set of math operations comparable to Cycles Math and Vector Math nodes, so equivalent nodes can then be added to BlendLuxCore and more complex procedural textures can be ported over.

Math operations in LuxCore:

Proposed new operations to add:

Trig functions:

Comparison operators:

Vector math:

Hitpoint information:

Additionally:

While we're at it (sugar for certain equations):

If these suggestions are misguided, please let me know. I'd like to make LuxCore/BlendLuxCore my default renderer for work, and more procedural texture abilities would go a long way.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/59165991-additional-math-texture-operations?utm_campaign=plugin&utm_content=tracker%2F79505306&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F79505306&utm_medium=issues&utm_source=github).
Theverat commented 6 years ago

Good suggestion, I have something like this on my list since a while but did not find time for it yet.

Some comments:

  • [ ] Absolute Value

This is already implemented and available in BlendLuxCore.

  • [ ] Dot Product of Vectors
  • [ ] Cross Product of Vectors
  • [ ] Vector Normalization
  • [ ] Average of Vector elements

These would be kind of useless currently I fear, because we don't have any nodes that provide or accept vectors.

novacrazy commented 6 years ago

This is already implemented and available in BlendLuxCore.

Oops, missed that somehow. Edited the issue.

These would be kind of useless currently I fear, because we don't have any nodes that provide or accept vectors.

They would be useful for plenty of things, especially in conjunction with the property node we've been talking about in LuxCoreRender/BlendLuxCore#167. You could take the position of two objects, subtract them to get a vector, then adjust some procedural texture based on that vector between two objects, either by distance or normalize it and using a 3D mapping.

I've actually done stuff like that once to get texture-only eyes on a cartoon character that still tracked a world object.

Or it could be used with some procedural effects with emissive materials when they get near objects. Or procedural normal maps. Or really anything artists can come up with.

Math is always useful, even indirectly.

novacrazy commented 6 years ago

How would I go about adding these myself? I’ve looked at some of the existing stuff, but not all of it nor how it computes it on the GPU.

Theverat commented 6 years ago

You can look at the commits I made when I added the HSV texture: https://bitbucket.org/luxrender/luxrays/commits/all?search=hsv You need the header and source files for the texture, the parsing code in src/slg/scene/parsetextures.cpp, and a few smaller entries.

You don't have to write the OpenCL code immediately, do the C++ part first.

I have planned to write a "how to add a texture" tutorial like this one since ages, but I did not find the time yet unfortunately. I would be very helpful for new developers.

Theverat commented 6 years ago

A question for @Dade916: Since we are planning to add a lot of textures with rather simple operations, should we go a different route and put all of these operations into one texture (giant switch/case)? Which is better, also from the OpenCL perspective?

EgertKanep commented 6 years ago

Could you make a custom math node, where user could type in his/her own equation? It would be much more flexible. For beginners there could be a sheet with basic operations

Theverat commented 6 years ago

Could you make a custom math node, where user could type in his/her own equation?

You mean that the user types in a string? That would be possible, but this is stuff that the upper software layer (in our case, the BlendLuxCore addon) can handle. It would parse the string, build an AST and translate it to LuxCore texture nodes.

EgertKanep commented 6 years ago

To give a visual idea of my proposal I will make a reference to BlackmagicDesign Fusion. In the expression tab user can type in an operation for each individual channel, additionally they can route in another texture and use those values for doing operations as well. Probably we could use only 1 channel that would control rbg and leave alpha alone image

Theverat commented 5 years ago

I added a remap texture in commit cce9953a2d73738c3d1a70d9c797c12610b4a842.

Theverat commented 5 years ago

By the way, @Dade916: How should we add vector operations? Currently there are only interfaces for float and Spectrum datatypes, not Vector. Should it be added as a new function Texture::GetVectorValue()?

We could make the default in the parent Texture class something like:

Vector Texture::GetVectorValue(const HitPoint &hitPoint) const {
    const Spectrum color = GetSpectrumValue(hitPoint);
    return Vector(color.c[0], color.c[1], color.c[2]);
}

This would make all textures instantly vector-compatible. Only the new vector-related textures (e.g. DotProduct) would need to override GetVectorValue.

Or do you think we should just pass Vectors around as Spectrums, and only convert to Vector in the vector-related functions that need it?

novacrazy commented 5 years ago

Would it not make more sense to use mathematical vectors and RGB colors (as vectors even) for the entirety of the procedural texture, and only converting it to a Spectrum type at the end? It’s just numbers until fed into the shaders, anyway.

Theverat commented 5 years ago

Spectrum is a typedef for RGB color in LuxCore currently: https://github.com/LuxCoreRender/LuxCore/blob/master/include/luxrays/core/color/color.h#L470

Theverat commented 5 years ago

I implemented the OpenCL version of the Divide texture: Hope I didn't forget anything, and sorry for the noisy diff: https://github.com/LuxCoreRender/LuxCore/commit/23db1881d9c4bbba9799749c1d03378f5259de73

Dade916 commented 5 years ago

I guess we can now close this.

Theverat commented 5 years ago

I would have left it open, there are still a lot of textures listed in the first post.

novacrazy commented 5 years ago

No power or trig functions are definitely still a dealbreaker for me.

Theverat commented 5 years ago

Don't worry. I should have mentioned in my pull request that I will continue working on the new_math_textures branch.

Theverat commented 5 years ago

I'm continuing to implement the planned textures. @Dade916, is it ok if I put the existing math textures (scale, add, subtract etc.) into a "slg/textures/math/" directory? Also I want to expose some hitpoint properties: shading normal, geometry normal and position. Maybe I should create a "slg/textures/hitpoint/" directory for them, and also move the hitpointcolor textures there? I'm imagining something like this:

slg/
  textures/
    math/
      scale.h
      add.h
      subtract.h
      ...
    vectormath/
      dotproduct.h
      crossproduct.h
      normalize.h
      ...
    hitpoint/
      hitpointcolor.h
      shadingnormal.h
      geometrynormal.h
      position.h
Dade916 commented 5 years ago

Sure.

Theverat commented 5 years ago

@CatherineTower has implemented two new textures:

Diplodocee commented 4 years ago

I see on this list that "breaking a vector into scalars" is something that's marked as completed, but I'm having a hard time figuring out how to do that. What is that node called/how do I access it?

Dade916 commented 4 years ago

They are the splitfloat3 and makefloat3 textures.