Sitelet https://github.com/IRCSS/Procedural-painting/commit/f84bc3e943c6b623d767601bcfe6f53a02c001b6
Skip to content

Commit f84bc3e

Browse files
committed
added support for OpenGl
1 parent bd79c27 commit f84bc3e

8 files changed

Lines changed: 79 additions & 18 deletions

File tree

‎Assets/Scenes/Main.unity‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ MonoBehaviour:
163163
m_Script: {fileID: 11500000, guid: ccc96ac8c42efed4ea1f23b2d28cf072, type: 3}
164164
m_Name:
165165
m_EditorClassIdentifier:
166-
ImageToReproduce: {fileID: 2800000, guid: b6ec9368b1f8b8d41bb829cf49614088, type: 3}
167-
blackAnwWhite: 1
168-
run_settings: {fileID: 11400000, guid: f05d0447d79604044b99d64bf94829fe, type: 2}
166+
ImageToReproduce: {fileID: 2800000, guid: 0d5c77ecce60ebb41aa1e65c9d13c9ce, type: 3}
167+
blackAnwWhite: 0
168+
run_settings: {fileID: 11400000, guid: cb86d3d200c9f1f44ac5e121f86648e5, type: 2}
169169
compute_shaders:
170170
compute_fitness_function: {fileID: 7200000, guid: b5263be85cc7edc499a4b108a87dfae8,
171171
type: 3}

‎Assets/Scripts/TestSections/SampleOnEdgesTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Start()
5454
// -----------------------------------------
5555
debug_positions_mat = new Material(Shader.Find("Unlit/pointRenderer"));
5656
if (!debug_positions_mat) Debug.LogError("No Material found!");
57-
debug_positions_mat.SetBuffer("buffer", debug_positions_buffer);
57+
debug_positions_mat.SetBuffer("points_buffer", debug_positions_buffer);
5858
// -----------------------------------------
5959
Construct_Position_Domain_handel = construct_position_domain_compute.FindKernel("CS_Construct_Position_Domain");
6060
Debug_Position_Domain_handel = construct_position_domain_compute.FindKernel("CS_Debug_Position_Domain");

‎Assets/Shaders/Resources/CIELabBlit.shader‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
// Checking the range of the function and making sure it is within the expected range
4747
fixed4 col = tex2D(_MainTex, i.uv);
4848
col.xyz = rgb2lab(col.xyz);
49-
float4 out_ = float4(0., 0., 0., 1.);
50-
if (col.x < 0.0 || col.y < 0.0 || col.z < 0.0) out_.x = 1.;
51-
if (col.x > 1.0 || col.y > 1.0 || col.z > 1.0) out_.y = 1.;
49+
//float4 out_ = float4(0., 0., 0., 1.);
50+
//if (col.x < 0.0 || col.y < 0.0 || col.z < 0.0) out_.x = 1.;
51+
//if (col.x > 1.0 || col.y > 1.0 || col.z > 1.0) out_.y = 1.;
5252

53-
return out_;
53+
return col;
5454
}
5555
ENDCG
5656
}

‎Assets/Shaders/Resources/FittestRenderShader.shader‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
ZWrite Off
99
ZTest Always
1010
Blend SrcAlpha OneMinusSrcAlpha
11-
11+
12+
13+
1214
LOD 100
1315

1416
Pass
1517
{
1618

1719
CGPROGRAM
20+
1821
#pragma vertex vert
1922
#pragma fragment frag
2023

2124
#include "UnityCG.cginc"
2225

2326

27+
2428
struct v2f
2529
{
2630
float2 uv : TEXCOORD0;
@@ -58,8 +62,16 @@
5862
float3 vertexPos = float3(0.,0.,0.);
5963
float2 v2_1 = float2(0.,0.); // generic name. Now it is uv, I will use the register for other things later
6064

61-
62-
65+
// Dealing with API differences. Not quite sure what is happening, the DirectX11 is clock wise
66+
// and OpenGl counterclockwise as default values, but I would have expected that Unity takes care
67+
// of this automaticly. However the triangle stream at this point is already past the Vertex Assembler
68+
// which might have a different settings. At anycase differnece between the Z axis between the two
69+
// is to be expected, the projection matrix should have maybe taken care of it, but maybe in Unity
70+
// the negation there is handeled by the camera matrix which I am not using. I just changed the
71+
// Z coordinates per API.
72+
73+
#if SHADER_API_D3D11 || SHADER_API_D3D11_9X
74+
// Counter clockwise binding
6375
[branch] switch (vertexCase) {
6476
case 0: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
6577
case 1: vertexPos = float3(-0.5,-0.5, 0.5); v2_1 = float2(0.,0.);break; // lower left of the Quad
@@ -69,6 +81,18 @@
6981
case 5: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
7082
}
7183

84+
85+
#else // Clock wise binding
86+
[branch] switch (vertexCase) {
87+
case 0: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
88+
case 1: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower left of the Quad
89+
case 2: vertexPos = float3(-0.5,-0.5, -0.5); v2_1 = float2(0.,0.);break; // lower right of the Quad
90+
case 3: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower right of the Quad
91+
case 4: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper right of the Quad
92+
case 5: vertexPos = float3( 0.5, 0.5, -0.5); v2_1 = float2(1.,1.);break; // upper left of the Quad
93+
}
94+
95+
#endif
7296
v2f o;
7397
o.uv = v2_1;
7498

@@ -91,8 +115,8 @@
91115

92116
vertexPos = mul(brushModelMat, float4(vertexPos.xyz, 1.));
93117

94-
o.vertex = mul(UNITY_MATRIX_P, float4(vertexPos.xyz, 1.));
95-
o.vertex = float4(vertexPos.xyz,1.);
118+
119+
o.vertex = float4(vertexPos.xyz, 1.);
96120
return o;
97121
}
98122

‎Assets/Shaders/Resources/PopulationShader.shader‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@
5252
float2 v2_1 = float2(0.,0.); // generic name. Now it is uv, I will use the register for other things later
5353

5454

55-
55+
// Dealing with API differences. Not quite sure what is happening, the DirectX11 is clock wise
56+
// and OpenGl counterclockwise as default values, but I would have expected that Unity takes care
57+
// of this automaticly. However the triangle stream at this point is already past the Vertex Assembler
58+
// which might have a different settings. At anycase differnece between the Z axis between the two
59+
// is to be expected, the projection matrix should have maybe taken care of it, but maybe in Unity
60+
// the negation there is handeled by the camera matrix which I am not using. I just changed the
61+
// Z coordinates per API.
62+
63+
#if SHADER_API_D3D11 || SHADER_API_D3D11_9X
64+
// Counter clockwise binding
5665
[branch] switch (vertexCase) {
5766
case 0: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
5867
case 1: vertexPos = float3(-0.5,-0.5, 0.5); v2_1 = float2(0.,0.);break; // lower left of the Quad
@@ -62,6 +71,19 @@
6271
case 5: vertexPos = float3(-0.5, 0.5, 0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
6372
}
6473

74+
75+
#else // Clock wise binding
76+
[branch] switch (vertexCase) {
77+
case 0: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper left of the Quad
78+
case 1: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower left of the Quad
79+
case 2: vertexPos = float3(-0.5,-0.5, -0.5); v2_1 = float2(0.,0.);break; // lower right of the Quad
80+
case 3: vertexPos = float3( 0.5,-0.5, -0.5); v2_1 = float2(1.,0.);break; // lower right of the Quad
81+
case 4: vertexPos = float3(-0.5, 0.5, -0.5); v2_1 = float2(0.,1.);break; // upper right of the Quad
82+
case 5: vertexPos = float3( 0.5, 0.5, -0.5); v2_1 = float2(1.,1.);break; // upper left of the Quad
83+
}
84+
85+
#endif
86+
6587
v2f o;
6688
o.uv = v2_1;
6789

@@ -84,7 +106,7 @@
84106

85107
vertexPos = mul(brushModelMat, float4(vertexPos.xyz, 1.));
86108

87-
o.vertex = mul(UNITY_MATRIX_P, float4(vertexPos.xyz, 1.));
109+
88110
o.vertex = float4(vertexPos.xyz,1.);
89111
return o;
90112
}

‎Assets/Shaders/Resources/construct_position_domain.compute‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@ void CS_Construct_Position_Domain(uint3 id : SV_DispatchThreadID)
2929

3030
if (mask.r > _sample_threshold)
3131
{
32+
33+
34+
35+
#if SHADER_API_D3D11 || SHADER_API_D3D11_9X
36+
37+
_position_domain_buffer.Append
38+
(float2(texutre_coordinates.x, 1. - texutre_coordinates.y)); // The sampleLevel method is actually flipping the y/v axis upside down. I am on Direct3D 11, on different platform the -1 I added here might need to go away
39+
40+
#else
3241
_position_domain_buffer.Append
33-
(float2(texutre_coordinates.x, 1.- texutre_coordinates.y)); // The sampleLevel method is actually flipping the y/v axis upside down. I am on Direct3D 11, on different platform the -1 I added here might need to go away
42+
(float2(texutre_coordinates.x, texutre_coordinates.y));
43+
44+
#endif
45+
3446
}
3547
}
3648

‎Assets/Shaders/Resources/pointRenderer.shader‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Shader "Unlit/pointRenderer"
2626
float4 color : TEXCOORD0;
2727
};
2828

29-
uniform StructuredBuffer<float2> buffer;
29+
uniform StructuredBuffer<float2> points_buffer;
3030

3131

3232

@@ -53,7 +53,7 @@ Shader "Unlit/pointRenderer"
5353
{
5454
v2f o;
5555

56-
o.vertex =float4(buffer[id].xy, 0.5, 1.);
56+
o.vertex =float4(points_buffer[id].xy, 0.5, 1.);
5757
//o.vertex = mul(UNITY_MATRIX_P, float4(buffer[id].xy, -0.5, 1.));
5858
o.color = float4(wang_rnd(id), wang_rnd(id+651), wang_rnd(id+21), 1.);
5959
return o;

‎ProjectSettings/ProjectSettings.asset‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ PlayerSettings:
300300
- m_BuildTarget: WebGLSupport
301301
m_APIs: 0b000000
302302
m_Automatic: 1
303+
- m_BuildTarget: WindowsStandaloneSupport
304+
m_APIs: 0200000011000000
305+
m_Automatic: 1
303306
m_BuildTargetVRSettings:
304307
- m_BuildTarget: Standalone
305308
m_Enabled: 0

0 commit comments

Comments
 (0)