Shader Nodes implementation :
Sample Shader nodes and test material definition git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10434 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
0360f9a44a
commit
241cbce7e6
95
engine/src/core-data/Common/MatDefs/Misc/UnshadedNodes.j3md
Normal file
95
engine/src/core-data/Common/MatDefs/Misc/UnshadedNodes.j3md
Normal file
@ -0,0 +1,95 @@
|
||||
MaterialDef UnshadedNodes {
|
||||
|
||||
MaterialParameters {
|
||||
Texture2D ColorMap
|
||||
Texture2D LightMap
|
||||
Color Color (Color)
|
||||
Boolean VertexColor (UseVertexColor)
|
||||
Boolean SeparateTexCoord
|
||||
|
||||
//FOG parameters
|
||||
Boolean UseFog
|
||||
Float FogDensity :1
|
||||
Color FogColor : 1 1 1 1
|
||||
}
|
||||
|
||||
Technique {
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
//used for fog
|
||||
WorldViewMatrix
|
||||
}
|
||||
|
||||
VertexShaderNodes{
|
||||
ShaderNode FogFactor{
|
||||
Definition: FogFactor : Common/MatDefs/ShaderNodes/Fog/Fog.j3sn
|
||||
Condition: UseFog
|
||||
InputMapping{
|
||||
modelViewMatrix = WorldParam.WorldViewMatrix
|
||||
modelPosition = Global.position
|
||||
fogDensity = MatParam.FogDensity
|
||||
}
|
||||
}
|
||||
ShaderNode UnshadedVert{
|
||||
Definition: CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
|
||||
InputMapping{
|
||||
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
|
||||
modelPosition = Global.position.xyz
|
||||
texCoord1 = Attr.inTexCoord: ColorMap || (LightMap && !SeparateTexCoord)
|
||||
texCoord2 = Attr.inTexCoord2: SeparateTexCoord
|
||||
vertColor = Attr.inColor: VertexColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.position = projPosition
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
FragmentShaderNodes{
|
||||
ShaderNode UnshadedFrag{
|
||||
Definition: Unshaded : Common/MatDefs/ShaderNodes/Common/Unshaded.j3sn
|
||||
InputMapping{
|
||||
texCoord = UnshadedVert.texCoord1: ColorMap
|
||||
vertColor = UnshadedVert.vertColor: VertexColor
|
||||
matColor = MatParam.Color: Color
|
||||
colorMap = MatParam.ColorMap: ColorMap
|
||||
color = Global.outColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.outColor = color
|
||||
}
|
||||
}
|
||||
ShaderNode LightMap{
|
||||
Definition: LightMapping : Common/MatDefs/ShaderNodes/LightMapping/LightMapping.j3sn
|
||||
Condition: LightMap
|
||||
InputMapping{
|
||||
texCoord = UnshadedVert.texCoord1: !SeparateTexCoord
|
||||
texCoord = UnshadedVert.texCoord2: SeparateTexCoord
|
||||
lightMap = MatParam.LightMap
|
||||
color = Global.outColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.outColor = color
|
||||
}
|
||||
}
|
||||
|
||||
ShaderNode FogOutput{
|
||||
Definition: FogOutput : Common/MatDefs/ShaderNodes/Fog/Fog.j3sn
|
||||
Condition: UseFog
|
||||
InputMapping{
|
||||
fogFactor = FogFactor.fogFactor
|
||||
color = Global.outColor
|
||||
fogColor = MatParam.FogColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.outColor = color
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition AttributeToVarying{
|
||||
Type : Vertex
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Basic/null.vert
|
||||
Documentation{
|
||||
This node can pass an attribute value to a varying value.
|
||||
@input floatVariable a float attribute
|
||||
@input vec2Variable a vec2 attribute
|
||||
@input vec3Variable a vec3 attribute
|
||||
@input vec4Variable a vec4 attribute
|
||||
@output floatVariable a float varying
|
||||
@output vec2Variable a vec2 varying
|
||||
@output vec3Variable a vec3 varying
|
||||
@output vec4Variable a vec4 varying
|
||||
}
|
||||
Input {
|
||||
float floatVariable
|
||||
vec2 vec2Variable
|
||||
vec3 vec3Variable
|
||||
vec4 vec4Variable
|
||||
}
|
||||
Output {
|
||||
float floatVariable
|
||||
vec2 vec2Variable
|
||||
vec3 vec3Variable
|
||||
vec4 vec4Variable
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition ColorMix {
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Basic/colorMix.frag
|
||||
Documentation{
|
||||
mixes two colors according to a mix factor
|
||||
@input color1 the first color to mix
|
||||
@input color2 the second color to mix
|
||||
@input factor the mix factor (from 0.0 to 1.0) fpr more information see the gsls mix function
|
||||
@output outColor the mixed color
|
||||
}
|
||||
Input {
|
||||
vec4 color1
|
||||
vec4 color2
|
||||
float factor
|
||||
}
|
||||
Output {
|
||||
vec4 outColor
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition ColorMult {
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Basic/colorMult.frag
|
||||
Documentation{
|
||||
Multiplies two colors
|
||||
@input color1 the first color
|
||||
@input color2 the second color
|
||||
@output outColor the resulting color
|
||||
}
|
||||
Input {
|
||||
vec4 color1
|
||||
vec4 color2
|
||||
}
|
||||
Output {
|
||||
vec4 outColor
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition TextureFetch {
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Basic/texture.frag
|
||||
Documentation{
|
||||
Fetches a color value in the given texture acording to given texture coordinates
|
||||
@input texture the texture to read
|
||||
@input texCoord the texture coordinates
|
||||
@output outColor the fetched color
|
||||
}
|
||||
Input {
|
||||
sampler2D texture
|
||||
vec2 texCoord
|
||||
}
|
||||
Output {
|
||||
vec4 outColor
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition TransformPosition{
|
||||
Type: Vertex
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Basic/transformPosition.vert
|
||||
Documentation {
|
||||
This node transforms a position according to the given matrix
|
||||
@input inputPosition the position to transform
|
||||
@input transformsMatrix the matrix to use for this transformation
|
||||
@output outPosition the transformed position
|
||||
}
|
||||
Input {
|
||||
vec3 inputPosition
|
||||
mat4 transformsMatrix
|
||||
}
|
||||
Output {
|
||||
vec4 outPosition
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
outColor = mix(color1,color2,factor);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
outColor = color1 * color2;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
outColor = texture2D(texture,texCoord);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
outPosition = transformsMatrix * vec4(inputPosition, 1.0);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
ShaderNodesDefinitions {
|
||||
ShaderNodeDefinition CommonVert {
|
||||
Type: Vertex
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Common/commonVert.vert
|
||||
Documentation {
|
||||
This Node is responsible for computing vertex position in projection space.
|
||||
It also can pass texture coordinates 1 & 2, and vertexColor to the frgment shader as varying (or inputs for glsl >=1.3)
|
||||
@input modelPosition the vertex position in model space (usually assigned with Attr.inPosition or Global.position)
|
||||
@input worldViewProjectionMatrix the World View Projection Matrix transforms model space to projection space.
|
||||
@input texCoord1 The first texture coordinates of the vertex (usually assigned with Attr.inTexCoord)
|
||||
@input texCoord2 The second texture coordinates of the vertex (usually assigned with Attr.inTexCoord2)
|
||||
@input vertColor The color of the vertex (usually assigned with Attr.inColor)
|
||||
@output projPosition Position of the vertex in projection space.(usually assigned to Global.position)
|
||||
@output vec2 texCoord1 The first texture coordinates of the vertex (output as a varying)
|
||||
@output vec2 texCoord2 The second texture coordinates of the vertex (output as a varying)
|
||||
@output vec4 vertColor The color of the vertex (output as a varying)
|
||||
}
|
||||
Input{
|
||||
vec3 modelPosition
|
||||
mat4 worldViewProjectionMatrix
|
||||
vec2 texCoord1
|
||||
vec2 texCoord2
|
||||
vec4 vertColor
|
||||
}
|
||||
Output{
|
||||
vec4 projPosition
|
||||
vec2 texCoord1
|
||||
vec2 texCoord2
|
||||
vec4 vertColor
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition Unshaded{
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Common/unshaded.frag
|
||||
Documentation {
|
||||
This Node is responsible for outputing the unshaded color of a fragment.
|
||||
It can support texture mapping, an arbitrary input color and a vertex color
|
||||
(all resulting colors will be multiplied)
|
||||
@input texCoord the texture coordinates to use for texture mapping
|
||||
@input vertColor the vertex color (often comming from a varrying)
|
||||
@input matColor the material color (often comming from a material parameter)
|
||||
@input colorMap the texture to use for texture mapping
|
||||
@input color the color this node contribution will be multiplied to
|
||||
@output outColor the color of the pixel (usually assigned to Global.color)
|
||||
}
|
||||
Input{
|
||||
vec2 texCoord
|
||||
vec4 vertColor
|
||||
vec4 matColor
|
||||
sampler2D colorMap
|
||||
vec4 color
|
||||
}
|
||||
Output{
|
||||
vec4 color
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
projPosition = worldViewProjectionMatrix * vec4(modelPosition, 1.0);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
void main(){
|
||||
#ifdef colorMap
|
||||
color *= texture2D(colorMap, texCoord);
|
||||
#endif
|
||||
|
||||
#ifdef vertColor
|
||||
color *= vertColor;
|
||||
#endif
|
||||
|
||||
#ifdef matColor
|
||||
color *= matColor;
|
||||
#endif
|
||||
|
||||
}
|
46
engine/src/core-data/Common/MatDefs/ShaderNodes/Fog/Fog.j3sn
Normal file
46
engine/src/core-data/Common/MatDefs/ShaderNodes/Fog/Fog.j3sn
Normal file
@ -0,0 +1,46 @@
|
||||
ShaderNodesDefinitions {
|
||||
ShaderNodeDefinition FogFactor{
|
||||
Type: Vertex
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Fog/fogFactor.vert
|
||||
Documentation {
|
||||
This Node is responsible for computing the fog factor of a vertex in the vertex shader.
|
||||
It computes the fogFactor according to view space z (distance from cam to vertex) and a fogDensity parameter.
|
||||
This Node should be used with a FogOutput for the fragment shader to effectively output the fog color.
|
||||
@input modelPostion the vertex position in model space
|
||||
@input modelViewMatrix the model view matrix responsible to transform a vertex position from model space to view space.
|
||||
@input fogDensity the fog density (usually assigned with a material parameter)
|
||||
@output fogFactor the fog factor of the vertex output as a varying
|
||||
}
|
||||
Input{
|
||||
vec4 modelPosition
|
||||
// Note here that the fog vertex shader will compute position of the vertex in view space
|
||||
// This is a pretty common operation that could be used elsewhere.
|
||||
// IMO I would split this in 2 ShaderNodes, so that the view space pos could be reused.
|
||||
mat4 modelViewMatrix
|
||||
float fogDensity
|
||||
}
|
||||
Output{
|
||||
float fogFactor
|
||||
}
|
||||
}
|
||||
ShaderNodeDefinition FogOutput{
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Fog/fogOutput.frag
|
||||
Documentation {
|
||||
This Node is responsible for multiplying a fog contribution to a color according to a fogColor and a fogFactor.
|
||||
This node should be used with a FogFactor node that will be responsible to compute the fogFactor in the vertex shader.
|
||||
@input fogFactor the previously computed fog factor
|
||||
@input fogColor the fog color
|
||||
@input color the color the fog contribution will be multiplied to.
|
||||
@output color the color with fog contribution (usually assigned to Global.color)
|
||||
}
|
||||
Input{
|
||||
float fogFactor
|
||||
vec4 fogColor
|
||||
vec4 color
|
||||
}
|
||||
Output{
|
||||
vec4 color
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
const float LOG2 = 1.442695;
|
||||
void main(){
|
||||
vec4 viewSpacePos = modelViewMatrix * modelPosition;
|
||||
fogFactor = exp2(-fogDensity * fogDensity * viewSpacePos.z * viewSpacePos.z * LOG2 );
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
color = mix(fogColor, color, fogFactor);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
ShaderNodeDefinitions{
|
||||
ShaderNodeDefinition LightMapping{
|
||||
Type: Fragment
|
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/LightMapping/lightMap.frag
|
||||
Documentation {
|
||||
This Node is responsible for multiplying a light mapping contribution to a given color.
|
||||
@input texCoord the texture coordinates to use for light mapping
|
||||
@input lightMap the texture to use for light mapping
|
||||
@input color the color the lightmap color will be multiplied to
|
||||
@output color the resulting color
|
||||
}
|
||||
Input{
|
||||
vec2 texCoord
|
||||
sampler2D lightMap
|
||||
vec4 color
|
||||
}
|
||||
Output{
|
||||
vec4 color
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
void main(){
|
||||
color *= texture2D(lightMap, texCoord);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user