@@ -6,15 +6,7 @@ Variants VERTEX_COLORS, LIT, HALF_LAMBERT, PER_VERTEX_LIGHTING, NORMALMAP, CUTOU
66
77Begin Parameters
88
9- varying vec2 v_texcoord0 : TEXCOORD0 = vec2 (0.0 , 0.0 )
10- varying vec3 v_worldPos : TEXCOORD1
11- varying vec3 v_normal : NORMAL
12- varying vec3 v_lightNormal : TEXCOORD3
13- varying vec4 v_color : COLOR
14- varying float v_instanceID : TEXCOORD2
15- varying vec3 v_tangent : TANGENT
16- varying vec3 v_bitangent : BITANGENT
17-
9+ uniform vec3 viewPosition;
1810uniform texture ambientOcclusionTexture
1911uniform color diffuseColor = #FFFFFFFF
2012uniform texture diffuseTexture = WHITE
@@ -33,93 +25,130 @@ End Parameters
3325Begin Instancing
3426End Instancing
3527
36- Begin Vertex
28+ Begin Common
3729
38- $input a_position, a_texcoord0, a_normal, a_color0, a_tangent, a_bitangent
39- $output v_texcoord0, v_worldPos, v_normal, v_color, v_instanceID, v_tangent, v_bitangent, v_lightNormal
30+ cbuffer Uniforms
31+ {
32+ float3 viewPosition;
33+ Sampler2D ambientOcclusionTexture;
34+ float4 diffuseColor;
35+ Sampler2D diffuseTexture;
36+ Sampler2D displacementTexture;
37+ float4 emissiveColor;
38+ Sampler2D emissiveTexture;
39+ Sampler2D heightTexture;
40+ Sampler2D normalTexture;
41+ float4 specularColor;
42+ Sampler2D specularTexture;
43+ float cutout;
44+ float alphaThreshold;
45+ };
46+
47+ struct VertexOutput
48+ {
49+ float3 position : SV_Position;
50+ float3 worldPosition;
51+ float3 lightNormal;
52+ float2 coords;
53+ float3 normal;
54+ float3 tangent;
55+ float3 bitangent;
56+ float4 color;
57+ uint instanceID;
58+ };
59+
60+ End Common
4061
41- #include "StapleLighting.sh"
62+ Begin Vertex
4263
43- void main()
64+ // TODO: Get slang to handle multiple preprocessor conditions
65+
66+ struct Input
67+ {
68+ float3 position : POSITION;
69+ float2 coords : TEXCOORD0;
70+ float3 normal : NORMAL;
71+ float3 tangent : TANGENT;
72+ float3 bitangent : BITANGENT;
73+ float4 color : COLOR0;
74+ uint instanceID : SV_InstanceID;
75+ };
76+
77+ [shader("vertex")]
78+ VertexOutput VertexMain(Input input)
4479{
45- mat4 model = StapleModelMatrix ;
80+ VertexOutput output ;
4681
47- #ifdef SKINNING
48- model = StapleGetSkinningMatrix(model, a_indices, a_weight);
49- #endif
82+ float4x4 model = world;
5083
51- mat4 projViewWorld = mul(mul(u_proj, u_view ), model);
52- mat4 viewWorld = mul(u_view , model);
84+ float4x4 projectionViewWorld = mul(mul(projection, view ), model);
85+ float4x4 viewWorld = mul(view , model);
5386
54- vec4 v_pos = mul(projViewWorld, vec4 (a_position , 1.0 ));
87+ float4 vertexPosition = mul(projectionViewWorld, float4(input.position , 1.0 ));
5588
56- gl_Position = v_pos ;
89+ output.position = vertexPosition.xyz ;
5790
58- v_worldPos = mul(model, vec4 (a_position , 1.0 )).xyz;
91+ output.worldPosition = mul(model, float4(input.position , 1.0 )).xyz;
5992
60- v_texcoord0 = a_texcoord0;
61- v_normal = a_normal;
62-
63- v_lightNormal = StapleLightNormal(a_normal, model);
64-
65- v_tangent = a_tangent;
66- v_bitangent = a_bitangent;
93+ output.coords = input.coords;
94+ output.normal = input.normal;
95+ output.tangent = input.tangent;
96+ output.bitangent = input.bitangent;
97+ output.lightNormal = StapleLightNormal(input.normal, model);
98+ output.instanceID = input.instanceID;
6799
68- v_instanceID = StapleInstanceID;
100+ // #if LIT && PER_VERTEX_LIGHTING
101+ // output.color = float4x4(diffuseColor.rgb * StapleProcessLights(viewPosition, output.worldPosition, input.normal), diffuseColor.a);
69102
70- #if LIT && PER_VERTEX_LIGHTING
71- v_color = vec4 (diffuseColor.rgb * StapleProcessLights(int (v_instanceID), u_viewPos, v_worldPos, v_normal), diffuseColor.a);
72-
73- #if VERTEX_COLORS
74- v_color = a_color0 * v_color;
75- #endif
76- #else
77- v_color = a_color0;
78- #endif
103+ // #ifdef VERTEX_COLORS
104+ // output.color = input.color * output.color;
105+ // #endif
106+ // #else
107+ output.color = input.color;
108+ // #endif
109+
110+ return output;
79111}
80112End Vertex
81113
82114Begin Fragment
83115
84- $input v_texcoord0, v_worldPos, v_normal, v_color, v_instanceID, v_tangent, v_bitangent, v_lightNormal
85-
86- #include "StapleLighting.sh"
87-
88- void main()
116+ [shader("fragment")]
117+ float4 FragmentMain(VertexOutput input) : SV_Target
89118{
90- #if VERTEX_COLORS || PER_VERTEX_LIGHTING
91- vec4 diffuse = v_color * diffuseColor;
92- #else
93- vec4 diffuse = texture2D ( diffuseTexture, v_texcoord0 ) * diffuseColor;
94- #endif
119+ // #if VERTEX_COLORS || PER_VERTEX_LIGHTING
120+ // float4 diffuse = input.color * diffuseColor;
121+ // #else
122+ float4 diffuse = diffuseTexture.Sample(input.coords ) * diffuseColor;
123+ // #endif
95124
96- #if CUTOUT
125+ #ifdef CUTOUT
97126 if (diffuse.a < alphaThreshold)
98127 {
99128 discard ;
100-
101- return ;
102129 }
103130#endif
104131
105- #if LIT && PER_VERTEX_LIGHTING
106- gl_FragColor = diffuse;
132+ // #if LIT && PER_VERTEX_LIGHTING
133+ return diffuse;
134+ /*
107135#elif LIT
108136
109137#if NORMALMAP
110- mat3 tbn = mtxFromCols (normalize (v_tangent ), normalize (v_bitangent ), normalize (v_normal ));
138+ float3x3 tbn = float3x3 (normalize(input.tangent ), normalize(input.bitangent ), normalize(input.normal ));
111139
112- vec3 normalMapNormal = normalize (texture2D ( normalTexture, v_texcoord0).xyz * 2.0 - 1.0 );
140+ float3 normalMapNormal = normalize(normalTexture.Sample( v_texcoord0).xyz * 2.0 - 1.0);
113141
114- vec3 light = StapleProcessLightsTangent(int (v_instanceID), u_viewPos, v_worldPos , normalMapNormal, tbn);
142+ float3 light = StapleProcessLightsTangent(viewPosition, input.worldPosition , normalMapNormal, tbn);
115143#else
116- vec3 light = StapleProcessLights(int (v_instanceID), u_viewPos, v_worldPos, v_lightNormal );
144+ float3 light = StapleProcessLights(viewPosition, input.world, input.lightNormal );
117145#endif
118146
119- gl_FragColor = vec4 (light, 1 ) * diffuse;
120- #else
121- gl_FragColor = diffuse;
122- #endif
147+ return float4(light, 1) * diffuse;
148+ */
149+ // #else
150+ // return diffuse;
151+ // #endif
123152}
124153
125154End Fragment
0 commit comments