-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ab95b8
commit 0a60032
Showing
5 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/GLSL/SpecularGlossinessFS.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,35 @@ | ||
precision highp float; | ||
|
||
uniform sampler2D uTexDiffuse; | ||
uniform sampler2D uTexNormal; | ||
uniform sampler2D uTexSpecGloss; | ||
|
||
in vec2 vTexCoord0; | ||
in vec3 vWorldPosition; | ||
in vec3 vWorldNormal; | ||
in vec3 vWorldTangent; | ||
in vec3 vWorldBinormal; | ||
in float vTangentW; | ||
|
||
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(uTexDiffuse, vTexCoord0.xy).xyz; | ||
vec3 normalMap = texture(uTexNormal, vTexCoord0.xy).xyz; | ||
vec3 sgMap = texture(uTexSpecGloss, vTexCoord0.xy).xyz; | ||
|
||
mat3 rotation = mat3(vWorldTangent, vWorldBinormal, vWorldNormal); | ||
vec3 localCoords = normalMap * 2.0 - vec3(1.0); | ||
localCoords.y = localCoords.y * vTangentW; | ||
vec3 n = rotation * localCoords; | ||
n = normalize(n); | ||
|
||
Diffuse = vec4(baseMap, 1.0); | ||
Position = vec4(vWorldPosition, 1.0); | ||
Normal = vec4(n, 1.0); | ||
SG = vec4(sgMap, 1.0); | ||
} |
36 changes: 36 additions & 0 deletions
36
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/GLSL/SpecularGlossinessVS.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,36 @@ | ||
in vec4 inPosition; | ||
in vec4 inColor; | ||
in vec3 inNormal; | ||
in vec2 inTexCoord0; | ||
in vec3 inTangent; | ||
in vec3 inBinormal; | ||
in vec2 inTangentW; | ||
|
||
uniform mat4 uMvpMatrix; | ||
uniform mat4 uWorldMatrix; | ||
uniform vec4 uUVScale; | ||
|
||
out vec3 vWorldNormal; | ||
out vec3 vWorldPosition; | ||
out vec3 vWorldTangent; | ||
out vec3 vWorldBinormal; | ||
|
||
out vec2 vTexCoord0; | ||
out float vTangentW; | ||
|
||
void main(void) | ||
{ | ||
vWorldPosition = (uWorldMatrix*inPosition).xyz; | ||
|
||
vec4 worldNormal = uWorldMatrix * vec4(inNormal,0.0); | ||
vec4 worldTangent = uWorldMatrix * vec4(inTangent,0.0); | ||
|
||
vWorldNormal = normalize(worldNormal.xyz); | ||
vWorldTangent = normalize(worldTangent.xyz); | ||
vWorldBinormal = cross(vWorldNormal.xyz, vWorldTangent.xyz); | ||
|
||
vTexCoord0 = inTexCoord0 * uUVScale.xy + uUVScale.zw; | ||
vTangentW = inTangentW.x; | ||
|
||
gl_Position = uMvpMatrix * inPosition; | ||
} |
50 changes: 50 additions & 0 deletions
50
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/HLSL/SpecularGlossinessFS.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 @@ | ||
Texture2D uTexDiffuse : register(t0); | ||
SamplerState uTexDiffuseSampler : register(s0); | ||
|
||
Texture2D uTexNormal : register(t1); | ||
SamplerState uTexNormalSampler : register(s1); | ||
|
||
Texture2D uTexSpecGloss : register(t2); | ||
SamplerState uTexSpecGlossSampler : register(s2); | ||
|
||
struct PS_INPUT | ||
{ | ||
float4 pos : SV_POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
float3 worldPosition: WORLDPOSITION; | ||
float3 worldNormal: WORLDNORMAL; | ||
float3 worldTangent: WORLDTANGENT; | ||
float3 worldBinormal: WORLDBINORMAL; | ||
float tangentw : TANGENTW; | ||
}; | ||
|
||
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 = uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0).xyz; | ||
float3 normalMap = uTexNormal.Sample(uTexNormalSampler, input.tex0).xyz; | ||
float3 sgMap = uTexSpecGloss.Sample(uTexSpecGlossSampler, 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); | ||
|
||
output.Diffuse = float4(baseMap, 1.0); | ||
output.Position = float4(input.worldPosition, 1.0); | ||
output.Normal = float4(n, 1.0); | ||
output.SG = float4(sgMap, 1.0); | ||
|
||
return output; | ||
} |
47 changes: 47 additions & 0 deletions
47
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/HLSL/SpecularGlossinessVS.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,47 @@ | ||
struct VS_INPUT | ||
{ | ||
float4 pos: POSITION; | ||
float3 norm: NORMAL; | ||
float4 color: COLOR; | ||
float2 tex0: TEXCOORD0; | ||
float3 tangent: TANGENT; | ||
float3 binormal: BINORMAL; | ||
float2 tangentw: TANGENTW; | ||
}; | ||
|
||
struct VS_OUTPUT | ||
{ | ||
float4 pos : SV_POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
float3 worldPosition: WORLDPOSITION; | ||
float3 worldNormal: WORLDNORMAL; | ||
float3 worldTangent: WORLDTANGENT; | ||
float3 worldBinormal: WORLDBINORMAL; | ||
float tangentw : TANGENTW; | ||
}; | ||
|
||
cbuffer cbPerObject | ||
{ | ||
float4x4 uMvpMatrix; | ||
float4x4 uWorldMatrix; | ||
float4 uUVScale; | ||
}; | ||
|
||
VS_OUTPUT main(VS_INPUT input) | ||
{ | ||
VS_OUTPUT output; | ||
output.pos = mul(input.pos, uMvpMatrix); | ||
output.tex0 = input.tex0 * uUVScale.xy + uUVScale.zw; | ||
output.tangentw = input.tangentw.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); | ||
|
||
output.worldPosition = worldPos.xyz; | ||
output.worldNormal = normalize(worldNormal.xyz); | ||
output.worldTangent = normalize(worldTangent.xyz); | ||
output.worldBinormal= normalize(cross(worldNormal.xyz, worldTangent.xyz)); | ||
|
||
return output; | ||
} |
25 changes: 25 additions & 0 deletions
25
Assets/BuiltIn/Shader/SpecularGlossiness/Deferred/SpecularGlossiness.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,25 @@ | ||
<shaderConfig name="SpecularGlossiness" baseShader="SOLID" deferred="true"> | ||
<uniforms> | ||
<vs> | ||
<uniform name="uMvpMatrix" type="WORLD_VIEW_PROJECTION" value="0" float="16" matrix="true"/> | ||
<uniform name="uWorldMatrix" type="WORLD" value="0" float="16" matrix="true"/> | ||
<uniform name="uUVScale" type="NODE_PARAM" valueIndex="0" value="1.0,1.0,0.0,0.0" float="4"/> | ||
</vs> | ||
<fs> | ||
<uniform name="uTexDiffuse" type="DEFAULT_VALUE" value="0" float="1" directX="false"/> | ||
<uniform name="uTexNormal" type="DEFAULT_VALUE" value="1" float="1" directX="false"/> | ||
<uniform name="uTexSpecGloss" type="DEFAULT_VALUE" value="2" float="1" directX="false"/> | ||
</fs> | ||
</uniforms> | ||
<resources> | ||
</resources> | ||
<customUI> | ||
<ui control="UIGroup" name="Texture"> | ||
<ui control="UITexture" name="uTexDiffuse" autoReplace="_diff."/> | ||
<ui control="UITexture" name="uTexNormal" autoReplace="_norm.;_ddn.;_n."/> | ||
<ui control="UITexture" name="uTexSpecGloss" autoReplace="_spec.;_s."/> | ||
</ui> | ||
</customUI> | ||
<shader type="GLSL" vs="GLSL/SpecularGlossinessVS.glsl" fs="GLSL/SpecularGlossinessFS.glsl"/> | ||
<shader type="HLSL" vs="HLSL/SpecularGlossinessVS.hlsl" fs="HLSL/SpecularGlossinessFS.hlsl"/> | ||
</shaderConfig> |