<commit_before>'use strict';
var Camera = require( 'osg/Camera' );
var ComputeBoundsVisitor = require( 'osg/ComputeBoundsVisitor' );
var FrameBufferObject = require( 'osg/FrameBufferObject' );
var Matrix = require( 'osg/Matrix' );
var Notify = require( 'osg/Notify' );
var StateAttribute = require( 'osg/StateAttribute' );
var StateSet = require( 'osg/StateSet' );
var Texture = require( 'osg/Texture' );
var Transform = require( 'osg/Transform' );
var Uniform = require( 'osg/Uniform' );
var MACROUTILS = require( 'osg/Utils' );
var Vec3 = require( 'osg/Vec3' );
var Vec4 = require( 'osg/Vec4' );
var Viewport = require( 'osg/Viewport' );
var WebGLCaps = require( 'osg/WebGLCaps' );
var ShadowReceiveAttribute = require( 'osgShadow/ShadowReceiveAttribute' );
var ShadowCasterVisitor = require( 'osgShadow/ShadowCasterVisitor' );
var ShadowFrustumIntersection = require( 'osgShadow/ShadowFrustumIntersection' );
var ShadowCastAttribute = require( 'osgShadow/ShadowCastAttribute' );
var ShadowTechnique = require( 'osgShadow/ShadowTechnique' );
var ShadowTexture = require( 'osgShadow/ShadowTexture' );


// Custom camera cull callback
// we customize it just to avoid to add extra 'virtual' function
// on the shadowTecnique class
var CameraCullCallback = function ( shadowTechnique ) {
    this._shadowTechnique = shadowTechnique;
};

CameraCullCallback.prototype = {
    cull: function ( node, nv ) {

        // see ShadowTechnique CameraCullCallback
        this._shadowTechnique.getShadowedScene().nodeTraverse( nv );



        var cs = nv.getCurrentCullingSet();
        if ( nv.getComputeNearFar() === true && nv.getComputedFar() >= nv.getComputedNear() ) {
            var m = nv.getCurrentProjectionMatrix();

            //Matrix.clampProjectionMatrix( m, nv.getComputedNear(), nv.getComputedFar(), nv.getNearFarRatio() );
            this._shadowTechnique.getDepthRange()[ 0 ] = nv.getComputedNear();
            this._shadowTechnique.getDepthRange()[ 1 ] = nv.getComputedFar();

            Matrix.getFrustumPlanes( m, nv.getCurrentModelViewMatrix(), cs.getFrustum().getPlanes(), false );
            // TODO: no far no near.
            // should check if we have them
            // should add at least a near 0 clip if not
            cs.getFrustum().setupMask( 6 );
        }

        this._shadowTechnique.setLightFrustum( cs.getFrustum() );
        return false;
    }
};

/**
 *  ShadowMap provides an implementation of shadow textures.
 *  @class ShadowMap
 */
var ShadowMap = function ( settings ) {
    ShadowTechnique.call( this );

    this._projectionMatrix = Matrix.create();
    this._viewMatrix = Matrix.create();

    this._lightUp = Vec3.createAndSet( 0.0, 0.0, 1.0 );

    this._light = settings.light;

    // data
    this._cameraShadow = new Camera();
    this._cameraShadow.setCullCallback( new CameraCullCallback( this ) );
    this._cameraShadow.setRenderOrder( Camera.PRE_RENDER, 0 );
    this._cameraShadow.setReferenceFrame( Transform.ABSOLUTE_RF );
    this._cameraShadow.setClearColor( Vec4.createAndSet( 1.0, 1.0, 1.0, 1.0 ) );

    this._texture = new ShadowTexture();
    this._textureUnitBase = 4;
    this._textureUnit = this._textureUnitBase;

    // see shadowSettings.js header for param explanations
    this._textureMagFilter = undefined;
    this._textureMinFilter = undefined;
    this._textureSize = 256;


    this._receivingStateset = undefined;

    this._casterStateSet = new StateSet();
    this._casterStateSet.addUniform( Uniform.createFloat1( 0, 'exponent0' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 0, 'exponent1' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 0.005, 'bias' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 1.0 / this._textureSize, 'texelSize' ) );
    this._casterStateSet.addUniform( Uniform.createFloat2( [ this._textureSize, this._textureSize ], 'RenderSize' ) );


    this._shadowReceiveAttribute = new ShadowReceiveAttribute( this._light.getLightNumber() );
    this._casterStateSet.setAttributeAndModes( this._shadowReceiveAttribute, StateAttribute.ON | StateAttribute.OVERRIDE );

    // default name, overridable with shadow settings
    this._shadowCastShaderGeneratorName = 'ShadowCast';


<commit_msg>[#DEV-6348] Fixes wrong shadow blend/depth state<commit_after>'use strict';
var Camera = require( 'osg/Camera' );
var BlendFunc = require( 'osg/BlendFunc' );
var ComputeBoundsVisitor = require( 'osg/ComputeBoundsVisitor' );
var Depth = require( 'osg/Depth' );
var FrameBufferObject = require( 'osg/FrameBufferObject' );
var Matrix = require( 'osg/Matrix' );
var Notify = require( 'osg/Notify' );
var StateAttribute = require( 'osg/StateAttribute' );
var StateSet = require( 'osg/StateSet' );
var Texture = require( 'osg/Texture' );
var Transform = require( 'osg/Transform' );
var Uniform = require( 'osg/Uniform' );
var MACROUTILS = require( 'osg/Utils' );
var Vec3 = require( 'osg/Vec3' );
var Vec4 = require( 'osg/Vec4' );
var Viewport = require( 'osg/Viewport' );
var WebGLCaps = require( 'osg/WebGLCaps' );
var ShadowReceiveAttribute = require( 'osgShadow/ShadowReceiveAttribute' );
var ShadowCasterVisitor = require( 'osgShadow/ShadowCasterVisitor' );
var ShadowFrustumIntersection = require( 'osgShadow/ShadowFrustumIntersection' );
var ShadowCastAttribute = require( 'osgShadow/ShadowCastAttribute' );
var ShadowTechnique = require( 'osgShadow/ShadowTechnique' );
var ShadowTexture = require( 'osgShadow/ShadowTexture' );


// Custom camera cull callback
// we customize it just to avoid to add extra 'virtual' function
// on the shadowTecnique class
var CameraCullCallback = function ( shadowTechnique ) {
    this._shadowTechnique = shadowTechnique;
};

CameraCullCallback.prototype = {
    cull: function ( node, nv ) {

        // see ShadowTechnique CameraCullCallback
        this._shadowTechnique.getShadowedScene().nodeTraverse( nv );



        var cs = nv.getCurrentCullingSet();
        if ( nv.getComputeNearFar() === true && nv.getComputedFar() >= nv.getComputedNear() ) {
            var m = nv.getCurrentProjectionMatrix();

            //Matrix.clampProjectionMatrix( m, nv.getComputedNear(), nv.getComputedFar(), nv.getNearFarRatio() );
            this._shadowTechnique.getDepthRange()[ 0 ] = nv.getComputedNear();
            this._shadowTechnique.getDepthRange()[ 1 ] = nv.getComputedFar();

            Matrix.getFrustumPlanes( m, nv.getCurrentModelViewMatrix(), cs.getFrustum().getPlanes(), false );
            // TODO: no far no near.
            // should check if we have them
            // should add at least a near 0 clip if not
            cs.getFrustum().setupMask( 6 );
        }

        this._shadowTechnique.setLightFrustum( cs.getFrustum() );
        return false;
    }
};

/**
 *  ShadowMap provides an implementation of shadow textures.
 *  @class ShadowMap
 */
var ShadowMap = function ( settings ) {
    ShadowTechnique.call( this );

    this._projectionMatrix = Matrix.create();
    this._viewMatrix = Matrix.create();

    this._lightUp = Vec3.createAndSet( 0.0, 0.0, 1.0 );

    this._light = settings.light;

    // data
    this._cameraShadow = new Camera();
    this._cameraShadow.setCullCallback( new CameraCullCallback( this ) );
    this._cameraShadow.setRenderOrder( Camera.PRE_RENDER, 0 );
    this._cameraShadow.setReferenceFrame( Transform.ABSOLUTE_RF );
    this._cameraShadow.setClearColor( Vec4.createAndSet( 1.0, 1.0, 1.0, 1.0 ) );

    this._texture = new ShadowTexture();
    this._textureUnitBase = 4;
    this._textureUnit = this._textureUnitBase;

    // see shadowSettings.js header for param explanations
    this._textureMagFilter = undefined;
    this._textureMinFilter = undefined;
    this._textureSize = 256;

    this._receivingStateset = undefined;

    this._casterStateSet = new StateSet();
    this._casterStateSet.addUniform( Uniform.createFloat1( 0, 'exponent0' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 0, 'exponent1' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 0.005, 'bias' ) );
    this._casterStateSet.addUniform( Uniform.createFloat1( 1.0 / this._textureSize, 'texelSize' ) );
    this._casterStateSet.addUniform( Uniform.createFloat2( [ this._textureSize, this._textureSize ], 'RenderSize' ) );

    // make sure no unintended blend happens
    // if casting semi-transparent (alphablend material with full opaque pixels) shadow
    this._casterStateSet.setAttributeAndModes( new Depth( Depth.LESS ), StateAttribute.ON | StateAttribute.OVERRIDE );
    this._casterStateSet.setAttributeAndModes( new BlendFunc(), StateAttribute.ON | StateAttribute.OVERRIDE );

    this._shadowReceiveAttribute = new ShadowReceiveAttribute( this._light.getLightNumber() );
    this._casterStateSet.setAttributeAndModes( this._shadowReceiveAttribute, StateAttribute.ON | StateAttribute.OVERRIDE );

    // default name, overridable with shadow settings
    this._shadowCastShaderGeneratorName = 'ShadowCast';


{'fraction_non_alphanumeric': 0.11909536541889483, 'fraction_numerical': 0.010249554367201427, 'mean_word_length': 3.8788043478260867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5425258', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2647, 'n_words': 604}