Skip to main content

Shader error when trying to apply shadows

So I am trying to apply shadows to this shader I have but I get this error:

THREE.WebGLShader: gl.getShaderInfoLog() vertex ERROR: 0:229: 'transformedNormal' : undeclared identifier ERROR: 0:229: 'inverseTransformDirection' : no matching overloaded function found ERROR: 0:229: '=' : dimension mismatch ERROR: 0:229: '=' : cannot convert from 'const mediump float' to 'highp 3-component vector of float' ERROR: 0:254: 'mvPosition' : redefinition

I assume there's missing shader chunk for normals but I have no idea how to implement one as I am very very new to webgl and three I will put the code below can anyone guide me on how I can apply a fix for this?

shader module:

import { mergeUniforms } from './three/src/renderers/shaders/UniformsUtils.js'
import { UniformsLib } from './three/src/renderers/shaders/UniformsLib.js'

export default {


  uniforms: mergeUniforms([
    UniformsLib.lights,
    UniformsLib.fog,
  ]),


 

  vertexShader: `
    #include <common>
    #include <fog_pars_vertex>
    #include <shadowmap_pars_vertex>
    varying vec2 vUv;
uniform float time;

float N (vec2 st) { // https://thebookofshaders.com/10/
    return fract( sin( dot( st.xy, vec2(12.9898,78.233 ) ) ) *  43758.5453123);
}

float smoothNoise( vec2 ip ){ // https://www.youtube.com/watch?v=zXsWftRdsvU
  vec2 lv = fract( ip );
  vec2 id = floor( ip );
  
  lv = lv * lv * ( 3. - 2. * lv );
  
  float bl = N( id );
  float br = N( id + vec2( 1, 0 ));
  float b = mix( bl, br, lv.x );
  
  float tl = N( id + vec2( 0, 1 ));
  float tr = N( id + vec2( 1, 1 ));
  float t = mix( tl, tr, lv.x );
  
  return mix( b, t, lv.y );
}

    void main() {
      #include <begin_vertex>
      #include <project_vertex>
      #include <worldpos_vertex>
      #include <shadowmap_vertex>
      #include <fog_vertex>
      
       vUv = uv;
  float t = time * 2.;
  
  // VERTEX POSITION
  
  vec4 mvPosition = vec4( position, 1.0 );
  #ifdef USE_INSTANCING
    mvPosition = instanceMatrix * mvPosition;
  #endif
  
  // DISPLACEMENT
  
  float noise = smoothNoise(mvPosition.xz * 0.5 + vec2(0., t));
  noise = pow(noise * 0.5 + 0.5, 2.) * 2.;
  
  // here the displacement is made stronger on the blades tips.
  float dispPower = 1. - cos( uv.y * 3.1416 * 0.5 );
  
  float displacement = noise * ( 0.3 * dispPower );
  mvPosition.z -= displacement;
  
  //
  
  vec4 modelViewPosition = modelViewMatrix * mvPosition;
  gl_Position = projectionMatrix * modelViewPosition;
    }
  `,

  fragmentShader: `
    #include <common>
    #include <packing>
    #include <fog_pars_fragment>
    #include <bsdfs>
    #include <lights_pars_begin>
    #include <shadowmap_pars_fragment>
    #include <shadowmask_pars_fragment>
    #include <dithering_pars_fragment>
    varying vec2 vUv;
    void main() {
      // CHANGE THAT TO YOUR NEEDS
      // ------------------------------
      
       vec3 baseColor = vec3( 0.41, 1.0, 0.5 );
  float clarity = ( vUv.y * 0.875 ) + 0.125;
     
      vec3 shadowColor = vec3(0, 0, 0);
      float shadowPower = 0.5;
      // ------------------------------
      
      
      // it just mixes the shadow color with the frag color
      gl_FragColor = vec4( mix( (baseColor * clarity, 1), shadowColor, (1.0 - getShadowMask() ) * shadowPower), 1.0);
      
    
      #include <fog_fragment>
      #include <dithering_fragment>
    }
  `
};

and in the main I have this:

const uniforms = {
time: {
  value: 0
}
}

this.leavesMaterial = new THREE.ShaderMaterial({
...BasicCustomShader,
uniforms,
side: THREE.DoubleSide,

fog: true,
lights: true,
dithering: true,
});



const instanceNumber = 50000;
const dummy = new THREE.Object3D();

const geometry = new THREE.PlaneGeometry( 0.1, 1, 1, 4 );
geometry.translate( 0, 0.5, 0 ); // move grass blade geometry lowest point at 0.
geometry.receiveShadow = true;
const instancedMesh = new THREE.InstancedMesh( geometry, this.leavesMaterial, instanceNumber );
geometry.receiveShadow = true;
this.scene_.add( instancedMesh );

// Position and scale the grass blade instances randomly.

for ( let i=0 ; i<instanceNumber ; i++ ) {

dummy.position.set(
  ( Math.random() - 0.3 ) * 300,
  0,
  ( Math.random() - 0.3 ) * 300
);

dummy.scale.setScalar( 1.0 + Math.random() * 2.6 );
dummy.scale.y = 1.0 + Math.random() * 5.5;
dummy.rotation.y = Math.random() * Math.PI;

dummy.updateMatrix();
instancedMesh.setMatrixAt( i, dummy.matrix );

}


// animate loop

this.leavesMaterial.uniforms.time.value = clock.getElapsedTime();
this.leavesMaterial.uniformsNeedUpdate = true;

thank you for any help

Via Active questions tagged javascript - Stack Overflow https://ift.tt/vQZ7qGo

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data