Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
eos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
eos
Commits
efc90e64
Commit
efc90e64
authored
Aug 14, 2015
by
Patrik Huber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added texturing functions
parent
9b00e3e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
include/eos/render/detail/render_detail.hpp
include/eos/render/detail/render_detail.hpp
+96
-0
No files found.
include/eos/render/detail/render_detail.hpp
View file @
efc90e64
...
...
@@ -113,6 +113,102 @@ double implicit_line(float x, float y, const cv::Vec4f& v1, const cv::Vec4f& v2)
return
((
double
)
v1
[
1
]
-
(
double
)
v2
[
1
])
*
(
double
)
x
+
((
double
)
v2
[
0
]
-
(
double
)
v1
[
0
])
*
(
double
)
y
+
(
double
)
v1
[
0
]
*
(
double
)
v2
[
1
]
-
(
double
)
v2
[
0
]
*
(
double
)
v1
[
1
];
};
// used only in tex2D_linear_mipmap_linear
// template?
float
clamp
(
float
x
,
float
a
,
float
b
)
{
return
std
::
max
(
std
::
min
(
x
,
b
),
a
);
};
cv
::
Vec2f
texcoord_wrap
(
const
cv
::
Vec2f
&
texcoords
)
{
return
cv
::
Vec2f
(
texcoords
[
0
]
-
(
int
)
texcoords
[
0
],
texcoords
[
1
]
-
(
int
)
texcoords
[
1
]);
};
// forward decls
cv
::
Vec3f
tex2d_linear_mipmap_linear
(
const
cv
::
Vec2f
&
texcoords
,
const
Texture
&
texture
,
float
dudx
,
float
dudy
,
float
dvdx
,
float
dvdy
);
cv
::
Vec3f
tex2d_linear
(
const
cv
::
Vec2f
&
imageTexCoord
,
unsigned
char
mipmapIndex
,
const
Texture
&
texture
);
cv
::
Vec3f
tex2d
(
const
cv
::
Vec2f
&
texcoords
,
const
Texture
&
texture
,
float
dudx
,
float
dudy
,
float
dvdx
,
float
dvdy
)
{
return
(
1.0
f
/
255.0
f
)
*
tex2d_linear_mipmap_linear
(
texcoords
,
texture
,
dudx
,
dudy
,
dvdx
,
dvdy
);
};
cv
::
Vec3f
tex2d_linear_mipmap_linear
(
const
cv
::
Vec2f
&
texcoords
,
const
Texture
&
texture
,
float
dudx
,
float
dudy
,
float
dvdx
,
float
dvdy
)
{
using
cv
::
Vec2f
;
float
px
=
std
::
sqrt
(
std
::
pow
(
dudx
,
2
)
+
std
::
pow
(
dvdx
,
2
));
float
py
=
std
::
sqrt
(
std
::
pow
(
dudy
,
2
)
+
std
::
pow
(
dvdy
,
2
));
float
lambda
=
std
::
log
(
std
::
max
(
px
,
py
))
/
CV_LOG2
;
unsigned
char
mipmapIndex1
=
detail
::
clamp
((
int
)
lambda
,
0.0
f
,
std
::
max
(
texture
.
widthLog
,
texture
.
heightLog
)
-
1
);
unsigned
char
mipmapIndex2
=
mipmapIndex1
+
1
;
Vec2f
imageTexCoord
=
detail
::
texcoord_wrap
(
texcoords
);
Vec2f
imageTexCoord1
=
imageTexCoord
;
imageTexCoord1
[
0
]
*=
texture
.
mipmaps
[
mipmapIndex1
].
cols
;
imageTexCoord1
[
1
]
*=
texture
.
mipmaps
[
mipmapIndex1
].
rows
;
Vec2f
imageTexCoord2
=
imageTexCoord
;
imageTexCoord2
[
0
]
*=
texture
.
mipmaps
[
mipmapIndex2
].
cols
;
imageTexCoord2
[
1
]
*=
texture
.
mipmaps
[
mipmapIndex2
].
rows
;
cv
::
Vec3f
color
,
color1
,
color2
;
color1
=
tex2d_linear
(
imageTexCoord1
,
mipmapIndex1
,
texture
);
color2
=
tex2d_linear
(
imageTexCoord2
,
mipmapIndex2
,
texture
);
float
lambdaFrac
=
std
::
max
(
lambda
,
0.0
f
);
lambdaFrac
=
lambdaFrac
-
(
int
)
lambdaFrac
;
color
=
(
1.0
f
-
lambdaFrac
)
*
color1
+
lambdaFrac
*
color2
;
return
color
;
};
cv
::
Vec3f
tex2d_linear
(
const
cv
::
Vec2f
&
imageTexCoord
,
unsigned
char
mipmap_index
,
const
Texture
&
texture
)
{
int
x
=
(
int
)
imageTexCoord
[
0
];
int
y
=
(
int
)
imageTexCoord
[
1
];
float
alpha
=
imageTexCoord
[
0
]
-
x
;
float
beta
=
imageTexCoord
[
1
]
-
y
;
float
oneMinusAlpha
=
1.0
f
-
alpha
;
float
oneMinusBeta
=
1.0
f
-
beta
;
float
a
=
oneMinusAlpha
*
oneMinusBeta
;
float
b
=
alpha
*
oneMinusBeta
;
float
c
=
oneMinusAlpha
*
beta
;
float
d
=
alpha
*
beta
;
cv
::
Vec3f
color
;
using
cv
::
Vec4b
;
//int pixelIndex;
//pixelIndex = getPixelIndex_wrap(x, y, texture->mipmaps[mipmapIndex].cols, texture->mipmaps[mipmapIndex].rows);
int
pixelIndexCol
=
x
;
if
(
pixelIndexCol
==
texture
.
mipmaps
[
mipmap_index
].
cols
)
{
pixelIndexCol
=
0
;
}
int
pixelIndexRow
=
y
;
if
(
pixelIndexRow
==
texture
.
mipmaps
[
mipmap_index
].
rows
)
{
pixelIndexRow
=
0
;
}
//std::cout << texture.mipmaps[mipmapIndex].cols << " " << texture.mipmaps[mipmapIndex].rows << " " << texture.mipmaps[mipmapIndex].channels() << std::endl;
//cv::imwrite("mm.png", texture.mipmaps[mipmapIndex]);
color
[
0
]
=
a
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
0
];
color
[
1
]
=
a
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
1
];
color
[
2
]
=
a
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
2
];
//pixelIndex = getPixelIndex_wrap(x + 1, y, texture.mipmaps[mipmapIndex].cols, texture.mipmaps[mipmapIndex].rows);
pixelIndexCol
=
x
+
1
;
if
(
pixelIndexCol
==
texture
.
mipmaps
[
mipmap_index
].
cols
)
{
pixelIndexCol
=
0
;
}
pixelIndexRow
=
y
;
if
(
pixelIndexRow
==
texture
.
mipmaps
[
mipmap_index
].
rows
)
{
pixelIndexRow
=
0
;
}
color
[
0
]
+=
b
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
0
];
color
[
1
]
+=
b
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
1
];
color
[
2
]
+=
b
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
2
];
//pixelIndex = getPixelIndex_wrap(x, y + 1, texture.mipmaps[mipmapIndex].cols, texture.mipmaps[mipmapIndex].rows);
pixelIndexCol
=
x
;
if
(
pixelIndexCol
==
texture
.
mipmaps
[
mipmap_index
].
cols
)
{
pixelIndexCol
=
0
;
}
pixelIndexRow
=
y
+
1
;
if
(
pixelIndexRow
==
texture
.
mipmaps
[
mipmap_index
].
rows
)
{
pixelIndexRow
=
0
;
}
color
[
0
]
+=
c
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
0
];
color
[
1
]
+=
c
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
1
];
color
[
2
]
+=
c
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
2
];
//pixelIndex = getPixelIndex_wrap(x + 1, y + 1, texture.mipmaps[mipmapIndex].cols, texture.mipmaps[mipmapIndex].rows);
pixelIndexCol
=
x
+
1
;
if
(
pixelIndexCol
==
texture
.
mipmaps
[
mipmap_index
].
cols
)
{
pixelIndexCol
=
0
;
}
pixelIndexRow
=
y
+
1
;
if
(
pixelIndexRow
==
texture
.
mipmaps
[
mipmap_index
].
rows
)
{
pixelIndexRow
=
0
;
}
color
[
0
]
+=
d
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
0
];
color
[
1
]
+=
d
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
1
];
color
[
2
]
+=
d
*
texture
.
mipmaps
[
mipmap_index
].
at
<
Vec4b
>
(
pixelIndexRow
,
pixelIndexCol
)[
2
];
return
color
;
};
void
raster_triangle
(
TriangleToRasterize
triangle
,
cv
::
Mat
colourbuffer
,
cv
::
Mat
depthbuffer
,
boost
::
optional
<
Texture
>
texture
,
bool
enable_far_clipping
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment