Jump to content

SetPostEffectParameter not working


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

With the changes in 0.9.5 and the switch to OpenGL i noticed that the SetPostEffectParameters have changed which was very logical to me, So instead of using Matrix offsets to provide the parameters, it seems the logic behind the scenes are just uniform variables.

Long story short, they currently have no effect.

small snippet using the godrays shader whcih exposes the "Exposure" uniform. Using this code doesn't change the exposure value:

int pidex = camera->AddPostEffect(LoadPostEffect("Shaders/GodRays.fx"));
camera->SetPostEffectParameter(pidex, "Exposure", 10.0f);

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

  • Solution

This will be fixed in the next build. The command is now called Camera::SetUniform, and it accepts the following values:
int, ivec2, ivec3, ivec4, float, vec2, vec2, vec4, texture

Textures will be passed as a uvec2 bindless handle. The texture will be kept in memory while it is used by a camera.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

It works nicely, but i have found a few things to improve:

  1. If a uniform is set with a faulty shader (compiled with errors) an exception is thrown, and you can't see the actual compilation errors
    1. With this in mind, the compile error msg should also provide the filename instead of the index of the file (i have for instance a shader with around 30 inlcudes in them)
  2. please provide also unifrom handling for matrices.
  3. the bindless texture handling can be made much more easy, when passed to a shader it can be used the same way as normal unifrom texture bindings if you use one of these methods: 
void glUniformHandleui64ARB(GLint location, GLuint64 value);
void glUniformHandleui64vARB(GLint location, GLsizei count, const GLuint64 *value);
void glProgramUniformHandleui64ARB(GLuint program, GLint location, GLuint64 value);
void glProgramUniformHandleui64vARB(GLuint program, GLint location, GLsizei count, const GLuint64 *values);

with these methods a shader can consume bindless textures (used as uniforms) with this syntax:

layout(bindless_sampler) uniform sampler2D bindless;
layout(bindless_image) uniform image2D bindless2;

with this the textures can be accessed without casting them in the shader itself.

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

 

4 hours ago, klepto2 said:
layout(bindless_sampler) uniform sampler2D bindless;
layout(bindless_image) uniform image2D bindless2;

this changes everything GIF by The Next Step

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I will do this so it will choose the type based on what is in the shader, and you can use either. It also stores a shared pointer to the texture so it can't get deleted as long as it is bound to the shader:

void RenderShader::SetUniform(const int location, std::shared_ptr<RenderTexture> tex)
{
  if (not Finalize()) return;
  if (location < 0 or location >= uniforms.size()) return;
  auto& u = uniforms[location];
  if (u.defined and u.resource == tex) return;
  if (u.size != 1) return;
  GLuint64 handle = 0;
  switch (u.type)
  {
    case GL_UNSIGNED_INT64_ARB:
      if (tex) handle = tex->GetHandle();
      glProgramUniformHandleui64ARB(program, u.location, handle);
      break;
    case GL_UNSIGNED_INT_VEC2:
      if (tex) handle = tex->GetHandle();
      glProgramUniform2uiv(program, u.location, 1, (GLuint*)handle);
      break;
    default:
      return;
      break;
  }
  glCheckError();
  u.defined = true;
  u.resource = nullptr;
  if (handle) u.resource = tex;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

1 hour ago, Josh said:

The only downside is you can no longer check if the value is 0 to disable the texture.

Actually this should be possible, as you cast the sampler back to uint.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

17 minutes ago, klepto2 said:

Actually this should be possible, as you cast the sampler back to uint.

Wouldn't it have to be cast to a uvec2? The first four bytes could form a zero and the second four bytes could be another value, and an uint would not detect that.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

with this:

#extension GL_ARB_gpu_shader_int64 : enable

you can use use uint64_t directly in the shaders. Also the uvec2 approach might not work on mac system as it is bound to little endian machines if i remember correctly.

 

Also with the latest update the SetUniform with textures isn't working anymore. I assumed that with this update it should be possible to go both ways. but whether uvec2 and uint64_t is not working. When i debug the program with nvidia nsight, the handles are all 0 or (0,0) and i don't see the bound samplers in the shaders resources.

14 hours ago, Josh said:

I will do this so it will choose the type based on what is in the shader, and you can use either. It also stores a shared pointer to the texture so it can't get deleted as long as it is bound to the shader:

void RenderShader::SetUniform(const int location, std::shared_ptr<RenderTexture> tex)
{
  if (not Finalize()) return;
  if (location < 0 or location >= uniforms.size()) return;
  auto& u = uniforms[location];
  if (u.defined and u.resource == tex) return;
  if (u.size != 1) return;
  GLuint64 handle = 0;
  switch (u.type)
  {
    case GL_UNSIGNED_INT64_ARB:
      if (tex) handle = tex->GetHandle();
      glProgramUniformHandleui64ARB(program, u.location, handle);
      break;
    case GL_UNSIGNED_INT_VEC2:
      if (tex) handle = tex->GetHandle();
      glProgramUniform2uiv(program, u.location, 1, (GLuint*)handle);
      break;
    default:
      return;
      break;
  }
  glCheckError();
  u.defined = true;
  u.resource = nullptr;
  if (handle) u.resource = tex;
}

this code seems to be wrong it should be more like:

void RenderShader::SetUniform(const int location, std::shared_ptr<RenderTexture> tex)
{
  if (not Finalize()) return;
  if (location < 0 or location >= uniforms.size()) return;
  auto& u = uniforms[location];
  if (u.defined and u.resource == tex) return;
  if (u.size != 1) return;
  GLuint64 handle = 0;
  switch (u.type)
  {
    case GL_UNSIGNED_INT_VEC2:
      if (tex) handle = tex->GetHandle();
      glProgramUniform2uiv(program, u.location, 1, (GLuint*)handle);
      break;
    default: //Default because the handle can be interpreted as uint64_t and all samplerxd types
      if (tex) handle = tex->GetHandle();
      glProgramUniformHandleui64ARB(program, u.location, handle);
      break;
      break;
  }
  glCheckError();
  u.defined = true;
  u.resource = nullptr;
  if (handle) u.resource = tex;
}

Also some notes about the bindless_sampler/bindless_image qualifier. according to the ARB_bindless_texture specs the default qualifier for sampler or images is the bound qualifier which is the original flow with glActiveTexture etc. if you use the bindless_ qualifier it is possible to either use the original flow or the bindless flow. 

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

I think the type needs to be an exact match. We should determine what a bindless handle looks like on the CPU side.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Maybe you should revert the changes to this for now, currently the textures are not working anymore no matter what uniform type i use. previously the uvec2 approach works at least. 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...