Projection Layer – DayZ

From Bohemia Interactive Community
Revision as of 16:37, 24 September 2024 by ImpulZ (talk | contribs) (Created page with "{{TOC|side}} == Motivation and technical design == frameless|alt=Results of the projection layer displaying snow on top of rocks|Results of the projection layer displaying snow on top of rocks A projection layer can be used for easily adding snow or moss or any other material directionally to an asset. Examples are Sakhal rocks and trees as well as few selected structures such as wooden bridges across the map. A projection layer has be...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Motivation and technical design

Results of the projection layer displaying snow on top of rocks

A projection layer can be used for easily adding snow or moss or any other material directionally to an asset. Examples are Sakhal rocks and trees as well as few selected structures such as wooden bridges across the map.

A projection layer has been added as an option for Supershader, TreeAdvTrunk and Multishader.

  • The projected texture set (diffuse, specular and normal map) is...
  • blended with the material based on surface shading normal (so taking normal map of the material into account),...
  • being compared with chosen global space vector...
  • and with a falloff based on deviation from this vector.

This means we can pick projected textures, we can change the projection angle and we have control over falloff of the projection. The projection will be corrected for object rotations and deformations.

Usage

Common values:

Example values in .rvmat

degAngleTopProjectionStart=65;    //angle in degrees where the projection blend begins, below this angle the material is unaffected.  0 flat surface, 90 orthogonal to ground when projectionvector is vertically up
degAngleTopProjectionEnd=85;      //angle in degrees where the projection blend ends, above this angle the material is fully hidden by projected texture. 0 flat surface, 90 orthogonal to ground

projectionVector[]={0,1,0.05};    //Optional. vector of "up" direction for the projection. This allows to project at an angle different than vertical. Format is XYZ where Y is vertical direction. Here slight bias was added to reflect dominant wind direction.

When using TreeAdvTrunk

degAngleTopProjectionStart=65;    //0 flat surface, 90 orthogonal to ground
degAngleTopProjectionEnd=85;
treeAllowProjectionLayer=1;
projectionVector[]={0,1,0.05};
PixelShaderID="TreeAdvTrunk";
VertexShaderID="TreeAdvTrunk";
  • treeAllowProjectionLayer=1;  - switch enabling the projection, set to 1

Additional stages were added for the projected textures as stages 4-6:

class Stage4
{
        texture="#(argb,8,8,3)color(1,1,0.3,1,smdi)";
    uvSource="tex";
    class uvTransform
    {
        aside[]={1,0,0};
        up[]={0,1,0};
        dir[]={0,0,1};
        pos[]={0,0,0};
    };
};
class Stage5
{
    texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_ca.tga";
    uvSource="tex";
    class uvTransform
    {
        aside[]={1,0,0};
        up[]={0,1,0};
        dir[]={0,0,1};
        pos[]={0,0,0};
    };

};
class Stage6
{
    texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_nohq.tga";

    uvSource="tex";
    class uvTransform
    {
        aside[]={1,0,0};
        up[]={0,1,0};
        dir[]={0,0,1};
        pos[]={0,0,0};
    };              

};

/

//plantWind[]={0.01,0.05,0.95,0.50};
plantWind[] = { 0.01, 0.10, 0.95, 0.50 };
ambient[]={1,1,1,1};
diffuse[]={0.2,0.15,0.1,1};
forcedDiffuse[]={0,0,0,0};
emmisive[]={0,0,0,1};
specular[]={0,0,0,0};
specularPower=50;
degAngleTopProjectionStart=65;	//0 flat surface, 90 orthogonal to ground
degAngleTopProjectionEnd=85;
treeAllowProjectionLayer=1;
projectionVector[]={0,1,0.05};
PixelShaderID="TreeAdvTrunk";
VertexShaderID="TreeAdvTrunk";
class Stage1
{
	//texture="#(argb,8,8,3)color(0,0,0,1,CO)";
	texture="DZ\plants_bliss\Tree\Data\bark_Betula_pendula_NOHQ.tga";
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class Stage2
{
	texture="#(argb,8,8,3)color(0.5,0.5,0.5,1,MC)";
	uvSource="tex1";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
treeColorization[]={-0.3,-10,20,0};
class Stage3
{
	texture="DZ\plants\tree\Data\t_PiceaAbies_trunk_dxt5.tga";
	uvSource="WorldPos";
	class uvTransform
	{
		aside[]={256,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class Stage4
{
		texture="#(argb,8,8,3)color(1,1,0.3,1,smdi)";
	//texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_ca.tga";
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class Stage5
{
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_ca.tga";
	//texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_nohq.tga";
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};

};
class Stage6
{
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_2_nohq.tga";

	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};              

};

/

↑ Back to spoiler's top

When using SuperShader

'''superAllowProjectionLayer'''=1;
degAngleTopProjectionStart=50;    //0 flat surface, 90 orthogonal to ground, where projection start
degAngleTopProjectionEnd=60;     //where projection end
PixelShaderID="Super";
VertexShaderID="Super";

The material needs to be written with TexGen classes outside of the stages.

The material needs to be written with TexGen classes outside of the stages.

class TexGen0
{
    uvSource="tex";
    class uvTransform
    {
        aside[]={1,0,0};
        up[]={0,1,0};
        dir[]={0,0,1};
        pos[]={0,0,0};
    };
};
class TexGen1
{
    uvSource="tex";
    class uvTransform
    {
        aside[]={10,0,0};
        up[]={0,10,0};
        dir[]={0,0,1};              
        pos[]={0,0,0};
    };
};

Additional stages were added for the projected textures as stages 10-12:

    class Stage10 //_co or _ca.  if not present, topdown projection is disable (default for material)
    {
        texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_co.tga";
        texGen="1";
    };
    class Stage11
    {
        texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_nohq.tga";
        texGen="1";
    };
    class Stage12
    {
        texture="#(argb,8,8,3)color(0,0,1,1,SMDI)";
        texGen="1";
    };

        stage13 = AS map

ambient[]={1,1,1,1};
diffuse[]={1,1,1,1};
forcedDiffuse[]={0,0,0,0};
emmisive[]={0,0,0,1};
specular[]={0.25,0.25,0.25,0};
specularPower=10;
superAllowProjectionLayer=1;
degAngleTopProjectionStart=50;	//0 flat surface, 90 orthogonal to ground, where projection start
degAngleTopProjectionEnd=60; //where projection end
PixelShaderID="Super";
VertexShaderID="Super";

class TexGen0
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen1
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={10,0,0};
		up[]={0,10,0};
		dir[]={0,0,1};              
		pos[]={0,0,0};
	};
};
class Stage0
{
	texture="dz\rocks_bliss\data\RM_boulder5_CO.tga";
	texGen="0";
};
class Stage1
{
	texture="DZ\Rocks_Bliss\Data\RM_boulder5_NOHQ.tga";
	texGen="0";
};
class Stage2
{
	texture="DZ\Rocks_Bliss\Data\RM_boulder5_DT.tga";
	texGen="0";
};
class Stage3
{
	texture="#(argb,8,8,3)color(0,0,0,0,MC)";
	texGen="0";
};
class Stage4
{
	texture="DZ\Rocks_Bliss\Data\RM_boulder5_AS.tga";
	texGen="0";
};
class Stage5
{
	texture="DZ\Rocks_Bliss\Data\RM_boulder5_SMDI.tga";
	texGen="0";
};
class Stage6
{
	texture="#(ai,32,128,1)fresnel(0.14,0.17)";
	texGen="0";
};
class Stage7
{
	texture="DZ\data\data\env_land_co.tga";
	texGen="0";
};
class Stage10
{
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_co.tga";
	texGen="1";
};
class Stage11
{
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_nohq.tga";
	texGen="1";
};
class Stage12
{
	texture="#(argb,8,8,3)color(0,0,1,1,SMDI)";
	texGen="1";
};
↑ Back to spoiler's top

When using MultiShader

multiTopProjectionLayer = 3;        // layer of multi material which will be projected down, -1 = no projection (0 layer can't be used as it's default everywhere)
degAngleTopProjectionStart = 50;    // 0 flat surface, 90 orthogonal to ground (start of blend according surface normal)
degAngleTopProjectionEnd = 60;        // 0 flat surface, 90 orthogonal to ground (end of blend according surface normal)
multiTopProjectionBlend = 0;        // 1  = blend with also the original mask, 0 = only top down projection, ignore MASK
multiTopProjectionLayerNormal = -1;    // <0, 3> , -1 use geometry normal
  • select which of your four materials will become the projected layer with multiTopProjectionLayer, in this example we use 3 i.e. Blue MASK layer
  • use multiTopProjectionBlend to specify if original layer mask will be used as well
  • if the color map of a top down projected layer contains alpha channel (_CA name postfix) the alpha channel is also applied to that mask. This will be most useful for projecting moss

Alpha channel is applied to projection

  • one of the normal maps can be used while blending adding extra details to the snow placement. With parameter multiTopProjectionLayerNormal, select a layer to be used by using a value of 0-3 or select -1 to use geometry normal without any normal maps applied.

projection layer 16.jpg projection layer 15.jpg projection layer 14.jpg

Examples:

multiTopProjectionBlend = 0;        // 1  = blend with also the original mask, 0 = only top down projection, ignore MASK
multiTopProjectionLayerNormal = -1;    // <0, 3> , -1 use geometry normal

projection layer 18.jpg

multiTopProjectionBlend = 0;        // 1  = blend with also the original mask, 0 = only top down projection, ignore MASK
multiTopProjectionLayerNormal = 1;    // <0, 3> , -1 use geometry normal

projection layer 20.jpg

multiTopProjectionBlend = 1;        // 1  = blend with also the original mask, 0 = only top down projection, ignore MASK
multiTopProjectionLayerNormal = 1;    // <0, 3> , -1 use geometry normal

projection layer 19.jpg

stages examples. Stages from last material (multiTopProjectionLayer = 3) are reused here, stages:

    class Stage3     
    {    
        texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_co.tga";
        texGen="3";
    };

    class Stage8
    {    
        texture="DZ\rocks_sakhal\Data\cliff_rock_sharp_DTSMDI.tga"
        texGen="7";
    };

    class Stage14
    {    
        texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_nohq.tga";
        texGen="3";
    };

ambient[]={1,1,1,1};
diffuse[]={1,1,1,1};
forcedDiffuse[]={0,0,0,0};
emmisive[]={0,0,0,1};
specular[]={0.1,0.1,0.1,0};
specularPower=50;
multiTopProjectionLayer = 3;		// layer of multi material which will be projected down, -1 = no projection (0 layer can't be used as it's default everywhere)
degAngleTopProjectionStart = 50;	// 0 flat surface, 90 orthogonal to ground (start of blend according surface normal)
degAngleTopProjectionEnd = 60;		// 0 flat surface, 90 orthogonal to ground (end of blend according surface normal)
multiTopProjectionBlend = 0;		// 1  = blend with also original mask, 0 = only top down projection
multiTopProjectionLayerNormal = -1;	// <0, 3> , -1 use geometry normal
PixelShaderID="Multi";
VertexShaderID="Multi";
class TexGen0
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen1
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen2
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen3
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen4 
{
	uvSource="tex"; 
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen5
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={150,0,0};
		up[]={0,150,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen6
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class TexGen7
{
	uvSource="tex";
	class uvTransform
	{
		aside[]={1,0,0};
		up[]={0,1,0};
		dir[]={0,0,1};
		pos[]={0,0,0};
	};
};
class Stage0			//Base texture for Multimaterial - same as base in p3d file
{
	texture="DZ\rocks_sakhal\Data\Cliff_stone_small_F_CO.tga";
	texGen="0";
};
class Stage1			//Red channel - base tilable rock
{
	texture="DZ\rocks_sakhal\Data\cliff_rock_CO.tga"; 
	texGen="1";
};
class Stage2			//Green channel texture - green tilable things like moss or grass
	
{	
	texture="DZ\rocks_sakhal\Data\cliff_rock_green_CO.tga"; 
	texGen="2";
};
class Stage3			//Blue channel texture - snow
{	
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_co.tga";
	texGen="3";
};
class Stage4
{
    	texture="DZ\rocks_sakhal\Data\Cliff_stone_small_F_MASK.tga";
	texGen="4";
};
class Stage5
{	
	texture="#(argb,8,8,3)color(0.5,0,0.5,1,DTSMDI)";
	texGen="7";
};
class Stage6
{
	texture="DZ\rocks_sakhal\Data\cliff_rock_DTSMDI.tga";
	texGen="7";
};
class Stage7
{	
	texture="DZ\rocks_sakhal\Data\cliff_rock_green_DTSMDI.tga"
	texGen="7";
};
class Stage8
{	
	texture="DZ\rocks_sakhal\Data\cliff_rock_sharp_DTSMDI.tga"
	texGen="7";
};
class Stage9
{	
	texture="#(argb,8,8,3)color(0,0,0,0,MC)";
	texGen="4";
};
class Stage10
{
	texture="DZ\rocks_sakhal\Data\Cliff_stone_small_F_AS.tga";
	texGen="4";
};
class Stage11
{
	texture="DZ\rocks_sakhal\Data\Cliff_stone_small_F_NOHQ.tga";
	texGen="0";
};
class Stage12
{	
	texture="DZ\rocks_sakhal\Data\cliff_rock_NOHQ.tga";
	texGen="1";
};
class Stage13
{	
	texture="DZ\rocks_sakhal\Data\cliff_rock_green_NOHQ.tga";
	texGen="2";
};
class Stage14
{	
	texture="DZ\surfaces_sakhal\data\objects\sakhal_snow_nohq.tga";
	texGen="3";
};
↑ Back to spoiler's top