Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libRendering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STORM
repos
Radium
libRendering
Commits
4db71905
Commit
4db71905
authored
4 years ago
by
Mathias Paulin
Browse files
Options
Downloads
Patches
Plain Diff
Fix multi-material usage of CustomAttribToColorPass
parent
fbc1df78
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.cpp
+26
-32
26 additions, 32 deletions
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.cpp
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.hpp
+14
-4
14 additions, 4 deletions
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.hpp
with
40 additions
and
36 deletions
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.cpp
+
26
−
32
View file @
4db71905
...
@@ -115,19 +115,21 @@ void CustomAttribToColorPass::execute(
...
@@ -115,19 +115,21 @@ void CustomAttribToColorPass::execute(
bool
CustomAttribToColorPass
::
buildRenderTechnique
(
bool
CustomAttribToColorPass
::
buildRenderTechnique
(
const
Ra
::
Engine
::
Rendering
::
RenderObject
*
ro
,
const
Ra
::
Engine
::
Rendering
::
RenderObject
*
ro
,
Ra
::
Engine
::
Rendering
::
RenderTechnique
&
rt
)
const
{
Ra
::
Engine
::
Rendering
::
RenderTechnique
&
rt
)
const
{
if
(
m_needConfigRebuild
)
{
m_needConfigRebuild
=
false
;
Ra
::
Engine
::
Data
::
ShaderConfigurationFactory
::
removeConfiguration
(
{
"CustomAtt2ClrPass::CustomColorProgram"
}
);
}
std
::
string
resourcesRootDir
=
getResourcesDir
();
std
::
string
resourcesRootDir
=
getResourcesDir
();
auto
mat
=
const_cast
<
Ra
::
Engine
::
Rendering
::
RenderObject
*>
(
ro
)
->
getMaterial
();
auto
mat
=
const_cast
<
Ra
::
Engine
::
Rendering
::
RenderObject
*>
(
ro
)
->
getMaterial
();
// Volumes are not allowed here
// Volumes are not allowed here
if
(
mat
->
getMaterialAspect
()
==
Ra
::
Engine
::
Data
::
Material
::
MaterialAspect
::
MAT_DENSITY
)
if
(
mat
->
getMaterialAspect
()
==
Ra
::
Engine
::
Data
::
Material
::
MaterialAspect
::
MAT_DENSITY
)
{
return
false
;
}
{
return
false
;
}
if
(
m_needConfigRebuild
)
{
m_needConfigRebuild
=
false
;
Ra
::
Engine
::
Data
::
ShaderConfigurationFactory
::
removeConfiguration
(
{
"CustomAtt2ClrPass::CustomColorProgram"
+
mat
->
getMaterialName
()}
);
}
if
(
auto
cfg
=
Ra
::
Engine
::
Data
::
ShaderConfigurationFactory
::
getConfiguration
(
if
(
auto
cfg
=
Ra
::
Engine
::
Data
::
ShaderConfigurationFactory
::
getConfiguration
(
{
"CustomAtt2ClrPass::CustomColorProgram"
}
)
)
{
"CustomAtt2ClrPass::CustomColorProgram"
+
mat
->
getMaterialName
()
}
)
)
{
rt
.
setConfiguration
(
*
cfg
,
passIndex
()
);
}
{
rt
.
setConfiguration
(
*
cfg
,
passIndex
()
);
}
else
else
{
{
...
@@ -191,34 +193,26 @@ bool CustomAttribToColorPass::buildRenderTechnique(
...
@@ -191,34 +193,26 @@ bool CustomAttribToColorPass::buildRenderTechnique(
"vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir);
\n
"
"vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir);
\n
"
"void main()
\n
"
"void main()
\n
"
"{
\n
"
"{
\n
"
"// All vectors are in world space
\n
"
"vec3 normalWorld = getWorldSpaceNormal();
\n
"
"// A material is always evaluated in the fragment local Frame
\n
"
"vec3 tangentWorld = getWorldSpaceTangent();
\n
"
"// compute matrix from World to local Frame
\n
"
"vec3 binormalWorld = getWorldSpaceBiTangent();
\n
"
"vec3 normalWorld = getWorldSpaceNormal();// normalized interpolated normal
\n
"
"vec4 bc = getDiffuseColor(material, getPerVertexTexCoord());
\n
"
"vec3 tangentWorld = getWorldSpaceTangent();// normalized tangent
\n
"
"if (toDiscard(material, bc)) discard;
\n
"
"vec3 binormalWorld = getWorldSpaceBiTangent();// normalized bitangent
\n
"
"normalWorld = getNormal(material, getPerVertexTexCoord(), "
"// discard non opaque fragment
\n
"
"normalWorld, tangentWorld, binormalWorld);
\n
"
"vec4 bc = getDiffuseColor(material, getPerVertexTexCoord());
\n
"
"binormalWorld = normalize(cross(normalWorld, tangentWorld));
\n
"
"if (toDiscard(material, bc))
\n
"
"tangentWorld = normalize(cross(binormalWorld, normalWorld));
\n
"
"discard;
\n
"
"mat3 world2local;
\n
"
"// Apply normal mapping
\n
"
"world2local[0] = vec3(tangentWorld.x, binormalWorld.x, normalWorld.x);
\n
"
"normalWorld = getNormal(material, getPerVertexTexCoord(),
\n
"
"world2local[1] = vec3(tangentWorld.y, binormalWorld.y, normalWorld.y);
\n
"
"normalWorld, tangentWorld, binormalWorld);// normalized bump-mapped normal
\n
"
"world2local[2] = vec3(tangentWorld.z, binormalWorld.z, normalWorld.z);
\n
"
"binormalWorld = normalize(cross(normalWorld, tangentWorld));// normalized "
"vec3 lightDir = normalize(world2local * in_lightVector);
\n
"
"tangent
\n
"
"vec3 viewDir = normalize(world2local * in_viewVector);
\n
"
"tangentWorld = normalize(cross(binormalWorld, normalWorld));// normalized "
"bitangent
\n
"
"mat3 world2local;
\n
"
"world2local[0] = vec3(tangentWorld.x, binormalWorld.x, normalWorld.x);
\n
"
"world2local[1] = vec3(tangentWorld.y, binormalWorld.y, normalWorld.y);
\n
"
"world2local[2] = vec3(tangentWorld.z, binormalWorld.z, normalWorld.z);
\n
"
"// transform all vectors in local frame so that N = (0, 0, 1);
\n
"
"vec3 lightDir = normalize(world2local * in_lightVector);// incident direction
\n
"
"vec3 viewDir = normalize(world2local * in_viewVector);// outgoing direction
\n
"
"out_color = computeCustomColor(material, lightDir, viewDir);
\n
"
"out_color = computeCustomColor(material, lightDir, viewDir);
\n
"
"}
\n
"
};
"}
\n
"
};
Ra
::
Engine
::
Data
::
ShaderConfiguration
theConfig
{
"CustomAtt2ClrPass::CustomColorProgram"
};
Ra
::
Engine
::
Data
::
ShaderConfiguration
theConfig
{
"CustomAtt2ClrPass::CustomColorProgram"
+
mat
->
getMaterialName
()};
theConfig
.
addShaderSource
(
Ra
::
Engine
::
Data
::
ShaderType
::
ShaderType_VERTEX
,
theConfig
.
addShaderSource
(
Ra
::
Engine
::
Data
::
ShaderType
::
ShaderType_VERTEX
,
vertexShaderSource
+
m_customVertexAttrib
);
vertexShaderSource
+
m_customVertexAttrib
);
theConfig
.
addShaderSource
(
Ra
::
Engine
::
Data
::
ShaderType
::
ShaderType_FRAGMENT
,
theConfig
.
addShaderSource
(
Ra
::
Engine
::
Data
::
ShaderType
::
ShaderType_FRAGMENT
,
...
...
This diff is collapsed.
Click to expand it.
src/libRender/RadiumNBR/Passes/CustomAttribToColorPass.hpp
+
14
−
4
View file @
4db71905
...
@@ -21,7 +21,7 @@ class CustomAttribToColorPass : public RenderPass
...
@@ -21,7 +21,7 @@ class CustomAttribToColorPass : public RenderPass
{
{
public:
public:
CustomAttribToColorPass
(
const
std
::
vector
<
RenderObjectPtr
>*
objectsToRender
,
CustomAttribToColorPass
(
const
std
::
vector
<
RenderObjectPtr
>*
objectsToRender
,
const
Ra
::
Core
::
Utils
::
Index
&
idx
);
const
Ra
::
Core
::
Utils
::
Index
&
idx
);
~
CustomAttribToColorPass
()
override
;
~
CustomAttribToColorPass
()
override
;
bool
buildRenderTechnique
(
const
Ra
::
Engine
::
Rendering
::
RenderObject
*
ro
,
bool
buildRenderTechnique
(
const
Ra
::
Engine
::
Rendering
::
RenderObject
*
ro
,
...
@@ -42,7 +42,9 @@ class CustomAttribToColorPass : public RenderPass
...
@@ -42,7 +42,9 @@ class CustomAttribToColorPass : public RenderPass
void
setLightManager
(
const
Ra
::
Engine
::
Scene
::
LightManager
*
lm
);
void
setLightManager
(
const
Ra
::
Engine
::
Scene
::
LightManager
*
lm
);
/// Set the custom glsl function for attrib management (vertex) and colorcomputation (fragment)
/// Set the custom glsl function for attrib management (vertex) and colorcomputation (fragment)
void
setAttribToColorFunc
(
const
std
::
string
&
vertex_source
,
const
std
::
string
&
fragment_source
);
void
setAttribToColorFunc
(
const
std
::
string
&
vertex_source
,
const
std
::
string
&
fragment_source
);
private:
private:
/// The framebuffer used to render this pass
/// The framebuffer used to render this pass
std
::
unique_ptr
<
globjects
::
Framebuffer
>
m_fbo
{
nullptr
};
std
::
unique_ptr
<
globjects
::
Framebuffer
>
m_fbo
{
nullptr
};
...
@@ -54,9 +56,17 @@ class CustomAttribToColorPass : public RenderPass
...
@@ -54,9 +56,17 @@ class CustomAttribToColorPass : public RenderPass
SharedTextures
m_outputTexture
;
SharedTextures
m_outputTexture
;
/// The custom Attrib Vertex shader function
/// The custom Attrib Vertex shader function
std
::
string
m_customVertexAttrib
{};
std
::
string
m_customVertexAttrib
{
"void outputCustomAttribs(){}
\n
"
};
/// the custom FragmentColor shader function
/// the custom FragmentColor shader function
std
::
string
m_customFragmentColor
{};
/// If not changed, compute the same expression (without ao) than the light stage
std
::
string
m_customFragmentColor
{
"vec4 computeCustomColor(Material mat, vec3 light_dir, vec3 view_dir) {
\n
"
"vec3 bsdf= evaluateBSDF(material, getPerVertexTexCoord(), light_dir, view_dir);
\n
"
"vec3 contribution = lightContributionFrom(light, getWorldSpacePosition().xyz);
\n
"
"return vec4(bsdf * 3.141592 * contribution, 1.0);
\n
"
"}
\n
"
};
/// State indicator
/// State indicator
mutable
bool
m_needConfigRebuild
{
true
};
mutable
bool
m_needConfigRebuild
{
true
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment