Krita Source Code Documentation
Loading...
Searching...
No Matches
CFReorientedNormalMapCombine< channels_type > Struct Template Reference

#include <KoCompositeOpFunctions.h>

+ Inheritance diagram for CFReorientedNormalMapCombine< channels_type >:

Static Public Member Functions

static void composeChannels (float srcR, float srcG, float srcB, float &dstR, float &dstG, float &dstB)
 
- Static Public Member Functions inherited from KoClampedSourceAndDestinationCompositeOpGenericFunctorBase< channels_type >
static channels_type clampDestinationChannelValue (channels_type value)
 
static channels_type clampSourceChannelValue (channels_type value)
 

Detailed Description

template<typename channels_type>
struct CFReorientedNormalMapCombine< channels_type >

Definition at line 54 of file KoCompositeOpFunctions.h.

Member Function Documentation

◆ composeChannels()

template<typename channels_type >
static void CFReorientedNormalMapCombine< channels_type >::composeChannels ( float srcR,
float srcG,
float srcB,
float & dstR,
float & dstG,
float & dstB )
inlinestatic

If the source vector has zero height, then we should just skip all the changes (with seems to be the behavior of the formula around the null point)

If the destination vector has zero height, then we should skip its modification (since we cannot rotate it in any way

If the resulting length of the vector is zero, then just keep the destination unchanged. Usually it means that the destination vector is null (i.e. dstR == dstG == dstB == 0.5)

Definition at line 56 of file KoCompositeOpFunctions.h.

56 {
57 // see https://blog.selfshadow.com/publications/blending-in-detail/ by Barre-Brisebois and Hill
58
59 using namespace Arithmetic;
60
66 if (isZeroValueFuzzy(srcB)) {
67 return;
68 }
69
75 float tx = 2*srcR-1;
76 float ty = 2*srcG-1;
77 float tz = 2*srcB;
78 float ux = -2*dstR+1;
79 float uy = -2*dstG+1;
80 float uz = 2*dstB-1;
81 float k = (tx*ux+ty*uy+tz*uz)/tz; // dot(t,u)/t.z
82 float rx = tx*k-ux;
83 float ry = ty*k-uy;
84 float rz = tz*k-uz;
85
86 float finalLength = rx*rx+ry*ry+rz*rz;
87
88
94 if (isZeroValueStrict(finalLength)) {
95 return;
96 }
97
98 k = 1 / sqrt(finalLength); // normalize result
99 rx *= k;
100 ry *= k;
101 rz *= k;
102 dstR = rx*0.5+0.5;
103 dstG = ry*0.5+0.5;
104 dstB = rz*0.5+0.5;
105 }
bool isZeroValueStrict(T value)

The documentation for this struct was generated from the following file: