lorensen / VTKExamples

The VTK examples, formerly hosted on media wiki
Apache License 2.0
342 stars 157 forks source link

How to map a jpg picture to the six surfaces of a cube ?(user shader) #633

Closed hisupersylar closed 1 year ago

hisupersylar commented 4 years ago

recent i study the shader in the vtk. in opengl, i can easily use shaders to map a picture to the six surfaces of a cube. in the fragment shader, i can get the 2D Texture coordinate,then call the function texture or texture2D to get the color at the coordinate. all the codes is as followed:

layout(binding =0) uniform sampler2D tex1 // user the shader version 430 void main() { vec4 texcolor = texture(tex1,TexCoord); // here the TexCoord is a 2D coord. }

in the vtk, we need to get the value of above variable " tex1". in fact , the tex1 is the texture unit of the vtkOpenGLTexture. we use the vtkOpenglTexture to Create the texture. but questions come. how to get the texture unit ?beacause we can pass the unit of the texture to the shader by the uniform variable 。 in the vtkOpenglTexture class ,there is a member function GetTextureUnit who can get the texture unit. then,i found the vtkOpenGLTexture need to set the vtkTextureObject class instance. so i think it is too complex.who can help me ?

hisupersylar commented 4 years ago

in the link https://vtk.org/Wiki/Shaders_In_VTK,i found this as followed: Any vtkTextures assigned to the actor/property will get declared and bound for use in the shader. The names as of VTK 9.0 will be colortexture for the texture used in texture based scalar coloring, actortexture for the actor's texture, and property textures will be named based on the name you passed to SetTexture. The order is that the Actor's texture gets processed first followed by any textures specified in the property. The actual texture unit used for a texture is unknown, but you can count on it having a texture unit and being active when the shader is executed.

ajpmaclean commented 4 years ago

This example: PhysicallyBasedRendering whilst rather complex may give you the information you need. The functions GetTexture and ReadCubeMap may give you the information you need.

Also look at the examples in: Shaders