Skip to content

Update animated parameters by getting current time from renderer #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2018

Conversation

usakhelo
Copy link
Contributor

Hi,
This PR fixes bug #212. OSL materials and textures were not updated during animation rendering. Now they are working. What I did is instead of getting current with the call GetCOREInterface()->GetTime() I added a function to renderer to get currently rendered frame from the it.

Thanks for review!
Sergo.

@@ -554,10 +554,11 @@ asf::auto_release_ptr<asr::EnvironmentEDF> AppleseedEnvMap::create_envmap(const
{
float sun_theta_deg = m_sun_theta;
float sun_phi_deg = m_sun_phi;
const TimeValue time = get_current_time();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move inside the if below?

@@ -279,30 +280,31 @@ TSTR OSLMaterial::GetSubTexmapSlotName(int i)

void OSLMaterial::Update(TimeValue t, Interval& valid)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant blank line.

auto shader_group_name = make_unique_name(assembly.shader_groups(), std::string(name) + "_shader_group");
auto shader_group = asr::ShaderGroupFactory::create(shader_group_name.c_str());

const TimeValue time = get_current_time();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move inside if below?

else
m_pblock->GetValue(tex_param.first, t, tex_map, m_params_validity);

if (tex_map)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make comparison explicit.

{
Texmap* tex_map = nullptr;
m_pblock->GetValue(tex_param.first, t, tex_map, m_params_validity);
if (tex_map)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make comparison explicit.

@@ -50,17 +50,17 @@ void connect_output_selector(
const char* material_input_name,
Texmap* texmap)
{
const auto t = GetCOREInterface()->GetTime();
TimeValue time = get_current_time();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make const.

@@ -106,11 +107,11 @@ void connect_output_map(
Texmap* texmap,
const float const_value)
{
const auto t = GetCOREInterface()->GetTime();
const auto time = get_current_time();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TimeValue out of consistency with the rest of the code.

@@ -81,11 +81,12 @@ void connect_output_map(
Texmap* texmap,
const Color const_value)
{
const auto t = GetCOREInterface()->GetTime();
TimeValue time = get_current_time();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make const.


if (source_map)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make comparison explicit.

@@ -31,6 +31,7 @@

// appleseed-max headers.
#include "appleseedoslplugin/osltexture.h"
#include "appleseedrenderer/appleseedrenderer.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit concerning that utilities depends on appleseedrenderer: lower level components should never depend on higher level ones. Maybe get_current_time() should be declared in appleseedrenderer.{h,cpp}.

For the same reason I'm slightly concerned about the dependencies toward appleseedoslplugin/osltexture.h and osloutputselectormap/osloutputselector.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I make get_current_time in appleseedrenderer a global function, not the class member? So that I don't have to check and cast current renderer to get the time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I meant. You could also make it a static method of AppleseedRenderer to highlight the dependency to that class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to move it to the renderer class but in some utilities I still need to call that function so I still need to include renderer header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other way is to pass time from the renderer to all that create_material and so on as an argument.

@usakhelo
Copy link
Contributor Author

Hi @dictoon ,
I added time parameter to the utility functions and then I noticed that only couple of other functions need to be changed in order to get rid of static get_time function. So I decided to change all the functions and now time is passed from the project builder to each material creation function.
It may seem too much of parameters to some of the functions, but it also makes it obvious that they all need time information to work correctly.

@luisbarrancos
Copy link
Member

This might be relevant:
AcademySoftwareFoundation/OpenShadingLanguage#828
OSL will have acess to global (or camera) frame.

@dictoon
Copy link
Member

dictoon commented Oct 15, 2018

So I decided to change all the functions and now time is passed from the project builder to each material creation function.

In my opinion, definitely the right solution as it makes dependencies clear.

Copy link
Member

@dictoon dictoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Feel free to merge after you've addressed the few remaining details I reported.

@@ -1953,7 +1948,6 @@ void AppleseedRenderer::clear()
m_entities.clear();
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We conventionally keep two blank lines before block comments.

namespace
{
class MaxShadeContext
: public ShadeContext
{
public:
explicit MaxShadeContext(const asr::SourceInputs& source_inputs)
explicit MaxShadeContext(const asr::SourceInputs& source_inputs, TimeValue time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit has become redundant here, not that it really hurts...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make time const.

@@ -567,9 +559,10 @@ namespace
: public asr::Source
{
public:
explicit MaxProceduralTextureSource(Texmap* texmap)
explicit MaxProceduralTextureSource(Texmap* texmap, TimeValue time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make time const.

@@ -651,18 +644,19 @@ namespace
}

private:
Texmap* m_texmap;
Texmap* m_texmap;
TimeValue m_time;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be made const here too? (I think so.)

@@ -689,9 +683,10 @@ namespace
: public asr::Texture
{
public:
MaxProceduralTexture(const char* name, Texmap* texmap)
MaxProceduralTexture(const char* name, Texmap* texmap, TimeValue time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make time const.

@usakhelo usakhelo merged commit ddc03b0 into appleseedhq:master Oct 16, 2018
@usakhelo usakhelo deleted the fix_animated_parameters branch October 14, 2019 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants