SO3Engine
SO3GBufferHigh.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
26
27namespace SO3
28{
29
41
42Ogre::String SGBufferHigh::GetGBufferMaterialPixelOutputStructureTypeNameImpl()
43{
44 return "SO3_GBufferHigh_PixelShaderOutput";
45}
46
47Ogre::String SGBufferHigh::GetGBufferCompositorPixelInputStructureTypeNameImpl()
48{
49 return "SO3_GBufferHigh_PixelShaderInput";
50}
51
52Ogre::String SGBufferHigh::GenerateGBufferMaterialPixelOutputStructureImpl()
53{
54 Ogre::StringStream ss;
55
56 // GBuffer that support specular map, velocity (motion blur), emissive light, and material id. 4 mrt used.
57 ss << "struct SO3_GBufferHigh_PixelShaderOutput : I_GBufferPixelShaderOutput" << std::endl;
58 ss << "{" << std::endl;
59 ss << " float4 mrt0 : COLOR0; // Diffuse (rgb) + Emissive power (a)" << std::endl;
60 ss << " float4 mrt1 : COLOR1; // Specular (rgb) + Shininess power (a)" << std::endl;
61 ss << " float4 mrt2 : COLOR2; // Normal (rgb) + Depth (a)" << std::endl;
62 ss << " float4 mrt3 : COLOR3; // Velocity (rg) + material id (b). One empty channel for extension (a)." << std::endl;
63
64 // Initialize output to default values
65 ss << " void Reset()" << std::endl;
66 ss << " {" << std::endl;
67 ss << " mrt0 = float4(0, 0, 0, 0);" << std::endl;
68 ss << " mrt1 = float4(0, 0, 0, 0);" << std::endl;
69 ss << " mrt2 = float4(0, 0, 0, 0);" << std::endl;
70 ss << " mrt3 = float4(0, 0, 0, 0);" << std::endl;
71 ss << " }" << std::endl;
72
73 // Get the diffuse term
74 ss << " float3 GetDiffuse()" << std::endl;
75 ss << " {" << std::endl;
76 ss << " return mrt0.rgb;" << std::endl;
77 ss << " }" << std::endl;
78
79 // Set the diffuse term
80 ss << " void SetDiffuse(in float3 diffuse)" << std::endl;
81 ss << " {" << std::endl;
82 ss << " mrt0.rgb = diffuse;" << std::endl;
83 ss << " }" << std::endl;
84
85 // Get the specular term
86 ss << " float3 GetSpecular()" << std::endl;
87 ss << " {" << std::endl;
88 ss << " return mrt1.rgb;" << std::endl;
89 ss << " }" << std::endl;
90
91 // Set the specular term
92 ss << " void SetSpecular(in float3 specular)" << std::endl;
93 ss << " {" << std::endl;
94 ss << " mrt1.rgb = specular;" << std::endl;
95 ss << " }" << std::endl;
96
97 // Get the shininess term
98 ss << " float GetShininess()" << std::endl;
99 ss << " {" << std::endl;
100 ss << " return mrt1.a;" << std::endl;
101 ss << " }" << std::endl;
102
103 // Set the shininess term
104 ss << " void SetShininess(in float shininess)" << std::endl;
105 ss << " {" << std::endl;
106 ss << " mrt1.a = shininess;" << std::endl;
107 ss << " }" << std::endl;
108
109 // Get the normal
110 ss << " float3 GetNormal()" << std::endl;
111 ss << " {" << std::endl;
112 ss << " return mrt2.rgb;" << std::endl;
113 ss << " }" << std::endl;
114
115 // Set the normal
116 ss << " void SetNormal(in float3 normal)" << std::endl;
117 ss << " {" << std::endl;
118 ss << " mrt2.rgb = normal;" << std::endl;
119 ss << " }" << std::endl;
120
121 // Get the depth
122 ss << " float GetDepth()" << std::endl;
123 ss << " {" << std::endl;
124 ss << " return mrt2.a;" << std::endl;
125 ss << " }" << std::endl;
126
127 // Set the depth
128 ss << " void SetDepth(in float depth)" << std::endl;
129 ss << " {" << std::endl;
130 ss << " mrt2.a = depth;" << std::endl;
131 ss << " }" << std::endl;
132
133 // Get the emissive term
134 ss << " float GetEmissive()" << std::endl;
135 ss << " {" << std::endl;
136 ss << " return mrt0.a;" << std::endl;
137 ss << " }" << std::endl;
138
139 // Set the emissive term
140 ss << " void SetEmissive(in float emissive)" << std::endl;
141 ss << " {" << std::endl;
142 ss << " mrt0.a = emissive;" << std::endl;
143 ss << " }" << std::endl;
144
145 // Get the material id
146 ss << " float GetMaterialID()" << std::endl;
147 ss << " {" << std::endl;
148 ss << " return mrt3.b;" << std::endl;
149 ss << " }" << std::endl;
150
151 // Set the material id term
152 ss << " void SetMaterialID(in float materialId)" << std::endl;
153 ss << " {" << std::endl;
154 ss << " mrt3.b = materialId;" << std::endl;
155 ss << " }" << std::endl;
156
157 // Get the velocity vector
158 ss << " float2 GetVelocity()" << std::endl;
159 ss << " {" << std::endl;
160 ss << " return mrt3.rg;" << std::endl;
161 ss << " }" << std::endl;
162
163 // Set the velocity vector
164 ss << " void SetVelocity(in float2 velocity)" << std::endl;
165 ss << " {" << std::endl;
166 ss << " mrt3.rg = velocity;" << std::endl;
167 ss << " }" << std::endl;
168 ss << "};" << std::endl;
169 ss << std::endl;
170
171 return ss.str();
172}
173
174Ogre::String SGBufferHigh::GenerateGBufferCompositorPixelInputStructureImpl()
175{
176 Ogre::StringStream ss;
177
178 // GBuffer that support specular map, velocity (motion blur), emissive light, and material id. 4 mrt used.
179 ss << "struct SO3_GBufferHigh_PixelShaderInput : I_GBufferPixelShaderInput" << std::endl;
180 ss << "{" << std::endl;
181 ss << " uniform sampler2D mrt0 : register(s0); // Diffuse (rgb) + Emissive power (a)" << std::endl;
182 ss << " uniform sampler2D mrt1 : register(s1); // Specular (rgb) + Shininess power (a)" << std::endl;
183 ss << " uniform sampler2D mrt2 : register(s2); // Normal (rgb) + Depth (a)" << std::endl;
184 ss << " uniform sampler2D mrt3 : register(s3); // Velocity (rg) + material id (b). One empty channel for extension (a)" << std::endl;
185
186 // Get the diffuse term
187 ss << " float3 GetDiffuse(in float2 coordinate)" << std::endl;
188 ss << " {" << std::endl;
189 ss << " return tex2D(mrt0, coordinate).rgb;" << std::endl;
190 ss << " }" << std::endl;
191
192 // Get the specular term
193 ss << " float3 GetSpecular(in float2 coordinate)" << std::endl;
194 ss << " {" << std::endl;
195 ss << " return tex2D(mrt1, coordinate).rgb;" << std::endl;
196 ss << " }" << std::endl;
197
198 // Get the shininess term
199 ss << " float GetShininess(in float2 coordinate)" << std::endl;
200 ss << " {" << std::endl;
201 ss << " return tex2D(mrt1, coordinate).a;" << std::endl;
202 ss << " }" << std::endl;
203
204 // Get the normal
205 ss << " float3 GetNormal(in float2 coordinate)" << std::endl;
206 ss << " {" << std::endl;
207 ss << " return tex2D(mrt2, coordinate).rgb;" << std::endl;
208 ss << " }" << std::endl;
209
210 // Get the depth
211 ss << " float GetDepth(in float2 coordinate)" << std::endl;
212 ss << " {" << std::endl;
213 ss << " return tex2D(mrt2, coordinate).a;" << std::endl;
214 ss << " }" << std::endl;
215
216 // Get the emissive term
217 ss << " float GetEmissive(in float2 coordinate)" << std::endl;
218 ss << " {" << std::endl;
219 ss << " return tex2D(mrt0, coordinate).a;" << std::endl;
220 ss << " }" << std::endl;
221
222 // Get the material id
223 ss << " float GetMaterialID(in float2 coordinate)" << std::endl;
224 ss << " {" << std::endl;
225 ss << " return tex2D(mrt3, coordinate).b;" << std::endl;
226 ss << " }" << std::endl;
227
228 // Get the velocity vector
229 ss << " float2 GetVelocity(in float2 coordinate)" << std::endl;
230 ss << " {" << std::endl;
231 ss << " return tex2D(mrt3, coordinate).rg;" << std::endl;
232 ss << " }" << std::endl;
233 ss << "};" << std::endl;
234 ss << std::endl;
235
236 return ss.str();
237}
238
239}
Ogre::uint32 channels
Definition SO3GBuffer.h:53
@ SO3_GBUFFER_SHININESS
Definition SO3GBuffer.h:46
@ SO3_GBUFFER_MATERIAL_ID
Definition SO3GBuffer.h:49