In Texture3D sample, a color lookup table is created that can be applied to Texture voxels.
I want to implement this in a GLSL vertex shader using a Texture1D color lookup texture.
In TGlDirectOpenGL.OnRender, I added
GLSLShader.Apply(rci,nil);
Problem is: how to pass textures to the shader? I tried to use Param[].AsUniformBuffer:
Hi Daniel,
Thanks! Tried your suggestion, unfortunately, same error message.
Somehow, I have to make the texture known as "uniform", but I have no clue how.
Could not find any sample using a 3D texture with a shader.
Regards, Ronald
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The shader is not attached to a GLScene object. I based my project on GLScene's Texture3D demo, which uses GLDirectOpenGL.OnRender event for rendering, in which I added GLSLShader.Apply just before gl.Begin and GLSLShader.UnApply just after gl.End.
3D objects are rendered OK without the Shader/Apply/UnApply, but I want to be able to remap grayscale values in Texture to rgb colors dynamically (In Dicom terminology change Window Center/Width).
I try to implement a Transfer Function as described here using GLScene.
Hi Ronald can you put the full code of OpenGLDirectRender function and how you generate your 1D Texture, and also the full code of your GLSL script.
The best way for using a specific shader and apply it to any model is to make a child of TGLCustomShader you can take a look at the sample code of GLFurShader, GLIvoryShader, GLErodeShader ect... unit to see how to do. Is not so complicated
Cheers
Jérôme
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for reaching out. Original issue ("Unknown uniform") turned out to caused by the fact that during testing, I did not use the uniforms in shader code (empty main()) and thus, shader compiler removed the uniform.
However, the issue of "how to change texture colors via lookup table in shader" is still unsolved, as is the usage of TGLSLShader (or TGLCustomShader derived class) in combination with TDirectOpenGL.OnRender.
For that, I will start a new Topic. As this issue can be investigated using existing Texture3D demo, I will create sample code based on Texture3D demo and go from there.
Regards, Ronald
PS Daniel, thanks for pointing me in the right direction regarding texture reference passing to shader!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for reaching out. Original issue ("Unknown uniform") turned out to caused by the fact that during testing, I did not use the uniforms in shader code (empty main()) and thus, shader compiler removed the uniform.
This behaviour is normal. Because passing an empty value have non sense. You must also take care of the compatibility of the shader's script, GLScene use OpenGL Legacy (ver < 3.0)
However, the issue of "how to change texture colors via lookup table in shader" is still unsolved,
Ok, so you try to pass an array of byte or TGLColor. So the best way i think is to pass thrue a 1D Texture see here Sampler (GLSL) for more information
In the shader for passing 1D Texture you must do as is :
is the usage of TGLSLShader (or TGLCustomShader derived class) in combination with TDirectOpenGL.OnRender.
When you make a descendant of TGLSLShader (or TGLCustomShader TDirectOpenGL is not needed. Just attach the shader to the material.
For that, I will start a new Topic. As this issue can be investigated using existing Texture3D demo, I will create sample code based on Texture3D demo and go from there.
This is a good idea, post your sample as zip here when it's ready,
It will more easy for help you
I'm using Lazarus but it's not a problem, I already have the texture3D sample works.
The only thing i've need is your GLSL Script and how you initialize the array of color.
Regards. Jérôme
Last edit: Jerome.D (BeanzMaster) 2020-10-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
In Texture3D sample, a color lookup table is created that can be applied to Texture voxels.
I want to implement this in a GLSL vertex shader using a Texture1D color lookup texture.
In TGlDirectOpenGL.OnRender, I added
Problem is: how to pass textures to the shader? I tried to use Param[].AsUniformBuffer:
but this gives me error messages "Unknown uniform".
Shader code (test only):
Suggestions/ideas are highly appreciated!
Regards, Ronald
Hey!
Try this:
Param['aimage'].AsTexture[0] := FTexture3d.Handle;
or
Param['aimage'].AsTexture3D[0] := FTexture3d.Handle;
Hi Daniel,
Thanks! Tried your suggestion, unfortunately, same error message.
Somehow, I have to make the texture known as "uniform", but I have no clue how.
Could not find any sample using a 3D texture with a shader.
Regards, Ronald
Have you managed to make a shader work with a simple texture (sampler2D)?
Unfortunately, no.
I did manage to do 3D volume rendering of a Texture3D (using TGLDirectOpenGL.OnRender), but I did not manage to get any shader to work with it.
In fact, when trying to use a GLSL fragment shader setting fixed color (using gl_FragColor), my entire 3D texture was replaced by a small colored dot.
Is this possible at all using GLScene?
What object do you attach the shader to?
Usually it's added to a material/texture.
The shader is not attached to a GLScene object. I based my project on GLScene's Texture3D demo, which uses GLDirectOpenGL.OnRender event for rendering, in which I added GLSLShader.Apply just before gl.Begin and GLSLShader.UnApply just after gl.End.
3D objects are rendered OK without the Shader/Apply/UnApply, but I want to be able to remap grayscale values in Texture to rgb colors dynamically (In Dicom terminology change Window Center/Width).
I try to implement a Transfer Function as described here using GLScene.
Last edit: Ronald 2020-10-14
Hi Ronald can you put the full code of OpenGLDirectRender function and how you generate your 1D Texture, and also the full code of your GLSL script.
The best way for using a specific shader and apply it to any model is to make a child of TGLCustomShader you can take a look at the sample code of GLFurShader, GLIvoryShader, GLErodeShader ect... unit to see how to do. Is not so complicated
Cheers
Jérôme
Hi Jerome,
Thanks for reaching out. Original issue ("Unknown uniform") turned out to caused by the fact that during testing, I did not use the uniforms in shader code (empty main()) and thus, shader compiler removed the uniform.
However, the issue of "how to change texture colors via lookup table in shader" is still unsolved, as is the usage of TGLSLShader (or TGLCustomShader derived class) in combination with TDirectOpenGL.OnRender.
For that, I will start a new Topic. As this issue can be investigated using existing Texture3D demo, I will create sample code based on Texture3D demo and go from there.
Regards, Ronald
PS Daniel, thanks for pointing me in the right direction regarding texture reference passing to shader!
This behaviour is normal. Because passing an empty value have non sense. You must also take care of the compatibility of the shader's script, GLScene use OpenGL Legacy (ver < 3.0)
In the shader for passing 1D Texture you must do as is :
When you make a descendant of TGLSLShader (or TGLCustomShader TDirectOpenGL is not needed. Just attach the shader to the material.
This is a good idea, post your sample as zip here when it's ready,
It will more easy for help you
I'm using Lazarus but it's not a problem, I already have the texture3D sample works.
The only thing i've need is your GLSL Script and how you initialize the array of color.
Regards. Jérôme
Last edit: Jerome.D (BeanzMaster) 2020-10-16