git-svn-id: svn://db.shs.com.ru/libs@613 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -99,10 +99,11 @@ protected:
|
||||
|
||||
class Map {
|
||||
public:
|
||||
Map() {bitmap_id = 0; color_amount = 1.f; color_offset = 0.f; animation_frame_rate = -1.f;}
|
||||
Map() {bitmap_id = 0; color_amount = 1.f; color_offset = 0.f; animation_frame_rate = -1.f; bitmap_scale = QPointF(1., 1.);}
|
||||
QString bitmap_path;
|
||||
GLuint bitmap_id;
|
||||
QPointF bitmap_offset;
|
||||
QPointF bitmap_scale;
|
||||
float color_amount;
|
||||
float color_offset;
|
||||
QString animation;
|
||||
@@ -138,18 +139,19 @@ public:
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Map & m) {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, m.bitmap_path) << cs.chunk(2, m.color_amount) << cs.chunk(3, m.color_offset) << cs.chunk(4, m.animation) << cs.chunk(5, m.animation_frame_rate);
|
||||
cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(4, m.animation).add(5, m.animation_frame_rate).add(6, m.bitmap_scale);
|
||||
s << cs.data(); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Map & m) {
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: m.bitmap_path = cs.getData<QString>(); break;
|
||||
case 2: m.color_amount = cs.getData<float>(); break;
|
||||
case 3: m.color_offset = cs.getData<float>(); break;
|
||||
case 4: m.animation = cs.getData<QString>(); break;
|
||||
case 5: m.animation_frame_rate = cs.getData<float>(); break;
|
||||
case 1: m.bitmap_path = cs.getData<QString>(); break;
|
||||
case 2: m.color_amount = cs.getData<float>(); break;
|
||||
case 3: m.color_offset = cs.getData<float>(); break;
|
||||
case 4: m.animation = cs.getData<QString>(); break;
|
||||
case 5: m.animation_frame_rate = cs.getData<float>(); break;
|
||||
case 6: m.bitmap_scale = cs.getData<QPointF>(); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
@@ -157,9 +159,9 @@ inline QDataStream & operator >>(QDataStream & s, Map & m) {
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Material & m) {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, m.name) << cs.chunk(2, m.color_diffuse) << cs.chunk(3, m.color_specular) << cs.chunk(4, m.color_self_illumination)
|
||||
<< cs.chunk(5, m.transparency) << cs.chunk(6, m.reflectivity) << cs.chunk(7, m.glass) << cs.chunk(8, m.map_diffuse) << cs.chunk(9, m.map_normal)
|
||||
<< cs.chunk(10, m.map_relief) << cs.chunk(11, m.map_specular) << cs.chunk(12, m.map_specularity) << cs.chunk(13, m.map_self_illumination);
|
||||
cs.add(1, m.name).add(2, m.color_diffuse).add(3, m.color_specular).add(4, m.color_self_illumination)
|
||||
.add(5, m.transparency).add(6, m.reflectivity).add(7, m.glass).add(8, m.map_diffuse).add(9, m.map_normal)
|
||||
.add(10, m.map_relief).add(11, m.map_specular).add(12, m.map_specularity).add(13, m.map_self_illumination);
|
||||
s << qCompress(cs.data()); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Material & m) {
|
||||
@@ -169,19 +171,19 @@ inline QDataStream & operator >>(QDataStream & s, Material & m) {
|
||||
ChunkStream cs(ba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: m.name = cs.getData<QString>(); break;
|
||||
case 2: m.color_diffuse = cs.getData<QColor>(); break;
|
||||
case 3: m.color_specular = cs.getData<QColor>(); break;
|
||||
case 4: m.color_self_illumination = cs.getData<QColor>(); break;
|
||||
case 5: m.transparency = cs.getData<float>(); break;
|
||||
case 6: m.reflectivity = cs.getData<float>(); break;
|
||||
case 7: m.glass = cs.getData<bool>(); break;
|
||||
case 8: m.map_diffuse = cs.getData<Map>(); break;
|
||||
case 9: m.map_normal = cs.getData<Map>(); break;
|
||||
case 10: m.map_relief = cs.getData<Map>(); break;
|
||||
case 11: m.map_specular = cs.getData<Map>(); break;
|
||||
case 12: m.map_specularity = cs.getData<Map>(); break;
|
||||
case 13: m.map_self_illumination = cs.getData<Map>(); break;
|
||||
case 1: m.name = cs.getData<QString>(); break;
|
||||
case 2: m.color_diffuse = cs.getData<QColor>(); break;
|
||||
case 3: m.color_specular = cs.getData<QColor>(); break;
|
||||
case 4: m.color_self_illumination = cs.getData<QColor>(); break;
|
||||
case 5: m.transparency = cs.getData<float>(); break;
|
||||
case 6: m.reflectivity = cs.getData<float>(); break;
|
||||
case 7: m.glass = cs.getData<bool>(); break;
|
||||
case 8: m.map_diffuse = cs.getData<Map>(); break;
|
||||
case 9: m.map_normal = cs.getData<Map>(); break;
|
||||
case 10: m.map_relief = cs.getData<Map>(); break;
|
||||
case 11: m.map_specular = cs.getData<Map>(); break;
|
||||
case 12: m.map_specularity = cs.getData<Map>(); break;
|
||||
case 13: m.map_self_illumination = cs.getData<Map>(); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
|
||||
@@ -75,6 +75,7 @@ const char qgl_structs[] =
|
||||
"struct QGLMap {\n"
|
||||
" float offset;\n"
|
||||
" float amount;\n"
|
||||
" vec2 scale;\n"
|
||||
" sampler2D map;\n"
|
||||
"};\n"
|
||||
"struct QGLMaterial {\n"
|
||||
@@ -174,6 +175,7 @@ void setUniformMap(QOpenGLShaderProgram * prog, QString map_name, const Map & ma
|
||||
if (!prog->isLinked()) return;
|
||||
prog->setUniformValue(("qgl_Material." + map_name + ".offset").toLatin1().constData(), map.color_offset);
|
||||
prog->setUniformValue(("qgl_Material." + map_name + ".amount").toLatin1().constData(), map.color_amount);
|
||||
prog->setUniformValue(("qgl_Material." + map_name + ".scale").toLatin1().constData(), map.bitmap_scale);
|
||||
prog->setUniformValue(("qgl_Material." + map_name + ".map").toLatin1().constData(), map.bitmap_id > 0 ? channel : def_channel);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ void MaterialMapEditor::setMap(const Map & m) {
|
||||
active = false;
|
||||
ui->sliderAmount->setValue(m.color_amount);
|
||||
ui->sliderOffset->setValue(m.color_offset);
|
||||
ui->spinScaleX->setValue(m.bitmap_scale.x());
|
||||
ui->spinScaleY->setValue(m.bitmap_scale.y());
|
||||
ui->linePath->setProperty("GLpath", m.bitmap_path); ui->linePath->setText(QFileInfo(m.bitmap_path).fileName());
|
||||
updateIcon();
|
||||
active = true;
|
||||
@@ -65,6 +67,8 @@ Map MaterialMapEditor::map() {
|
||||
Map m;
|
||||
m.color_amount = ui->sliderAmount->value();
|
||||
m.color_offset = ui->sliderOffset->value();
|
||||
m.bitmap_scale.setX(ui->spinScaleX->value());
|
||||
m.bitmap_scale.setY(ui->spinScaleY->value());
|
||||
m.bitmap_path = ui->linePath->property("GLpath").toString();
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -6,15 +6,21 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>509</width>
|
||||
<height>74</height>
|
||||
<width>587</width>
|
||||
<height>138</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@@ -36,15 +42,17 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonClear">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
<property name="icon">
|
||||
<iconset resource="../qad/utils/qad_utils.qrc">
|
||||
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonSelect">
|
||||
<property name="text">
|
||||
<string>^</string>
|
||||
<property name="icon">
|
||||
<iconset resource="../qad/application/qad_application.qrc">
|
||||
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -60,10 +68,10 @@
|
||||
<item row="1" column="1">
|
||||
<widget class="SpinSlider" name="sliderAmount">
|
||||
<property name="minimum">
|
||||
<double>-10.000000000000000</double>
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10.000000000000000</double>
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
@@ -77,6 +85,12 @@
|
||||
<property name="pageStep">
|
||||
<double>0.200000000000000</double>
|
||||
</property>
|
||||
<property name="spinMinimum">
|
||||
<double>-99.000000000000000</double>
|
||||
</property>
|
||||
<property name="spinMaximum">
|
||||
<double>99.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
@@ -89,10 +103,10 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="SpinSlider" name="sliderOffset">
|
||||
<property name="minimum">
|
||||
<double>-10.000000000000000</double>
|
||||
<double>-1.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10.000000000000000</double>
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>2</number>
|
||||
@@ -103,8 +117,96 @@
|
||||
<property name="pageStep">
|
||||
<double>0.200000000000000</double>
|
||||
</property>
|
||||
<property name="spinMinimum">
|
||||
<double>-99.000000000000000</double>
|
||||
</property>
|
||||
<property name="spinMaximum">
|
||||
<double>99.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Scale X:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="spinScaleX">
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Scale Y:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="spinScaleY">
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -121,7 +223,10 @@
|
||||
<header>iconedlabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../qad/utils/qad_utils.qrc"/>
|
||||
<include location="../qad/application/qad_application.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>linePath</sender>
|
||||
@@ -130,8 +235,8 @@
|
||||
<slot>mapChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>175</x>
|
||||
<y>19</y>
|
||||
<x>471</x>
|
||||
<y>22</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>99</x>
|
||||
@@ -171,6 +276,38 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>spinScaleX</sender>
|
||||
<signal>valueChanged(double)</signal>
|
||||
<receiver>MaterialMapEditor</receiver>
|
||||
<slot>mapChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>377</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>332</x>
|
||||
<y>164</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>spinScaleY</sender>
|
||||
<signal>valueChanged(double)</signal>
|
||||
<receiver>MaterialMapEditor</receiver>
|
||||
<slot>mapChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>519</x>
|
||||
<y>110</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>493</x>
|
||||
<y>164</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>mapChanged()</slot>
|
||||
|
||||
@@ -19,10 +19,10 @@ void main(void) {
|
||||
//float logz = log(pos.w * C + 1.) * FC;
|
||||
vec4 dc = qgl_FragColor;
|
||||
vec2 tc = qgl_FragTexture.xy;
|
||||
float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
|
||||
float hei = dot(texture(qgl_Material.map_relief.map, tc * qgl_Material.map_relief.scale).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
|
||||
|
||||
vec3 n, dn, bn;
|
||||
dn = texture(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.);
|
||||
dn = texture(qgl_Material.map_normal.map, tc * qgl_Material.map_normal.scale).rgb - vec3(0.5, 0.5, 1.);
|
||||
dn = dn * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
|
||||
dn.y = -dn.y;
|
||||
dn = TBN * dn;
|
||||
@@ -31,15 +31,15 @@ void main(void) {
|
||||
bn = normalize(qgl_NormalMatrix * binormal);
|
||||
//n = dn;
|
||||
|
||||
dc *= texture(qgl_Material.map_diffuse.map, tc) * qgl_Material.map_diffuse.amount + qgl_Material.map_diffuse.offset;
|
||||
dc *= texture(qgl_Material.map_diffuse.map, tc * qgl_Material.map_diffuse.scale) * qgl_Material.map_diffuse.amount + qgl_Material.map_diffuse.offset;
|
||||
|
||||
vec4 spec = texture(qgl_Material.map_specular.map, tc) * qgl_Material.map_specular.amount + qgl_Material.map_specular.offset;
|
||||
vec4 spec = texture(qgl_Material.map_specular.map, tc * qgl_Material.map_specular.scale) * qgl_Material.map_specular.amount + qgl_Material.map_specular.offset;
|
||||
spec *= qgl_Material.color_specular;
|
||||
float specularity = dot(texture(qgl_Material.map_specularity.map, tc).rgb, luma) * qgl_Material.map_specularity.amount + qgl_Material.map_specularity.offset;
|
||||
float specularity = dot(texture(qgl_Material.map_specularity.map, tc * qgl_Material.map_specularity.scale).rgb, luma) * qgl_Material.map_specularity.amount + qgl_Material.map_specularity.offset;
|
||||
specularity = clamp(specularity, 0.05, 0.99);
|
||||
float reflectivity = qgl_Material.reflectivity;//dot(texture(qgl_Material.map_specularity.map, tc).rgb, luma) * qgl_Material.map_specularity.amount + qgl_Material.map_specularity.offset;
|
||||
reflectivity = clamp(reflectivity, 0., 1.);
|
||||
vec4 self = texture(qgl_Material.map_self_illumination.map, tc) * qgl_Material.map_self_illumination.amount + qgl_Material.map_self_illumination.offset;
|
||||
vec4 self = texture(qgl_Material.map_self_illumination.map, tc * qgl_Material.map_self_illumination.scale) * qgl_Material.map_self_illumination.amount + qgl_Material.map_self_illumination.offset;
|
||||
self *= qgl_Material.color_self_illumination;
|
||||
|
||||
vec3 speed = pos.xyz/pos.w - ppos.xyz/ppos.w;
|
||||
|
||||
Reference in New Issue
Block a user