-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#150 Add MetallicRoughness instancing shader
- Loading branch information
1 parent
3016e93
commit 12f5028
Showing
16 changed files
with
486 additions
and
15 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/GLSL/MetallicRoughnessFSInstancing.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// File Generated by Assets/BuildShader.py - source: [MetallicRoughnessFS.glsl : INSTANCING] | ||
precision highp float; | ||
uniform sampler2D uTexAlbedo; | ||
uniform sampler2D uTexNormal; | ||
uniform sampler2D uTexRoughMetal; | ||
in vec2 vTexCoord0; | ||
in vec4 vWorldPosition; | ||
in vec3 vWorldNormal; | ||
in vec3 vWorldTangent; | ||
in vec3 vWorldBinormal; | ||
in float vTangentW; | ||
uniform vec4 uColor; | ||
layout(location = 0) out vec4 Diffuse; | ||
layout(location = 1) out vec4 Position; | ||
layout(location = 2) out vec4 Normal; | ||
layout(location = 3) out vec4 SG; | ||
void main(void) | ||
{ | ||
vec3 baseMap = texture(uTexAlbedo, vTexCoord0.xy).rgb * uColor.rgb; | ||
vec3 normalMap = texture(uTexNormal, vTexCoord0.xy).xyz; | ||
vec3 rmMap = texture(uTexRoughMetal, vTexCoord0.xy).rgb; | ||
mat3 rotation = mat3(vWorldTangent, vWorldBinormal, vWorldNormal); | ||
vec3 localCoords = normalMap * 2.0 - vec3(1.0, 1.0, 1.0); | ||
localCoords.y = localCoords.y * vTangentW; | ||
vec3 n = rotation * localCoords; | ||
n = normalize(n); | ||
float roughness = rmMap.r; | ||
float metallic = rmMap.g; | ||
vec3 f0 = vec3(0.04); | ||
vec3 diffuseColor = baseMap.rgb * (vec3(1.0) - f0); | ||
diffuseColor *= 1.0 - metallic; | ||
vec3 specularColor = mix(f0, baseMap.rgb, max(roughness, metallic)); | ||
Diffuse = vec4(diffuseColor, 1.0); | ||
Position = vWorldPosition; | ||
Normal = vec4(n, 1.0); | ||
SG = vec4(max(specularColor.r, specularColor.g), 1.0 - roughness, 1.0, 1.0); | ||
} |
32 changes: 32 additions & 0 deletions
32
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/GLSL/SpecularGlossinessVSInstancing.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// File Generated by Assets/BuildShader.py - source: [SpecularGlossinessVS.glsl : INSTANCING] | ||
in vec4 inPosition; | ||
in vec3 inNormal; | ||
in vec4 inColor; | ||
in vec2 inTexCoord0; | ||
in vec3 inTangent; | ||
in vec3 inBinormal; | ||
in vec2 inData; | ||
uniform mat4 uMvpMatrix; | ||
uniform mat4 uWorldMatrix; | ||
uniform mat4 uView; | ||
uniform vec4 uUVScale; | ||
out vec3 vWorldNormal; | ||
out vec4 vWorldPosition; | ||
out vec3 vWorldTangent; | ||
out vec3 vWorldBinormal; | ||
out vec2 vTexCoord0; | ||
out float vTangentW; | ||
void main(void) | ||
{ | ||
vWorldPosition = uWorldMatrix*inPosition; | ||
vec4 sampleFragPos = uView * vWorldPosition; | ||
vWorldPosition.w = sampleFragPos.z; | ||
vec4 worldNormal = uWorldMatrix * vec4(inNormal, 0.0); | ||
vec4 worldTangent = uWorldMatrix * vec4(inTangent, 0.0); | ||
vWorldNormal = normalize(worldNormal.xyz); | ||
vWorldTangent = normalize(worldTangent.xyz); | ||
vWorldBinormal = normalize(cross(vWorldNormal.xyz, vWorldTangent.xyz)); | ||
vTexCoord0 = inTexCoord0 * uUVScale.xy + uUVScale.zw; | ||
vTangentW = inData.x; | ||
gl_Position = uMvpMatrix * inPosition; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/HLSL/MetallicRoughnessFSInstancing.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// File Generated by Assets/BuildShader.py - source: [MetallicRoughnessFS.hlsl : INSTANCING] | ||
Texture2D uTexAlbedo : register(t0); | ||
SamplerState uTexAlbedoSampler : register(s0); | ||
Texture2D uTexNormal : register(t1); | ||
SamplerState uTexNormalSampler : register(s1); | ||
Texture2D uTexRoughMetal : register(t2); | ||
SamplerState uTexRoughMetalSampler : register(s2); | ||
struct PS_INPUT | ||
{ | ||
float4 pos : SV_POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
float4 worldPosition: WORLDPOSITION; | ||
float3 worldNormal: WORLDNORMAL; | ||
float3 worldTangent: WORLDTANGENT; | ||
float3 worldBinormal: WORLDBINORMAL; | ||
float tangentw : TANGENTW; | ||
float4 color: COLOR; | ||
float2 specGloss: SPECGLOSS; | ||
}; | ||
struct PS_OUTPUT | ||
{ | ||
float4 Diffuse: SV_TARGET0; | ||
float4 Position: SV_TARGET1; | ||
float4 Normal: SV_TARGET2; | ||
float4 SG: SV_TARGET3; | ||
}; | ||
PS_OUTPUT main(PS_INPUT input) | ||
{ | ||
PS_OUTPUT output; | ||
float3 baseMap = uTexAlbedo.Sample(uTexAlbedoSampler, input.tex0).rgb; | ||
baseMap *= input.color.rgb; | ||
float3 normalMap = uTexNormal.Sample(uTexNormalSampler, input.tex0).xyz; | ||
float3 rmMap = uTexRoughMetal.Sample(uTexRoughMetalSampler, input.tex0).xyz; | ||
float3x3 rotation = float3x3(input.worldTangent, input.worldBinormal, input.worldNormal); | ||
float3 localCoords = normalMap * 2.0 - float3(1.0, 1.0, 1.0); | ||
localCoords.y *= input.tangentw; | ||
float3 n = mul(localCoords, rotation); | ||
n = normalize(n); | ||
float roughness = rmMap.r; | ||
float metallic = rmMap.g; | ||
float3 f0 = float3(0.04, 0.04, 0.04); | ||
float3 diffuseColor = baseMap.rgb * (float3(1.0, 1.0, 1.0) - f0); | ||
diffuseColor *= (1.0 - metallic); | ||
float3 specularColor = lerp(f0, baseMap.rgb, max(roughness, metallic)); | ||
output.Diffuse = float4(diffuseColor, 1.0); | ||
output.Position = input.worldPosition; | ||
output.Normal = float4(n, 1.0); | ||
output.SG = float4(max(specularColor.r, specularColor.g), 1.0 - roughness, 1.0, 1.0); | ||
return output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/HLSL/SpecularGlossinessVSInstancing.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// File Generated by Assets/BuildShader.py - source: [SpecularGlossinessVS.hlsl : INSTANCING] | ||
struct VS_INPUT | ||
{ | ||
float4 pos: POSITION; | ||
float3 norm: NORMAL; | ||
float4 color: COLOR; | ||
float2 tex0: TEXCOORD0; | ||
float3 tangent: TANGENT; | ||
float3 binormal: BINORMAL; | ||
float2 data: DATA; | ||
float4 uvScale: TEXCOORD1; | ||
float4 uColor: TEXCOORD2; | ||
float2 uSpecGloss: TEXCOORD3; | ||
float3 sh0: TEXCOORD4; | ||
float3 sh1: TEXCOORD5; | ||
float3 sh2: TEXCOORD6; | ||
float3 sh3: TEXCOORD7; | ||
float4x4 worldMatrix: TEXCOORD8; | ||
}; | ||
struct VS_OUTPUT | ||
{ | ||
float4 pos : SV_POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
float4 worldPosition: WORLDPOSITION; | ||
float3 worldNormal: WORLDNORMAL; | ||
float3 worldTangent: WORLDTANGENT; | ||
float3 worldBinormal: WORLDBINORMAL; | ||
float tangentw : TANGENTW; | ||
float4 color: COLOR; | ||
float2 specGloss: SPECGLOSS; | ||
}; | ||
cbuffer cbPerObject | ||
{ | ||
float4x4 uVPMatrix; | ||
float4x4 uView; | ||
}; | ||
VS_OUTPUT main(VS_INPUT input) | ||
{ | ||
VS_OUTPUT output; | ||
output.color = input.uColor; | ||
output.specGloss = input.uSpecGloss; | ||
float4x4 uWorldMatrix = transpose(input.worldMatrix); | ||
float4 uUVScale = input.uvScale; | ||
float4x4 uMvpMatrix = mul(uWorldMatrix, uVPMatrix); | ||
output.pos = mul(input.pos, uMvpMatrix); | ||
output.tex0 = input.tex0 * uUVScale.xy + uUVScale.zw; | ||
output.tangentw = input.data.x; | ||
float4 worldPos = mul(input.pos, uWorldMatrix); | ||
float4 worldNormal = mul(float4(input.norm, 0.0), uWorldMatrix); | ||
float4 worldTangent = mul(float4(input.tangent, 0.0), uWorldMatrix); | ||
float4 sampleFragPos = mul(worldPos, uView); | ||
float sampleDepth = sampleFragPos.z; | ||
output.worldPosition = float4(worldPos.xyz, sampleDepth); | ||
output.worldNormal = normalize(worldNormal.xyz); | ||
output.worldTangent = normalize(worldTangent.xyz); | ||
output.worldBinormal = normalize(cross(worldNormal.xyz, worldTangent.xyz)); | ||
return output; | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/MetallicRoughness.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/MetallicRoughnessInstancing.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<shaderConfig name="MetallicRoughnessInstancing" baseShader="SOLID" deferred="true"> | ||
<uniforms> | ||
<vs> | ||
<uniform name="uVPMatrix" type="VIEW_PROJECTION" value="0" float="16" matrix="true"/> | ||
<uniform name="uView" type="DEFERRED_VIEW" value="0" float="16" matrix="true"/> | ||
</vs> | ||
<fs> | ||
<uniform name="uTexAlbedo" type="DEFAULT_VALUE" value="0" float="1" directX="false"/> | ||
<uniform name="uTexNormal" type="DEFAULT_VALUE" value="1" float="1" directX="false" normal="true"/> | ||
<uniform name="uTexRoughMetal" type="DEFAULT_VALUE" value="2" float="1" directX="false"/> | ||
</fs> | ||
</uniforms> | ||
<resources> | ||
</resources> | ||
<customUI> | ||
</customUI> | ||
<shader type="GLSL" | ||
vs="GLSL/SpecularGlossinessVSInstancing.glsl" | ||
fs="GLSL/MetallicRoughnessFSInstancing.glsl" | ||
vs_source="GLSL/SpecularGlossinessVS.glsl" | ||
fs_source="GLSL/MetallicRoughnessFS.glsl" | ||
define="INSTANCING"/> | ||
<shader type="HLSL" | ||
vs="HLSL/SpecularGlossinessVSInstancing.hlsl" | ||
fs="HLSL/MetallicRoughnessFSInstancing.hlsl" | ||
vs_source="HLSL/SpecularGlossinessVS.hlsl" | ||
fs_source="HLSL/MetallicRoughnessFS.hlsl" | ||
define="INSTANCING"/> | ||
</shaderConfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.