Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uniform vec4 uDiffuseColor;
- uniform vec4 uAmbientColor;
- uniform vec3 uSpecularColor;
- uniform float uShininess;
- uniform float uShadowStrength;
- uniform vec3 uShadowColor;
- // these are our new uniforms
- uniform sampler2D s_scaleRef;
- uniform sampler2D s_rot;
- uniform vec2 u_inst_grid;
- uniform float u_disp_scale;
- uniform float u_rot_max;
- // a new rotate funciton
- vec2 rotate2D(float angle, vec2 prevXY){
- mat2 transMat = mat2( cos(angle), -sin(angle),
- sin(angle), cos(angle));
- vec2 new_rot = transMat * prevXY;
- return new_rot;
- }
- out Vertex
- {
- vec4 color;
- vec3 worldSpacePos;
- vec3 worldSpaceNorm;
- vec3 texCoord0;
- flat int cameraIndex;
- } oVert;
- void main()
- {
- // here we use the grid size to crate a UV lookup for our texture
- vec2 samplerLookup = TDInstanceTranslate().xy / (u_inst_grid/2);
- samplerLookup = (samplerLookup / 2) + 0.5;
- // here we grab the alpha value from our texture to determine scale
- float scale = texture(s_scaleRef, samplerLookup).a * u_disp_scale;
- // let's also grab our texture for rotation
- float rotAngle = texture(s_rot, samplerLookup).r * u_rot_max;
- // rotate the instance
- vec2 instRot = rotate2D(rotAngle, TDInstanceTranslate().xy);
- vec3 new_p = P;
- new_p.xy += instRot;
- // scale the instance
- new_p *= scale;
- // First deform the vertex and normal
- // TDDeform always returns values in world space
- vec4 worldSpacePos =TDDeform(new_p);
- gl_Position = TDWorldToProj(worldSpacePos);
- // This is here to ensure we only execute lighting etc. code
- // when we need it. If picking is active we don't need this, so
- // this entire block of code will be ommited from the compile.
- // The TD_PICKING_ACTIVE define will be set automatically when
- // picking is active.
- #ifndef TD_PICKING_ACTIVE
- { // Avoid duplicate variable defs
- vec3 texcoord = TDInstanceTexCoord(uv[0]);
- oVert.texCoord0.stp = texcoord.stp;
- }
- int cameraIndex = TDCameraIndex();
- oVert.cameraIndex = cameraIndex;
- oVert.worldSpacePos.xyz = worldSpacePos.xyz;
- oVert.color = TDInstanceColor(Cd);
- vec3 worldSpaceNorm = normalize(TDDeformNorm(N));
- oVert.worldSpaceNorm.xyz = worldSpaceNorm;
- #else // TD_PICKING_ACTIVE
- // This will automatically write out the nessessary values
- // for this shader to work with picking.
- // See the documentation if you want to write custom values for picking.
- TDWritePickingValues();
- #endif // TD_PICKING_ACTIVE
- }
Add Comment
Please, Sign In to add comment