occt 7.4 how to set sampler2D in shaderprogram

Hello everyone, I don't know how to set the value for sampler2d in the fragment shader of shaderprogram of occt7.4.0?

gooch.fs

precision highp float;

varying vec2 TexCoords;
varying vec3 WorldPos;
varying vec3 Normal;

// material parameters
uniform sampler2D albedoMap;
uniform sampler2D normalMap;
uniform sampler2D metallicMap;
uniform sampler2D roughnessMap;
uniform sampler2D aoMap;


const float PI = 3.14159265359;

 

Kirill Gavrilov's picture

You may find useful the following multi-texture (with arbitrary textures) GLSL program test script:
tests/v3d/glsl/texture_multi1

pload MODELING VISUALIZATION

set aShaderVert "
THE_SHADER_OUT vec2 TexCoord;
void main() {
  TexCoord    = occTexCoord.st;
  gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}"

set aShaderFrag "
uniform sampler2D occSampler1;
uniform sampler2D occSampler2;
uniform sampler2D occSampler3;
THE_SHADER_IN vec2 TexCoord;
void main() {
  if      (TexCoord.s <  0.5 && TexCoord.t <  0.5) { occFragColor = occTexture2D(occSampler0, TexCoord.st); }
  else if (TexCoord.s <  0.5 && TexCoord.t >= 0.5) { occFragColor = occTexture2D(occSampler1, TexCoord.st); }
  else if (TexCoord.s >= 0.5 && TexCoord.t <  0.5) { occFragColor = occTexture2D(occSampler2, TexCoord.st); }
  else                                             { occFragColor = occTexture2D(occSampler3, TexCoord.st); }
}"

box b 1 2 3
vinit View1
vdisplay -dispMode 1 b
vfit
vtexture b -tex0 3 -tex1 4 -tex2 5 -tex3 6
vshaderprog b -vert $aShaderVert -frag $aShaderFrag

Concerning usage of standard PBR metal-roughness texture maps, they are implemented within current OCCT development branch and declared with other names - see Declarations.glsl:

uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler
#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
#define occTextureMetallic(theMet,   theTexCoord) (theMet  * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)